From b2598e76ba283cac1f36c0440d0f8a44c68e9b5f Mon Sep 17 00:00:00 2001 From: Joshua Horton Date: Tue, 11 Feb 2025 15:51:26 +0700 Subject: [PATCH] chore(web): fix coverage-reporting artifact Fixes: #13195 --- web/.c8rc.json | 12 ++++++++- web/build.sh | 26 ++++++++++++++----- web/common.inc.sh | 11 -------- web/src/app/browser/.c8rc.json | 10 +++++++ web/src/engine/attachment/.c8rc.json | 2 +- web/src/engine/common/web-utils/.c8rc.json | 2 +- web/src/engine/events/.c8rc.json | 2 +- web/src/engine/interfaces/.c8rc.json | 2 +- web/src/engine/keyboard-storage/.c8rc.json | 2 +- web/src/engine/keyboard/.c8rc.json | 2 +- .../engine/osk/gesture-processor/.c8rc.json | 2 +- .../predictive-text/templates/.c8rc.json | 2 +- .../predictive-text/wordbreakers/.c8rc.json | 2 +- .../worker-main/src/node/worker.ts | 4 +++ .../predictive-text/worker-thread/.c8rc.json | 2 +- .../engine/js-processor/basic-engine.tests.js | 5 +++- .../engine/js-processor/chirality.tests.js | 5 +++- .../engine/js-processor/deadkeys.tests.js | 5 +++- .../engine/unmatched_final_group.tests.js | 5 +++- web/src/test/auto/headless/getKeymanRoot.mjs | 12 +++++++++ 20 files changed, 83 insertions(+), 32 deletions(-) create mode 100644 web/src/app/browser/.c8rc.json create mode 100644 web/src/test/auto/headless/getKeymanRoot.mjs diff --git a/web/.c8rc.json b/web/.c8rc.json index f308b48487..070ef1b1d2 100644 --- a/web/.c8rc.json +++ b/web/.c8rc.json @@ -7,7 +7,17 @@ "reporter": ["text", "text-summary"], "reports-dir": "build/coverage", "src": [ - "**/src/", + "src/**", "../common/**/src" + ], + "include": [ + "src/**" + ], + "exclude": [ + "src/test/**", + "**/src/tests/**", + "**/build/**", + "src/tools/**", + "../node_modules/*" ] } diff --git a/web/build.sh b/web/build.sh index 5dd30f338f..0dd9b5ef53 100755 --- a/web/build.sh +++ b/web/build.sh @@ -141,12 +141,26 @@ test_action() { coverage_action() { builder_echo "Creating coverage report..." - cd "$KEYMAN_ROOT" - mkdir -p web/build/coverage/tmp - find . -type f -name coverage-\*.json -print0 | xargs -0 cp -t web/build/coverage/tmp - c8 report --config web/.c8rc.json ---reporter html --clean=false --reports-dir=web/build/coverage - rm -rf web/build/coverage/tmp - cd web + + # Always ensure our collation folder is clean, just in case something went wrong on a prior run. + rm -rf build/coverage/tmp + + # Also clean out the sub-report directories + main index.html; don't keep old ones if we fail! + rm -rf build/coverage/app + rm -rf build/coverage/engine + rm -f build/coverage/index.html + + # Collate the results into a single folder + mkdir build/coverage/tmp + find . -type f -name coverage-\*.json -print0 | xargs -0 cp -t build/coverage/tmp + + # Note for maintainers: the .c8rc.json config needs to be written from the perspective of + # the working directory - including its `include` and `exclude` entries. All ignores and + # such must be redefined in whatever that top-level .c8rc.json is. + c8 report --reporter html + + # No need to keep the collation folder around afterward; we can always redo that work. + rm -rf build/coverage/tmp } builder_run_child_actions build:engine/dom-utils diff --git a/web/common.inc.sh b/web/common.inc.sh index 429c9a9a8d..05c924d6ec 100644 --- a/web/common.inc.sh +++ b/web/common.inc.sh @@ -108,22 +108,11 @@ function test-headless() { TEST_CD_REQD=true fi - if [ $TEST_CD_REQD ]; then - # The mocha config needed to live-compile TS-based tests only applies - # if the command is started within the appropriate subfolder. - pushd "${TEST_BASE}" > /dev/null - TEST_BASE= - fi - if [[ -e .c8rc.json ]]; then c8 mocha --recursive "${TEST_BASE}${TEST_FOLDER}" $TEST_OPTS else mocha --recursive "${TEST_BASE}${TEST_FOLDER}" $TEST_OPTS fi - - if [ $TEST_CD_REQD ]; then - popd > /dev/null - fi } # Runs all headless tests (written in typescript) corresponding to the diff --git a/web/src/app/browser/.c8rc.json b/web/src/app/browser/.c8rc.json new file mode 100644 index 0000000000..3e9bef1df0 --- /dev/null +++ b/web/src/app/browser/.c8rc.json @@ -0,0 +1,10 @@ +{ + "check-coverage": false, + "clean": true, + "exclude-after-remap": true, + "reporter": ["text", "text-summary"], + "reports-dir": "../../../build/coverage/raw/app/browser", + "src": [ + "src/" + ] +} \ No newline at end of file diff --git a/web/src/engine/attachment/.c8rc.json b/web/src/engine/attachment/.c8rc.json index c789716cd5..eea63036d2 100644 --- a/web/src/engine/attachment/.c8rc.json +++ b/web/src/engine/attachment/.c8rc.json @@ -3,7 +3,7 @@ "clean": true, "exclude-after-remap": true, "reporter": ["text", "text-summary"], - "reports-dir": "build/coverage", + "reports-dir": "../../../build/coverage/raw/engine/attachment", "src": [ "src/" ] diff --git a/web/src/engine/common/web-utils/.c8rc.json b/web/src/engine/common/web-utils/.c8rc.json index 16a4e93b9c..4c652ff892 100644 --- a/web/src/engine/common/web-utils/.c8rc.json +++ b/web/src/engine/common/web-utils/.c8rc.json @@ -10,7 +10,7 @@ ], "exclude-after-remap": true, "reporter": ["text", "text-summary"], - "reports-dir": "build/coverage", + "reports-dir": "../../../build/coverage/raw/raw/engine/common/web-utils", "src": [ "src/" ] diff --git a/web/src/engine/events/.c8rc.json b/web/src/engine/events/.c8rc.json index c789716cd5..65dd2858d4 100644 --- a/web/src/engine/events/.c8rc.json +++ b/web/src/engine/events/.c8rc.json @@ -3,7 +3,7 @@ "clean": true, "exclude-after-remap": true, "reporter": ["text", "text-summary"], - "reports-dir": "build/coverage", + "reports-dir": "../../../build/coverage/raw/engine/events", "src": [ "src/" ] diff --git a/web/src/engine/interfaces/.c8rc.json b/web/src/engine/interfaces/.c8rc.json index c42b096f68..ebcb215dba 100644 --- a/web/src/engine/interfaces/.c8rc.json +++ b/web/src/engine/interfaces/.c8rc.json @@ -3,7 +3,7 @@ "clean": true, "exclude-after-remap": true, "reporter": ["text", "text-summary"], - "reports-dir": "../../../build/engine/interfaces/coverage", + "reports-dir": "../../../build/coverage/raw/engine/interfaces", "src": [ "src/" ] diff --git a/web/src/engine/keyboard-storage/.c8rc.json b/web/src/engine/keyboard-storage/.c8rc.json index c789716cd5..396d0ddcc5 100644 --- a/web/src/engine/keyboard-storage/.c8rc.json +++ b/web/src/engine/keyboard-storage/.c8rc.json @@ -3,7 +3,7 @@ "clean": true, "exclude-after-remap": true, "reporter": ["text", "text-summary"], - "reports-dir": "build/coverage", + "reports-dir": "../../../build/coverage/raw/engine/keyboard-storage", "src": [ "src/" ] diff --git a/web/src/engine/keyboard/.c8rc.json b/web/src/engine/keyboard/.c8rc.json index ceca963e15..b6bd4a818f 100644 --- a/web/src/engine/keyboard/.c8rc.json +++ b/web/src/engine/keyboard/.c8rc.json @@ -8,7 +8,7 @@ ], "exclude-after-remap": true, "reporter": ["text", "text-summary"], - "reports-dir": "build/coverage", + "reports-dir": "../../../build/coverage/raw/engine/keyboard", "src": [ "src/" ] diff --git a/web/src/engine/osk/gesture-processor/.c8rc.json b/web/src/engine/osk/gesture-processor/.c8rc.json index 719cd11dae..24afdfdddf 100644 --- a/web/src/engine/osk/gesture-processor/.c8rc.json +++ b/web/src/engine/osk/gesture-processor/.c8rc.json @@ -11,7 +11,7 @@ "src/engine/headless/*" ], "reporter": ["text", "text-summary"], - "reports-dir": "build/coverage", + "reports-dir": "../../../../build/coverage/raw/engine/osk/gesture-processor", "src": [ "src/engine/headless/*" ] diff --git a/web/src/engine/predictive-text/templates/.c8rc.json b/web/src/engine/predictive-text/templates/.c8rc.json index d107a1cacb..b938594fb2 100644 --- a/web/src/engine/predictive-text/templates/.c8rc.json +++ b/web/src/engine/predictive-text/templates/.c8rc.json @@ -7,7 +7,7 @@ ], "exclude-after-remap": true, "reporter": ["text", "text-summary"], - "reports-dir": "build/coverage", + "reports-dir": "../../../../build/coverage/raw/engine/predictive-text/templates", "src": [ "src/" ] diff --git a/web/src/engine/predictive-text/wordbreakers/.c8rc.json b/web/src/engine/predictive-text/wordbreakers/.c8rc.json index 6a0e2589da..c2ea18e238 100644 --- a/web/src/engine/predictive-text/wordbreakers/.c8rc.json +++ b/web/src/engine/predictive-text/wordbreakers/.c8rc.json @@ -7,7 +7,7 @@ ], "exclude-after-remap": true, "reporter": ["text", "text-summary"], - "reports-dir": "build/coverage", + "reports-dir": "../../../../build/coverage/raw/engine/predictive-text/wordbreakers", "src": [ "src/" ] diff --git a/web/src/engine/predictive-text/worker-main/src/node/worker.ts b/web/src/engine/predictive-text/worker-main/src/node/worker.ts index 5ad04e55d0..aafb2c4869 100644 --- a/web/src/engine/predictive-text/worker-main/src/node/worker.ts +++ b/web/src/engine/predictive-text/worker-main/src/node/worker.ts @@ -6,6 +6,10 @@ import { LMLayerWorkerCode, LMLayerWorkerSourcemapComment } from "@keymanapp/lm- export default class Worker { static constructInstance(): Worker { let scriptStr = unwrap(LMLayerWorkerCode); + const srcMapUrlIndex = scriptStr.indexOf("//# sourceMappingURL") + if(srcMapUrlIndex > 0) { + scriptStr = scriptStr.substring(0, srcMapUrlIndex); + } scriptStr += '\n' + LMLayerWorkerSourcemapComment; let worker = new MappedWorker(scriptStr); diff --git a/web/src/engine/predictive-text/worker-thread/.c8rc.json b/web/src/engine/predictive-text/worker-thread/.c8rc.json index b66bb5b106..f30fb6465e 100644 --- a/web/src/engine/predictive-text/worker-thread/.c8rc.json +++ b/web/src/engine/predictive-text/worker-thread/.c8rc.json @@ -7,7 +7,7 @@ ], "exclude-after-remap": true, "reporter": ["text", "text-summary"], - "reports-dir": "build/coverage", + "reports-dir": "../../../../build/coverage/raw/engine/predictive-text/worker-thread", "src": [ "src/main" ] diff --git a/web/src/test/auto/headless/engine/js-processor/basic-engine.tests.js b/web/src/test/auto/headless/engine/js-processor/basic-engine.tests.js index 68eb5136e3..df63ec3106 100644 --- a/web/src/test/auto/headless/engine/js-processor/basic-engine.tests.js +++ b/web/src/test/auto/headless/engine/js-processor/basic-engine.tests.js @@ -9,6 +9,9 @@ import { KeyboardInterface } from 'keyman/engine/js-processor'; import { NodeKeyboardLoader } from 'keyman/engine/keyboard/node-keyboard-loader'; import { KeyboardTest, NodeProctor } from '@keymanapp/recorder-core'; +import { getKeymanRoot } from '../../getKeymanRoot.mjs'; +const KEYMAN_ROOT = getKeymanRoot(); + describe('Engine - Basic Simulation', function() { let testJSONtext = fs.readFileSync(require.resolve('@keymanapp/common-test-resources/json/engine_tests/basic_lao_simulation.json')); // Common test suite setup. @@ -25,7 +28,7 @@ describe('Engine - Basic Simulation', function() { before(async function() { // -- START: Standard Recorder-based unit test loading boilerplate -- let keyboardLoader = new NodeKeyboardLoader(new KeyboardInterface({}, MinimalKeymanGlobal)); - let keyboard = await keyboardLoader.loadKeyboardFromPath('../../../../../common/test/' + testSuite.keyboard.filename); + let keyboard = await keyboardLoader.loadKeyboardFromPath(KEYMAN_ROOT + '/common/test/' + testSuite.keyboard.filename); keyboardWithHarness = keyboardLoader.harness; keyboardWithHarness.activeKeyboard = keyboard; diff --git a/web/src/test/auto/headless/engine/js-processor/chirality.tests.js b/web/src/test/auto/headless/engine/js-processor/chirality.tests.js index c2220b7f5d..ea068e014d 100644 --- a/web/src/test/auto/headless/engine/js-processor/chirality.tests.js +++ b/web/src/test/auto/headless/engine/js-processor/chirality.tests.js @@ -10,6 +10,9 @@ import { NodeKeyboardLoader } from 'keyman/engine/keyboard/node-keyboard-loader' import { KeyboardTest, NodeProctor } from '@keymanapp/recorder-core'; import { ModifierKeyConstants } from '@keymanapp/common-types'; +import { getKeymanRoot } from '../../getKeymanRoot.mjs'; +const KEYMAN_ROOT = getKeymanRoot(); + describe('Engine - Chirality', function() { let testJSONtext = fs.readFileSync(require.resolve('@keymanapp/common-test-resources/json/engine_tests/chirality.json')); // Common test suite setup. @@ -26,7 +29,7 @@ describe('Engine - Chirality', function() { before(async function() { // -- START: Standard Recorder-based unit test loading boilerplate -- let keyboardLoader = new NodeKeyboardLoader(new KeyboardInterface({}, MinimalKeymanGlobal)); - let keyboard = await keyboardLoader.loadKeyboardFromPath('../../../../../common/test/' + testSuite.keyboard.filename); + let keyboard = await keyboardLoader.loadKeyboardFromPath(KEYMAN_ROOT + '/common/test/' + testSuite.keyboard.filename); keyboardWithHarness = keyboardLoader.harness; keyboardWithHarness.activeKeyboard = keyboard; diff --git a/web/src/test/auto/headless/engine/js-processor/deadkeys.tests.js b/web/src/test/auto/headless/engine/js-processor/deadkeys.tests.js index fd5d1457d3..ae67121dfd 100644 --- a/web/src/test/auto/headless/engine/js-processor/deadkeys.tests.js +++ b/web/src/test/auto/headless/engine/js-processor/deadkeys.tests.js @@ -9,6 +9,9 @@ import { KeyboardInterface } from 'keyman/engine/js-processor'; import { NodeKeyboardLoader } from 'keyman/engine/keyboard/node-keyboard-loader'; import { KeyboardTest, NodeProctor } from '@keymanapp/recorder-core'; +import { getKeymanRoot } from '../../getKeymanRoot.mjs'; +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. @@ -25,7 +28,7 @@ describe('Engine - Deadkeys', function() { before(async function() { // -- START: Standard Recorder-based unit test loading boilerplate -- let keyboardLoader = new NodeKeyboardLoader(new KeyboardInterface({}, MinimalKeymanGlobal)); - let keyboard = await keyboardLoader.loadKeyboardFromPath('../../../../../common/test/' + testSuite.keyboard.filename); + let keyboard = await keyboardLoader.loadKeyboardFromPath(KEYMAN_ROOT + '/common/test/' + testSuite.keyboard.filename); keyboardWithHarness = keyboardLoader.harness; keyboardWithHarness.activeKeyboard = keyboard; diff --git a/web/src/test/auto/headless/engine/js-processor/engine/unmatched_final_group.tests.js b/web/src/test/auto/headless/engine/js-processor/engine/unmatched_final_group.tests.js index 8bfee041eb..5ceaf40cf6 100644 --- a/web/src/test/auto/headless/engine/js-processor/engine/unmatched_final_group.tests.js +++ b/web/src/test/auto/headless/engine/js-processor/engine/unmatched_final_group.tests.js @@ -9,6 +9,9 @@ import { KeyboardInterface } from 'keyman/engine/js-processor'; import { NodeKeyboardLoader } from 'keyman/engine/keyboard/node-keyboard-loader'; import { KeyboardTest, NodeProctor } from '@keymanapp/recorder-core'; +import { getKeymanRoot } from '../../../getKeymanRoot.mjs'; +const KEYMAN_ROOT = getKeymanRoot(); + describe('Engine - Unmatched Final Groups', function() { let testJSONtext = fs.readFileSync(require.resolve('@keymanapp/common-test-resources/json/engine_tests/ghp_enter.json')); // Common test suite setup. @@ -24,7 +27,7 @@ describe('Engine - Unmatched Final Groups', function() { before(async function() { // -- START: Standard Recorder-based unit test loading boilerplate -- let keyboardLoader = new NodeKeyboardLoader(new KeyboardInterface({}, MinimalKeymanGlobal)); - const keyboard = await keyboardLoader.loadKeyboardFromPath('../../../../../common/test/' + testSuite.keyboard.filename); + const keyboard = await keyboardLoader.loadKeyboardFromPath(KEYMAN_ROOT + '/common/test/' + testSuite.keyboard.filename); keyboardWithHarness = keyboardLoader.harness; keyboardWithHarness.activeKeyboard = keyboard; diff --git a/web/src/test/auto/headless/getKeymanRoot.mjs b/web/src/test/auto/headless/getKeymanRoot.mjs new file mode 100644 index 0000000000..ce17cecd0f --- /dev/null +++ b/web/src/test/auto/headless/getKeymanRoot.mjs @@ -0,0 +1,12 @@ +import { createRequire } from 'module'; +import * as path from 'path' +const require = createRequire(import.meta.url); + +export function getKeymanRoot() { + let anchorPath = require.resolve('@keymanapp/common-test-resources/index.mjs'); + let root = path.dirname(anchorPath); + for(let i=0; i < 3; i++) { + root = path.dirname(root); + } + return root; +} \ No newline at end of file