mirror of
https://github.com/keymanapp/keyman.git
synced 2026-11-01 02:37:48 +00:00
To reduce the number of possible failure cases within KeymanWeb, require variableStoreSerializer to always be initialized. This impacts only unit tests in practice. There remains a unit test special case in the variable store code itself which needs to be removed in the future. Create a mock VariableStoreTestSerializer class so that unit tests can run without impacting state or requiring cookies. (We should leverage this in future tests to verify that variable stores are saved correctly.) Establish keyman/test/headless-resources, so that we can include shared resources such as VariableStoreTestSerializer without creating a dependency on either DOM or Node.
59 lines
No EOL
2.2 KiB
JavaScript
59 lines
No EOL
2.2 KiB
JavaScript
/*
|
|
* Keyman is copyright (C) SIL Global. MIT License.
|
|
*/
|
|
import fs from 'node:fs';
|
|
|
|
import { assert } from 'chai';
|
|
import { createRequire } from 'module';
|
|
|
|
import { MinimalKeymanGlobal } from 'keyman/engine/keyboard';
|
|
import { JSKeyboardInterface } from 'keyman/engine/js-processor';
|
|
import { NodeKeyboardLoader, getKeymanRoot } from 'keyman/test/resources';
|
|
import { VariableStoreTestSerializer } from 'keyman/test/headless-resources';
|
|
import { KeyboardTest, NodeProctor } from '@keymanapp/recorder-core';
|
|
|
|
const require = createRequire(import.meta.url);
|
|
const KEYMAN_ROOT = getKeymanRoot();
|
|
|
|
describe('Engine - Deadkeys', function() {
|
|
let testJSONtext = fs.readFileSync(require.resolve('@keymanapp/common-test-resources/json/engine_tests/deadkeys.json'));
|
|
// Common test suite setup.
|
|
let testSuite = new KeyboardTest(JSON.parse(testJSONtext));
|
|
|
|
let keyboardWithHarness;
|
|
|
|
let device = {
|
|
formFactor: 'desktop',
|
|
OS: 'windows',
|
|
browser: 'native'
|
|
}
|
|
|
|
before(async function() {
|
|
// -- START: Standard Recorder-based unit test loading boilerplate --
|
|
let keyboardLoader = new NodeKeyboardLoader(new JSKeyboardInterface({}, MinimalKeymanGlobal, new VariableStoreTestSerializer()));
|
|
let keyboard = await keyboardLoader.loadKeyboardFromPath(KEYMAN_ROOT + '/common/test/' + testSuite.keyboard.filename);
|
|
keyboardWithHarness = keyboardLoader.harness;
|
|
keyboardWithHarness.activeKeyboard = keyboard;
|
|
|
|
assert.equal(keyboard.id, "Keyboard_" + testSuite.keyboard.id);
|
|
// -- END: Standard Recorder-based unit test loading boilerplate --
|
|
|
|
// This part provides extra assurance that the keyboard properly loaded.
|
|
assert.equal(keyboard.id, "Keyboard_test_deadkeys");
|
|
});
|
|
|
|
// Converts each test set into its own Mocha-level test.
|
|
for(let set of testSuite.inputTestSets) {
|
|
let proctor = new NodeProctor(keyboardWithHarness, device, assert.equal);
|
|
|
|
if(!proctor.compatibleWithSuite(testSuite)) {
|
|
it.skip(set.toTestName() + " - Cannot run this test suite on Node.");
|
|
} else {
|
|
it(set.toTestName(), async function() {
|
|
// Refresh the proctor instance at runtime.
|
|
let proctor = new NodeProctor(keyboardWithHarness, device, assert.equal);
|
|
await set.test(proctor);
|
|
});
|
|
}
|
|
}
|
|
}); |