Skip to content

Commit

Permalink
fix(web): mocha describe does not do async
Browse files Browse the repository at this point in the history
mocha describe() does not accept an async function. Any async prep
should be done in a before() function, which does support async.

One helpful ref: mochajs/mocha#2975 (comment)
  • Loading branch information
mcdurdin committed Dec 12, 2023
1 parent 60bb1e4 commit e2ce64d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ describe('InputProcessor', function() {
// rest of the recorder stuff since it uses only KeyboardProcessor, not InputProcessor.
let testDefinitions = new KeyboardTest(JSON.parse(testJSONtext));

before(async function () {
this.before(async function () {
// Load the keyboard.
let keyboardLoader = new NodeKeyboardLoader(new KeyboardInterface({}, MinimalKeymanGlobal));
const keyboard = await keyboardLoader.loadKeyboardFromPath(require.resolve('@keymanapp/common-test-resources/keyboards/test_8568_deadkeys.js'));
Expand Down
71 changes: 42 additions & 29 deletions common/web/input-processor/tests/cases/languageProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,16 @@ describe('LanguageProcessor', function() {
});
});

describe('.predict', async function() {
let compiler = new LexicalModelCompiler();
assert.isTrue(await compiler.init(callbacks, {}));
describe('.predict', function() {
let compiler = null;

this.beforeAll(async function() {
compiler = new LexicalModelCompiler();
console.dir(compiler)
console.dir(compiler.init)
assert.isTrue(await compiler.init(callbacks, {}));
});

const MODEL_ID = 'example.qaa.trivial';

// ES-module mode leaves out `__dirname`, so we rebuild it using other components.
Expand All @@ -68,20 +75,23 @@ describe('LanguageProcessor', function() {
const PATH = path.join(__dirname, '../../../../../developer/src/kmc-model/test/fixtures', MODEL_ID);

describe('using angle brackets for quotes', function() {
let modelCode = compiler.generateLexicalModelCode(MODEL_ID, {
format: 'trie-1.0',
sources: ['wordlist.tsv'],
punctuation: {
quotesForKeepSuggestion: { open: `«`, close: `»`},
insertAfterWord: " " , // OGHAM SPACE MARK
}
}, PATH);

let modelSpec = {
id: MODEL_ID,
languages: ['en'],
code: modelCode
};
let modelCode = null, modelSpec = null;
this.beforeAll(function() {
modelCode = compiler.generateLexicalModelCode(MODEL_ID, {
format: 'trie-1.0',
sources: ['wordlist.tsv'],
punctuation: {
quotesForKeepSuggestion: { open: `«`, close: `»`},
insertAfterWord: " " , // OGHAM SPACE MARK
}
}, PATH);

modelSpec = {
id: MODEL_ID,
languages: ['en'],
code: modelCode
};
});

it("successfully loads the model", function(done) {
let languageProcessor = new LanguageProcessor(worker);
Expand Down Expand Up @@ -116,18 +126,21 @@ describe('LanguageProcessor', function() {
});

describe('properly cases generated suggestions', function() {
let modelCode = compiler.generateLexicalModelCode(MODEL_ID, {
format: 'trie-1.0',
sources: ['wordlist.tsv'],
languageUsesCasing: true,
//applyCasing // we rely on the compiler's default implementation here.
}, PATH);

let modelSpec = {
id: MODEL_ID,
languages: ['en'],
code: modelCode
};
let modelCode = null, modelSpec = null;
this.beforeAll(function () {
modelCode = compiler.generateLexicalModelCode(MODEL_ID, {
format: 'trie-1.0',
sources: ['wordlist.tsv'],
languageUsesCasing: true,
//applyCasing // we rely on the compiler's default implementation here.
}, PATH);

modelSpec = {
id: MODEL_ID,
languages: ['en'],
code: modelCode
};
});

describe("does not alter casing when input is lowercased", function() {
it("when input is fully lowercased", function(done) {
Expand Down
2 changes: 1 addition & 1 deletion developer/src/kmc-kmn/test/test-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TestCompilerCallbacks } from '@keymanapp/developer-test-helpers';
import { makePathToFixture } from './helpers/index.js';
import { KMX, KmxFileReader } from '@keymanapp/common-types';

describe('Keyboard compiler features', async function() {
describe('Keyboard compiler features', function() {
let compiler: KmnCompiler = null;
let callbacks: TestCompilerCallbacks = null;

Expand Down
11 changes: 7 additions & 4 deletions developer/src/kmc-package/test/test-package-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ import { CompilerMessages } from '../src/compiler/messages.js';

const debug = false;

describe('KmpCompiler', async function () {
describe('KmpCompiler', function () {
const MODELS : string[] = [
'example.qaa.sencoten',
'withfolders.qaa.sencoten',
];

const callbacks = new TestCompilerCallbacks();
let kmpCompiler = new KmpCompiler();
assert.isTrue(await kmpCompiler.init(callbacks, null));
let kmpCompiler: KmpCompiler = null;

this.beforeAll(async function() {
kmpCompiler = new KmpCompiler();
assert.isTrue(await kmpCompiler.init(callbacks, null));
});

for (let modelID of MODELS) {
const kpsPath = modelID.includes('withfolders') ?
Expand Down

0 comments on commit e2ce64d

Please sign in to comment.