Skip to content

Commit

Permalink
chore(web): reverts keyboard-processor demodularization from #6597
Browse files Browse the repository at this point in the history
  • Loading branch information
jahorton committed May 18, 2022
1 parent 75e77c4 commit 6fd6aa4
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 115 deletions.
15 changes: 15 additions & 0 deletions common/core/web/keyboard-processor/src/tsconfig.bundled.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// This variant of the tsconfig.json exists to create a 'leaf', 'bundled'
// version of the keyboard-processor build product. The same reference
// cannot be prepended twice in a composite tsc build, posing problems
// for certain down-line builds if the two tsconfigs are not differentiated.
"extends": "./tsconfig.json",
"compilerOptions": {
"outFile": "../build/index.bundled.js"
},
"references": [
{ "path": "../../../../../common/models/types" },
{ "path": "../../../../../common/web/web-environment/", "prepend": true },
{ "path": "../../../../../common/core/web/utils/", "prepend": true}
]
}
43 changes: 8 additions & 35 deletions common/core/web/keyboard-processor/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,43 +55,16 @@ test-headless ( ) {
FLAGS="$FLAGS --reporter mocha-teamcity-reporter"
fi

# Poor Man's Modules until we support ES6 throughout
PREPEND=./tests/cases/prepend.js
rm -f $PREPEND
for n in tests/cases/*.js; do
echo $n
(cat ../../../web/web-environment/build/index.js; echo) > $PREPEND
(cat ../utils/build/index.js; echo) >> $PREPEND
(cat ../tools/recorder/build/nodeProctor/index.js; echo) >> $PREPEND
(cat ../keyboard-processor/build/index.js; echo) >> $PREPEND
(cat $n; echo) >> $PREPEND;
npm run mocha -- --recursive $FLAGS $PREPEND || die
rm $PREPEND
done

# Poor Man's Modules until we support ES6 throughout
PREPEND=./tests/cases/engine/prepend.js
rm -f $PREPEND
for n in tests/cases/engine/*.js; do
echo $n
(cat ../../../web/web-environment/build/index.js; echo) > $PREPEND
(cat ../utils/build/index.js; echo) >> $PREPEND
(cat ../tools/recorder/build/nodeProctor/index.js; echo) >> $PREPEND
(cat ../keyboard-processor/build/index.js; echo) >> $PREPEND
(cat $n; echo) >> $PREPEND;
npm run mocha -- --recursive $FLAGS $PREPEND || die
rm $PREPEND
done

# npm run mocha -- --recursive $FLAGS ./tests/cases/
npm run mocha -- --recursive $FLAGS ./tests/cases/
}

if [ $FETCH_DEPS = true ]; then
# Build test dependency
pushd "$KEYMAN_ROOT/common/core/web/tools/recorder/src"
./build.sh -skip-package-install || fail "recorder-core compilation failed."
popd
fi
# Build test dependency
pushd "$KEYMAN_ROOT/common/core/web/tools/recorder/src"
./build.sh -skip-package-install || fail "recorder-core compilation failed."
popd

# Compile web's `keyboard-processor` module."
npm run tsc -- -b src/tsconfig.bundled.json || fail "Failed to compile the testing version of the core/web/keyboard-processor module."

# Run headless (browserless) tests.
echo_heading "Running Keyboard Processor test suite"
Expand Down
10 changes: 5 additions & 5 deletions common/core/web/keyboard-processor/tests/cases/basic-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ var assert = require('chai').assert;
let fs = require('fs');
let vm = require('vm');

let KeyboardProcessor = com.keyman.text.KeyboardProcessor;
global.keyman = {};
let KeyboardProcessor = require('../../build/index.bundled.js');
let KMWRecorder = require('../../../tools/recorder/dist/nodeProctor');

// Initialize supplementary plane string extensions
String.kmwEnableSupplementaryPlane(false);
// Required initialization setup.
global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing.

describe('Engine - Basic Simulation', function() {
let testJSONtext = fs.readFileSync('../tests/resources/json/engine_tests/basic_lao_simulation.json');
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('Engine - Basic Simulation', function() {
// Converts each test set into its own Mocha-level test.
for(let set of testSuite.inputTestSets) {
let proctor = new KMWRecorder.NodeProctor(keyboard, device, assert.equal);

if(!proctor.compatibleWithSuite(testSuite)) {
it.skip(set.toTestName() + " - Cannot run this test suite on Node.");
} else {
Expand Down
11 changes: 7 additions & 4 deletions common/core/web/keyboard-processor/tests/cases/basic-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ var assert = require('chai').assert;
var fs = require("fs");
var vm = require("vm");

let KeyboardProcessor = com.keyman.text.KeyboardProcessor;
global.keyman = {};
global.com = com;
let KeyboardProcessor = require('../../build/index.bundled.js');

// Required initialization setup.
global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing.
global.keyman = {}; // So that keyboard-based checks against the global `keyman` succeed.
// 10.0+ dependent keyboards, like khmer_angkor, will otherwise fail to load.

// Initialize supplementary plane string extensions
String.kmwEnableSupplementaryPlane(false);
String.kmwEnableSupplementaryPlane(false);

// Test the KeyboardProcessor interface.
describe('KeyboardProcessor', function() {
Expand Down
10 changes: 5 additions & 5 deletions common/core/web/keyboard-processor/tests/cases/chirality.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ var assert = require('chai').assert;
let fs = require('fs');
let vm = require('vm');

let KeyboardProcessor = com.keyman.text.KeyboardProcessor;
global.keyman = {};
let KeyboardProcessor = require('../../build/index.bundled.js');
let KMWRecorder = require('../../../tools/recorder/dist/nodeProctor');

// Initialize supplementary plane string extensions
String.kmwEnableSupplementaryPlane(false);
// Required initialization setup.
global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing.

describe('Engine - Chirality', function() {
let testJSONtext = fs.readFileSync('../tests/resources/json/engine_tests/chirality.json');
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('Engine - Chirality', function() {
// Converts each test set into its own Mocha-level test.
for(let set of testSuite.inputTestSets) {
let proctor = new KMWRecorder.NodeProctor(keyboard, device, assert.equal);

if(!proctor.compatibleWithSuite(testSuite)) {
it.skip(set.toTestName() + " - Cannot run this test suite on Node.");
} else if(set.constraint.target == 'hardware') {
Expand Down
11 changes: 5 additions & 6 deletions common/core/web/keyboard-processor/tests/cases/deadkeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ var assert = require('chai').assert;
let fs = require('fs');
let vm = require('vm');

let KeyboardProcessor = com.keyman.text.KeyboardProcessor;
global.keyman = {};
global.com = com;
let KeyboardProcessor = require('../../build/index.bundled.js');
let KMWRecorder = require('../../../tools/recorder/dist/nodeProctor');

// Initialize supplementary plane string extensions
String.kmwEnableSupplementaryPlane(false);
// Required initialization setup.
global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing.

describe('Engine - Deadkeys', function() {
let testJSONtext = fs.readFileSync('../tests/resources/json/engine_tests/deadkeys.json');
Expand Down Expand Up @@ -42,7 +41,7 @@ describe('Engine - Deadkeys', function() {
// Converts each test set into its own Mocha-level test.
for(let set of testSuite.inputTestSets) {
let proctor = new KMWRecorder.NodeProctor(keyboard, device, assert.equal);

if(!proctor.compatibleWithSuite(testSuite)) {
it.skip(set.toTestName() + " - Cannot run this test suite on Node.");
} else {
Expand Down
49 changes: 23 additions & 26 deletions common/core/web/keyboard-processor/tests/cases/engine/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@ var assert = require('chai').assert;
let fs = require('fs');
let vm = require('vm');

let KeyboardProcessor = com.keyman.text.KeyboardProcessor;
global.keyman = {};
global.com = com;
let KeyboardProcessor = require('../../../build/index.bundled.js');
let KMWRecorder = require('../../../../tools/recorder/dist/nodeProctor');

// Initialize supplementary plane string extensions
String.kmwEnableSupplementaryPlane(false);

/*
/*
* ABOUT THIS TEST SUITE
* ---------------------
*
*
* This suite contains two types of tests, both designed to test all possible variations
* of behaviors that `KeyboardInterface.fullContextMatch` may be expected to handle.
*
*
* Type 1: White-box tests for validity of the generated context-cache
* - uses only the `baseSequence` of each test spec definition; does not
* use any `fullMatchDefs` entries.
* - uses the specified `contextCache` entry of each test spec in assertions
* - CTRL+F `Tests "stage 1" of fullContextMatch` for more details.
*
*
* Type 2: Black-box rule-matching tests
* - uses both `baseSequence` and `fullMatchDefs` entries of a test spec
* - tests that each simulation sequence's output either passes or fails against
Expand All @@ -30,6 +26,9 @@ String.kmwEnableSupplementaryPlane(false);
* It should be a removable limitation, though.
*/

// Required initialization setup.
global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing.

let device = {
formFactor: 'desktop',
OS: 'windows',
Expand Down Expand Up @@ -68,14 +67,13 @@ function runEngineRuleSet(ruleSet, defaultNoun) {
ruleSeq.test(proctor, target);

// Now for the real test!
let processor = new KeyboardProcessor();
processor.device = device;
let processor = new KeyboardProcessor(device);
processor.activeKeyboard = keyboard;
var res = processor.keyboardInterface.fullContextMatch(ruleDef.n, target, ruleDef.rule);

var msg = matchTest.msg;
if(!msg) {
msg = defaultNoun + " incorrectly reported as " + (matchTest.result ? "unmatched!" : "matched!");
msg = defaultNoun + " incorrectly reported as " + (matchTest.result ? "unmatched!" : "matched!");
}
assert.equal(res, matchTest.result, msg);
}
Expand Down Expand Up @@ -465,7 +463,7 @@ var ANY_CONTEXT_TEST_2 = {
*
* store(ac) 'ac'
* store(bc) 'bc'
*
*
* 'c' any(ac) any(bc) context(3) context(2) > 'success'
*/
var ANY_CONTEXT_TEST_3 = {
Expand Down Expand Up @@ -522,7 +520,7 @@ var ANY_CONTEXT_TEST_3 = {
*
* store(ab) 'ab'
* store(bc) 'bc'
*
*
* 'c' any(ab) index(bc, 2) 'a' > 'success'
*/
var ANY_INDEX_TEST_1 = {
Expand Down Expand Up @@ -569,7 +567,7 @@ var ANY_INDEX_TEST_1 = {
*
* store(ab) 'ab'
* store(bc) 'bc'
*
*
* 'c' any(ab) index(bc, 2) index(bc, 2) index(ab, 2) > 'success'
*/
var ANY_INDEX_TEST_2 = {
Expand Down Expand Up @@ -616,7 +614,7 @@ var ANY_INDEX_TEST_2 = {
*
* store(ab) 'ab'
* store(bc) 'bc'
*
*
* 'c' any(ab) any(bc) index(bc, 3) index(ab, 2) > 'success'
*/
var ANY_INDEX_TEST_3 = {
Expand Down Expand Up @@ -749,7 +747,7 @@ var DEADKEY_STORE_TEST_2 = {
*
* store(match) dk(0) dk(1) dk(2)
* store(abc) 'abc'
*
*
* any(match) index(abc, 1) > 'success'
*/
var DEADKEY_STORE_TEST_3 = {
Expand Down Expand Up @@ -882,7 +880,7 @@ var NOTANY_NUL_TEST_1 = {
*
* store(match) dk(0) dk(1) dk(2)
* store(abc) 'abc'
*
*
* notany(match) any(abc) > 'success'
*/
var NOTANY_NUL_TEST_2 = {
Expand Down Expand Up @@ -919,7 +917,7 @@ var NOTANY_NUL_TEST_2 = {
*
* store(first) dk(0) 'b' dk(2)
* store(second) 'a' dk(1) 'c'
*
*
* notany(first) any(second) > 'success'
*/
var NOTANY_NUL_TEST_3 = {
Expand Down Expand Up @@ -966,8 +964,8 @@ var NOTANY_NUL_TEST_3 = {
}]
};

var DEADKEY_RULE_SET = [ DEADKEY_TEST_1, DEADKEY_TEST_2, DEADKEY_TEST_3, DEADKEY_TEST_4,
DEADKEY_TEST_5, DEADKEY_TEST_6
var DEADKEY_RULE_SET = [ DEADKEY_TEST_1, DEADKEY_TEST_2, DEADKEY_TEST_3, DEADKEY_TEST_4,
DEADKEY_TEST_5, DEADKEY_TEST_6
];
var ANY_CONTEXT_RULE_SET = [ ANY_CONTEXT_TEST_1, ANY_CONTEXT_TEST_2, ANY_CONTEXT_TEST_3 ];
var ANY_INDEX_RULE_SET = [ ANY_INDEX_TEST_1, ANY_INDEX_TEST_2, ANY_INDEX_TEST_3 ];
Expand All @@ -983,7 +981,7 @@ var NOTANY_NUL_RULE_SET = [ NOTANY_NUL_TEST_1, NOTANY_NUL_TEST_2, NOTANY_NUL_TES

describe('Engine - Context Matching', function() {
before(function() {
let kp = new KeyboardProcessor();
let kp = new KeyboardProcessor(device);

// These two lines will load a keyboard from its file; headless-mode `registerKeyboard` will
// automatically set the keyboard as active.
Expand All @@ -1008,8 +1006,7 @@ describe('Engine - Context Matching', function() {
ruleSeq.test(proctor, target);

// Now for the real test!
let processor = new KeyboardProcessor();
processor.device = device;
let processor = new KeyboardProcessor(device);
processor.activeKeyboard = keyboard;
var res = processor.keyboardInterface._BuildExtendedContext(ruleDef.n, ruleDef.ln, target);

Expand Down Expand Up @@ -1070,7 +1067,7 @@ describe('Engine - Context Matching', function() {
runEngineRuleSet([ANY_INDEX_TEST_3]);
});
});

describe('handles interactions with deadkeys in stores', function() {
it('for any on pure deadkey store: DEADKEY_STORE_TEST_1', function() {
runEngineRuleSet([DEADKEY_STORE_TEST_1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ const assert = require('chai').assert;
const fs = require('fs');
const vm = require('vm');

let KeyboardProcessor = com.keyman.text.KeyboardProcessor;
global.keyman = {};
let KeyboardProcessor = require('../../../build/index.bundled.js');
const KMWRecorder = require('../../../../tools/recorder/dist/nodeProctor');

// Required initialization setup.
global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing.
global.keyman = {}; // So that keyboard-based checks against the global `keyman` succeed.
// 10.0+ dependent keyboards, like khmer_angkor, will otherwise fail to load.

// Initialize supplementary plane string extensions
String.kmwEnableSupplementaryPlane(false);
String.kmwEnableSupplementaryPlane(false);

const device = {
formFactor: 'desktop',
Expand All @@ -27,19 +32,19 @@ function runEngineRuleSet(ruleSet) {
}

/**
* Wrapper to simplify running tests -- supports either virtual key codes as string (e.g. 'A' is VK_A)
* Wrapper to simplify running tests -- supports either virtual key codes as string (e.g. 'A' is VK_A)
* or an array of integers. Does not currently support modifiers (not needed here).
* @param {String|Array} input Virtual key codes of each character (as string or array)
* @param {String} output Expected output
*/

function runStringRuleSet(input, output) {
const rule = {
"inputs":
"inputs":
typeof input == 'string'
? input.split("").map(ch =>
? input.split("").map(ch =>
{ return { "type": "key", "keyCode": ch.charCodeAt(0), "states": 10752, "modifiers": 0, "modifierChanged": false, "isVirtualKey": true } })
: input.map(ch =>
: input.map(ch =>
{ return { "type": "key", "keyCode": ch, "states": 10752, "modifiers": 0, "modifierChanged": false, "isVirtualKey": true } }),
"output": output
};
Expand Down
Loading

0 comments on commit 6fd6aa4

Please sign in to comment.