Skip to content

Commit

Permalink
Merge pull request #6597 from keymanapp/chore/web/fixup-test-paths
Browse files Browse the repository at this point in the history
chore(web): fixup keyboard-processor and input-processor tests 🎡
  • Loading branch information
mcdurdin authored May 26, 2022
2 parents e80ce48 + 08ec9a5 commit 9a29c08
Show file tree
Hide file tree
Showing 29 changed files with 279 additions and 186 deletions.
26 changes: 20 additions & 6 deletions common/core/web/input-processor/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,36 @@ if [ $FETCH_DEPS = true ]; then
fi

# Ensures that the lexical model compiler has been built locally.
echo_heading "Preparing Lexical Model Compiler for test use"
pushd $WORKING_DIRECTORY/node_modules/@keymanapp/lexical-model-compiler
npm run build
popd
#echo_heading "Preparing Lexical Model Compiler for test use"
#pushd $WORKING_DIRECTORY/node_modules/@keymanapp/lexical-model-compiler
#npm run build
#popd

test-headless ( ) {
if (( CI_REPORTING )); then
FLAGS="$FLAGS --reporter mocha-teamcity-reporter"
fi

npm run mocha -- --recursive $FLAGS ./tests/cases/
# Poor Man's Modules until we support ES6 throughout
PREPEND=./tests/cases/prepend.js
(cat ../../../../resources/web-environment/build/index.js; echo) > $PREPEND
(cat ../utils/build/index.js; echo) >> $PREPEND
(cat ../keyboard-processor/build/index.js; echo) >> $PREPEND
(cat ../input-processor/build/index.js; echo) >> $PREPEND
(cat tests/cases/inputProcessor.js; echo) >> $PREPEND

# TODO: We will re-enable languageProcessor tests when we have sorted out
# paths and modules for lmc
#(cat tests/cases/languageProcessor.js; echo) >> $PREPEND

npm run mocha -- --recursive $FLAGS ./tests/cases/prepend.js

rm $PREPEND
}

if [ $FETCH_DEPS = true ]; then
# First, run tests on the keyboard processor.
pushd $WORKING_DIRECTORY/node_modules/@keymanapp/keyboard-processor
pushd "$KEYMAN_ROOT/common/core/web/keyboard-processor"
./test.sh -skip-package-install || fail "Tests failed by dependencies; aborting integration tests."
popd
fi
Expand Down
7 changes: 3 additions & 4 deletions common/core/web/input-processor/tests/cases/inputProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ var assert = require('chai').assert;
var fs = require("fs");
var vm = require("vm");

let InputProcessor = require('../../dist');

// Required initialization setup.
global.com = InputProcessor.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.

let InputProcessor = com.keyman.text.InputProcessor;

let device = {
formFactor: 'phone',
OS: 'ios',
Expand Down Expand Up @@ -55,7 +54,7 @@ describe('InputProcessor', function() {
var keyboard;

// Easy peasy long context: use the input processor's full source!
let coreSourceCode = fs.readFileSync('dist/index.js', 'utf-8');
let coreSourceCode = fs.readFileSync('build/index.js', 'utf-8');

// At the time this test block was written... 810485 chars.
// Let's force it to the same order of magnitude, even if the codebase grows.
Expand Down
15 changes: 15 additions & 0 deletions common/core/web/keyboard-processor/src/keyboards/activeLayout.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
namespace com.keyman.keyboards {
type KeyDistribution = text.KeyDistribution;

// TS 3.9 changed behavior of getters to make them
// non-enumerable by default. This broke our 'polyfill'
// functions which depended on enumeration to copy the
// relevant props over.
// https://github.com/microsoft/TypeScript/pull/32264#issuecomment-677718191
function Enumerable(
target: unknown,
propertyKey: string,
descriptor: PropertyDescriptor
) {
descriptor.enumerable = true;
};

export class ActiveKey implements LayoutKey {

Expand Down Expand Up @@ -52,6 +64,7 @@ namespace com.keyman.keyboards {
*
* Is used to determine the keycode for input events, rule-matching, and keystroke processing.
*/
@Enumerable
public get baseKeyID(): string {
if(typeof this.id === 'undefined') {
return undefined;
Expand All @@ -78,6 +91,7 @@ namespace com.keyman.keyboards {
*
* Useful when the active layer of an input-event is already known.
*/
@Enumerable
public get coreID(): string {
if(typeof this.id === 'undefined') {
return undefined;
Expand Down Expand Up @@ -110,6 +124,7 @@ namespace com.keyman.keyboards {
*
* Useful when only the active keyboard is known about an input event.
*/
@Enumerable
public get elementID(): string {
if(typeof this.id === 'undefined') {
return undefined;
Expand Down
3 changes: 2 additions & 1 deletion common/core/web/keyboard-processor/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"target": "es5",
"types": ["node"],
"lib": ["es6"],
"outFile": "../build/index.js"
"outFile": "../build/index.js",
"experimentalDecorators": true,
},
"references": [
{ "path": "../../../../../common/models/types" },
Expand Down
40 changes: 35 additions & 5 deletions common/core/web/keyboard-processor/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,43 @@ test-headless ( ) {
FLAGS="$FLAGS --reporter mocha-teamcity-reporter"
fi

npm run mocha -- --recursive $FLAGS ./tests/cases/
# 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 ../../../../resources/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 ../../../../resources/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/
}

# Build test dependency
pushd "$KEYMAN_ROOT/common/core/web/tools/recorder/src"
./build.sh -skip-package-install || fail "recorder-core compilation failed."
popd
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

# 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 = require('../../dist');
let KMWRecorder = require('../../../tools/recorder/dist/nodeProctor');
let KeyboardProcessor = com.keyman.text.KeyboardProcessor;
global.keyman = {};

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

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: 4 additions & 7 deletions common/core/web/keyboard-processor/tests/cases/basic-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ var assert = require('chai').assert;
var fs = require("fs");
var vm = require("vm");

let KeyboardProcessor = require('../../dist');

// 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.
let KeyboardProcessor = com.keyman.text.KeyboardProcessor;
global.keyman = {};
global.com = com;

// 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 = require('../../dist');
let KMWRecorder = require('../../../tools/recorder/dist/nodeProctor');
let KeyboardProcessor = com.keyman.text.KeyboardProcessor;
global.keyman = {};

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

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: 6 additions & 5 deletions common/core/web/keyboard-processor/tests/cases/deadkeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ var assert = require('chai').assert;
let fs = require('fs');
let vm = require('vm');

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

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

describe('Engine - Deadkeys', function() {
let testJSONtext = fs.readFileSync('../tests/resources/json/engine_tests/deadkeys.json');
Expand Down Expand Up @@ -41,7 +42,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
Loading

0 comments on commit 9a29c08

Please sign in to comment.