mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-05 00:15:32 +00:00
chore(common/web): more import path fun
This commit is contained in:
parent
e6fe2b73bf
commit
8b57e28a34
2 changed files with 18 additions and 5 deletions
3
common/test/resources/index.mjs
Normal file
3
common/test/resources/index.mjs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// Exists to facilitate relative path resolution via Node's require.resolve function.
|
||||
|
||||
export { };
|
||||
|
|
@ -1,16 +1,26 @@
|
|||
import { assert } from 'chai';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { createRequire } from 'module';
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
import { KeyboardProperties, SpacebarText } from '@keymanapp/keyboard-processor';
|
||||
|
||||
describe('Keyboard Properties', function() {
|
||||
let rootCommonStubPath = '../../test/resources/json/keyboards/';
|
||||
let commonResourcesPackage = '@keymanapp/common-test-resources';
|
||||
let commonStubsSubpath = 'json/keyboards';
|
||||
let rootCommonStubPath = `${commonResourcesPackage}/${commonStubsSubpath}`;
|
||||
|
||||
it('initialization from KMW\'s addKeyboards() API spec', () => {
|
||||
let files = fs.readdirSync(rootCommonStubPath);
|
||||
// require.resolve cannot resolve a directory directly, unfortunately.
|
||||
// Needs a file to 'root' the resolution mechanism. See https://github.com/nodejs/node/issues/42219.
|
||||
const resolvedResourcesPath = path.dirname(require.resolve(`${commonResourcesPackage}/index.mjs`));
|
||||
const resolvedCommonStubPath = `${resolvedResourcesPath}/${commonStubsSubpath}`;
|
||||
let files = fs.readdirSync(resolvedCommonStubPath);
|
||||
|
||||
for(let file of files) {
|
||||
let stub = JSON.parse(fs.readFileSync(`${rootCommonStubPath}/${file}`));
|
||||
let stub = JSON.parse(fs.readFileSync(`${resolvedCommonStubPath}/${file}`));
|
||||
|
||||
let dataset = [];
|
||||
if(stub.languages instanceof Array) {
|
||||
|
|
@ -35,7 +45,7 @@ describe('Keyboard Properties', function() {
|
|||
|
||||
it('generates display-name text if not directly-specified', () => {
|
||||
// Could convert to run on all stubs, but... this should be fine as-is.
|
||||
let stub = JSON.parse(fs.readFileSync(`${rootCommonStubPath}/khmer_angkor.json`));
|
||||
let stub = JSON.parse(fs.readFileSync(require.resolve(`${rootCommonStubPath}/khmer_angkor.json`)));
|
||||
let propObject = new KeyboardProperties(stub);
|
||||
|
||||
// Without a configured SpacebarText value, will display the keyboard name.
|
||||
|
|
@ -56,7 +66,7 @@ describe('Keyboard Properties', function() {
|
|||
|
||||
it('does not override directly-specified display-name text', () => {
|
||||
// Could convert to run on all stubs, but... this should be fine as-is.
|
||||
let stub = JSON.parse(fs.readFileSync(`${rootCommonStubPath}/khmer_angkor.json`));
|
||||
let stub = JSON.parse(fs.readFileSync(require.resolve(`${rootCommonStubPath}/khmer_angkor.json`)));
|
||||
|
||||
const customDisplayName = "(custom)";
|
||||
let propObject = new KeyboardProperties(stub);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue