Skip to content

Commit

Permalink
Merge pull request #11453 from keymanapp/chore/web/kbd-proc-test-migr…
Browse files Browse the repository at this point in the history
…ation

chore(web): conversion of Web keyboard-loading browser-tests for @web/test-runner use 🏃
  • Loading branch information
jahorton authored May 22, 2024
2 parents b036a86 + 1d8de02 commit 0cd83b2
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 184 deletions.
16 changes: 12 additions & 4 deletions common/web/keyboard-processor/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ builder_describe_outputs \

builder_parse "$@"

function do_configure() {
verify_npm_setup

# Configure Web browser-engine testing environments. As is, this should only
# make changes when we update the dependency, even on our CI build agents.
playwright install
}

function do_build() {
tsc --build "$THIS_SCRIPT_PATH/tsconfig.all.json"

Expand Down Expand Up @@ -60,18 +68,18 @@ function do_build() {

function do_test() {
local MOCHA_FLAGS=
local KARMA_CONFIG=manual.conf.cjs
local WTR_CONFIG=
if builder_has_option --ci; then
echo "Replacing user-friendly test reports with CI-friendly versions."
MOCHA_FLAGS="$MOCHA_FLAGS --reporter mocha-teamcity-reporter"
KARMA_CONFIG=CI.conf.cjs
WTR_CONFIG=.CI
fi

c8 mocha --recursive $MOCHA_FLAGS ./tests/node/
karma start ./tests/dom/$KARMA_CONFIG
web-test-runner --config tests/dom/web-test-runner${WTR_CONFIG}.config.mjs
}

builder_run_action configure verify_npm_setup
builder_run_action configure do_configure
builder_run_action clean rm -rf ./build
builder_run_action build do_build
builder_run_action test do_test
6 changes: 0 additions & 6 deletions common/web/keyboard-processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
"devDependencies": {
"@keymanapp/resources-gosh": "*",
"c8": "^7.12.0",
"karma": "^6.4.1",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.2.0",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"karma-teamcity-reporter": "^1.1.0",
"mocha": "^10.0.0",
"mocha-teamcity-reporter": "^4.0.0",
"ts-node": "^10.9.1",
Expand Down
26 changes: 0 additions & 26 deletions common/web/keyboard-processor/tests/dom/CI.conf.cjs

This file was deleted.

95 changes: 0 additions & 95 deletions common/web/keyboard-processor/tests/dom/base.conf.cjs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
import { assert } from '../../../../../../node_modules/chai/chai.js';
import { assert } from 'chai';

import { DOMKeyboardLoader } from '../../../build/lib/dom-keyboard-loader.mjs';
import { extendString, KeyboardHarness, KeyboardInterface, MinimalKeymanGlobal, Mock } from '../../../build/lib/index.mjs';
import { DOMKeyboardLoader } from '@keymanapp/keyboard-processor/dom-keyboard-loader';
import { extendString, KeyboardHarness, Keyboard, KeyboardInterface, MinimalKeymanGlobal, Mock, DeviceSpec } from '@keymanapp/keyboard-processor';

// Note: rule processing tests will fail if string extensions are not established beforehand.
extendString();

const device = {
const device: DeviceSpec = {
touchable: false,
formFactor: 'phone',
OS: 'ios',
browser: 'safari'
formFactor: DeviceSpec.FormFactor.Phone,
OS: DeviceSpec.OperatingSystem.iOS,
browser: DeviceSpec.Browser.Safari
}

describe('Keyboard loading in DOM', function() {
afterEach(() => {
if(window.KeymanWeb) {
window.KeymanWeb.uninstall();
if(window['KeymanWeb']) {
window['KeymanWeb'].uninstall();
}
})

it('`window`, disabled rule processing', async () => {
const harness = new KeyboardHarness(window, MinimalKeymanGlobal);
let keyboardLoader = new DOMKeyboardLoader(harness);
let keyboard = await keyboardLoader.loadKeyboardFromPath('/resources/keyboards/khmer_angkor.js');
let keyboard: Keyboard = await keyboardLoader.loadKeyboardFromPath('/resources/keyboards/khmer_angkor.js');

assert.isOk(keyboard);
assert.equal(keyboard.id, 'Keyboard_khmer_angkor');
assert.isTrue(keyboard.isChiral);
assert.isFalse(keyboard.isCJK);
assert.isOk(window.KeymanWeb);
assert.isOk(window.keyman);

// Should be not be modified by the keyboard load; it is not activated by default.
assert.isNotOk(harness.activeKeyboard);
assert.isOk(window['KeymanWeb']);
assert.isOk(window['keyman']);

// Should be cleared post-keyboard-load.
assert.isNotOk(harness.loadedKeyboard);
Expand All @@ -42,24 +39,24 @@ describe('Keyboard loading in DOM', function() {
it('`window`, enabled rule processing', async () => {
const harness = new KeyboardInterface(window, MinimalKeymanGlobal);
const keyboardLoader = new DOMKeyboardLoader(harness);
const keyboard = await keyboardLoader.loadKeyboardFromPath('/resources/keyboards/khmer_angkor.js');
const keyboard: Keyboard = await keyboardLoader.loadKeyboardFromPath('/resources/keyboards/khmer_angkor.js');
harness.activeKeyboard = keyboard;

assert.isOk(keyboard);
assert.equal(keyboard.id, 'Keyboard_khmer_angkor');
assert.isTrue(keyboard.isChiral);
assert.isFalse(keyboard.isCJK);
assert.isOk(window.KeymanWeb);
assert.isOk(window.keyman);
assert.isOk(window['KeymanWeb']);
assert.isOk(window['keyman']);

// TODO: verify actual rule processing.
const nullKeyEvent = keyboard.constructNullKeyEvent(device);
const mock = new Mock();
const result = harness.processKeystroke(mock, nullKeyEvent);

assert.isOk(result);
assert.isOk(window.KeymanWeb);
assert.isOk(window.keyman);
assert.isOk(window['KeymanWeb']);
assert.isOk(window['keyman']);

// Should be cleared post-keyboard-load.
assert.isNotOk(harness.loadedKeyboard);
Expand All @@ -70,7 +67,7 @@ describe('Keyboard loading in DOM', function() {
let keyboardLoader = new DOMKeyboardLoader(harness);

// Preload a keyboard and make it active.
const test_kbd = await keyboardLoader.loadKeyboardFromPath('/resources/keyboards/test_917.js');
const test_kbd: Keyboard = await keyboardLoader.loadKeyboardFromPath('/resources/keyboards/test_917.js');
harness.activeKeyboard = test_kbd;
assert.isNotOk(harness.loadedKeyboard);

Expand Down
26 changes: 0 additions & 26 deletions common/web/keyboard-processor/tests/dom/manual.conf.cjs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @ts-check
import BASE_CONFIG from './web-test-runner.config.mjs';
import teamcityReporter from '@keymanapp/common-test-resources/test-runner-TC-reporter.mjs';
import { sessionStabilityReporter } from '@keymanapp/common-test-resources/test-runner-stability-reporter.mjs';

/** @type {import('@web/test-runner').TestRunnerConfig} */
export default {
...BASE_CONFIG,
reporters: [
teamcityReporter(), /* custom-written, for CI-friendly reports */
sessionStabilityReporter({ciMode: true})
]
}
62 changes: 62 additions & 0 deletions common/web/keyboard-processor/tests/dom/web-test-runner.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// @ts-check
import { devices, playwrightLauncher } from '@web/test-runner-playwright';
import { esbuildPlugin } from '@web/dev-server-esbuild';
import { defaultReporter, summaryReporter } from '@web/test-runner';
import { LauncherWrapper, sessionStabilityReporter } from '@keymanapp/common-test-resources/test-runner-stability-reporter.mjs';
import { importMapsPlugin } from '@web/dev-server-import-maps';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';

const dir = dirname(fileURLToPath(import.meta.url));
const KEYMAN_ROOT = resolve(dir, '../../../../..');

/** @type {import('@web/test-runner').TestRunnerConfig} */
export default {
// debug: true,
browsers: [
new LauncherWrapper(playwrightLauncher({ product: 'chromium' })),
new LauncherWrapper(playwrightLauncher({ product: 'firefox' })),
new LauncherWrapper(playwrightLauncher({ product: 'webkit', concurrency: 1 })),
],
concurrency: 10,
nodeResolve: true,
files: [
'**/*.spec.ts'
],
middleware: [
// Rewrites short-hand paths for test resources, making them fully relative to the repo root.
function rewriteResourcePath(context, next) {
if(context.url.startsWith('/resources/')) {
context.url = '/common/test' + context.url;
}

return next();
}
],
plugins: [
esbuildPlugin({ts: true, target: 'auto'}),
importMapsPlugin({
inject: {
importMap: {
// Redirects `eventemitter3` imports to the bundled ESM library. The standard import is an
// ESM wrapper around the CommonJS implementation, and WTR fails when it hits the CommonJS.
imports: {
'eventemitter3': '/node_modules/eventemitter3/dist/eventemitter3.esm.js'
}
}
}
})
],
reporters: [
summaryReporter({}), /* local-dev mocha-style */
sessionStabilityReporter({}),
defaultReporter({})
],
/*
Un-comment the next two lines for easy interactive debugging; it'll launch the
test page in your preferred browser.
*/
// open: true,
// manual: true,
rootDir: KEYMAN_ROOT
}
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0cd83b2

Please sign in to comment.