Skip to content

WEBUI-2038 : Migrate unit tests from Karma to Web Test Runner#3184

Open
madhurkulshrestha-hyland wants to merge 12 commits into
maintenance-3.1.xfrom
task-webui-2038-migrate-web-test-runner-lts2023
Open

WEBUI-2038 : Migrate unit tests from Karma to Web Test Runner#3184
madhurkulshrestha-hyland wants to merge 12 commits into
maintenance-3.1.xfrom
task-webui-2038-migrate-web-test-runner-lts2023

Conversation

@madhurkulshrestha-hyland
Copy link
Copy Markdown
Contributor

Summary

  • Replace @open-wc/karma-esm / Karma with @web/test-runner + Mocha TDD for unit tests
  • Reorganize test helper scripts under scripts/test/unit/ and scripts/test/ftest/
  • Restore full-tree coverage reporting for Sonar (bulk import + zero-coverage lcov injection)
  • Add dev-server fallbacks to suppress benign 404 / invalid JSON noise during tests
  • Fix related unit test failures (i18n stubs, bulk edit warning string)

Test plan

  • npm test — 1888 tests pass, coverage generated
  • npm run lint
  • CI test workflow green

JIRA: https://hyland.atlassian.net/browse/WEBUI-2038

Made with Cursor

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates the project’s unit-test harness from Karma (@open-wc/karma-esm) to Web Test Runner while keeping the existing “single barrel entry” approach (test/load-all-tests.js) and preserving broad coverage reporting for Sonar.

Changes:

  • Replace Karma config/runtime with web-test-runner.config.mjs and WTR-based npm test/npm run test:watch.
  • Reorganize test helper scripts into scripts/test/unit/ and scripts/test/ftest/, including coverage post-processing (zero-coverage injection).
  • Update docs/CI guidance to reflect the new unit test runner and the 1-entry-file execution model.

Reviewed changes

Copilot reviewed 27 out of 29 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
web-test-runner.config.mjs Adds Web Test Runner configuration (single entry file, coverage config, log filtering).
test/setup.js Updates shared Mocha bootstrap for WTR, coverage materialization tweaks, and async-error suppression logic.
test/nuxeo-edit-documents-button.test.js Updates expected i18n warning string.
test/nuxeo-dropzone.test.js Stubs i18n to avoid test failures under the new runner behavior.
test/nuxeo-document-create.test.js Stubs i18n to avoid test failures under the new runner behavior.
sonar-project.properties Updates comments to reference WTR-based coverage.
scripts/test/unit/web-test-runner-fallback-plugin.mjs Adds dev-server fallback responses to reduce noisy 404/invalid JSON during tests.
scripts/test/unit/web-test-runner-coverage-flag-plugin.mjs Injects a browser flag to let test/setup.js detect native V8 coverage runs.
scripts/test/unit/print-test-runner-notice.js Prints a banner explaining why WTR reports “1/1 test files”.
scripts/test/unit/inject-zero-coverage.js Post-processes lcov to add explicit 0%-coverage entries for manifest files missing from the report.
scripts/test/unit/generate-test-load-all.js Generates test/load-all-tests.js barrel used as the single WTR entry point.
scripts/test/unit/generate-coverage-imports.js Generates test/coverage-imports-data.js manifest for coverage materialization.
scripts/test/ftest/runner.js Moves functional test runner script under scripts/test/ftest/.
scripts/karma-esm-sequential-test-imports.js Removes unused Karma workaround script.
README.md Updates unit test description to mention WTR’s 1 entry file with many Mocha tests.
package.json Replaces Karma deps/scripts with WTR deps and new test pipeline scripts.
karma.conf.js Removes Karma configuration.
eslint.config.mjs Updates config-file linting target from karma.conf.js to web-test-runner.config.mjs.
CONTRIBUTING.md Updates test docs and CI description for WTR.
ARCHITECTURE.md Updates tech stack docs for WTR and script layout.
AGENTS.md Updates contributor workflow/testing notes for WTR.
.gitignore Updates comments for generated test barrel/coverage manifest scripts.
.github/workflows/test.yaml Updates workflow comments to reflect WTR-based npm test.
.github/skills/write-unit-test/SKILL.md Updates skill guidance to WTR workflow (regenerate barrel).
.github/skills/update-ai-context/SKILL.md Updates context guidance to reference WTR instead of Karma.
.github/instructions/unit-tests.instructions.md Updates unit-test instructions to WTR + barrel model.
.github/instructions/build-config.instructions.md Updates build-config instructions from Karma to WTR.
.github/copilot-instructions.md Updates repo instructions to reflect WTR unit testing.

Comment thread test/setup.js
Comment thread test/setup.js Outdated
Comment thread scripts/test/unit/web-test-runner-fallback-plugin.mjs Outdated
Comment thread scripts/test/unit/generate-coverage-imports.js Outdated
madhurkulshrestha-hyland added a commit that referenced this pull request May 24, 2026
Fix benign 404 suppression to accept error objects or message strings,
rephrase setup.js comment, rename fallbackBody parameter to avoid shadowing
path import, and update coverage-imports docs for Web Test Runner.

Co-authored-by: Cursor <cursoragent@cursor.com>
madhurkulshrestha-hyland added a commit that referenced this pull request May 24, 2026
Fix benign 404 suppression to accept error objects or message strings,
rephrase setup.js comment, rename fallbackBody parameter to avoid shadowing
path import, and update coverage-imports docs for Web Test Runner.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 28 out of 30 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

test/setup.js:180

  • The capture-phase unhandledrejection/error listeners stop propagation and preventDefault unconditionally. This can suppress real unhandled errors that occur during a test (not just “after test boundary”), causing tests to pass while errors are silently ignored. Consider only suppressing known-benign failures (e.g. based on _isBenignNuxeoNetworkFailure) or gating suppression to post-test situations so genuine async errors still fail the suite.
window.addEventListener(
  'unhandledrejection',
  (event) => {
    const reason = event.reason;
    _logIgnoredAsyncFailure('unhandledrejection', reason);
    event.stopImmediatePropagation();
    event.preventDefault();
  },
  true,
);

window.addEventListener(
  'error',
  (event) => {
    _logIgnoredAsyncFailure('error', event.error || event.message);
    event.stopImmediatePropagation();
    event.preventDefault();
  },
  true,

Comment thread scripts/test/unit/web-test-runner-coverage-flag-plugin.mjs Outdated
Comment thread web-test-runner.config.mjs
Comment thread scripts/test/ftest/runner.js Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 28 out of 30 changed files in this pull request and generated 2 comments.

Comment thread test/setup.js
Comment thread test/setup.js
madhurkulshrestha-hyland and others added 8 commits May 25, 2026 14:26
Replace @open-wc/karma-esm with @web/test-runner, reorganize test scripts,
restore full-tree coverage reporting for Sonar, and fix related test failures.

Co-authored-by: Cursor <cursoragent@cursor.com>
The load-all-tests.js graph is slow to transform on CI runners; 30s
browserStartTimeout caused false failures before Mocha could start.

Co-authored-by: Cursor <cursoragent@cursor.com>
System google-chrome-stable on GitHub runners mismatches puppeteer-core.
Pass puppeteer to chromeLauncher and install bundled Chromium in CI.

Co-authored-by: Cursor <cursoragent@cursor.com>
npm ci --ignore-scripts skips Puppeteer's browser download, so Sonar and
other workflows that run npm test failed to launch Chrome for Web Test Runner.

Co-authored-by: Cursor <cursoragent@cursor.com>
Fix benign 404 suppression to accept error objects or message strings,
rephrase setup.js comment, rename fallbackBody parameter to avoid shadowing
path import, and update coverage-imports docs for Web Test Runner.

Co-authored-by: Cursor <cursoragent@cursor.com>
WTR filterBrowserLogs only forwards error-level browser logs in CI,
so console.warn import failures were invisible unless WTR_VERBOSE=1.

Co-authored-by: Cursor <cursoragent@cursor.com>
Strip WTR query strings before matching setup.js for coverage flag injection,
log non-benign stray async failures as console.error, stop filtering those
logs in WTR config, and fix ftest runner cucumber report cleanup/spawn args.

Co-authored-by: Cursor <cursoragent@cursor.com>
Only suppress stray async errors outside active tests, fail coverage
materialization on import errors (Karma parity), and wrap long lines /
encode TINY_JPEG as base64 for max-len compliance.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 28 out of 30 changed files in this pull request and generated 2 comments.

Comment thread scripts/test/ftest/runner.js
Comment thread package.json
Add pretest:watch so watch mode installs Puppeteer Chromium, split the
TINY_JPEG base64 across short lines, and wrap the coverage manifest
expect.fail message for max-len readability.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 28 out of 30 changed files in this pull request and generated 2 comments.

Comment thread README.md Outdated
Comment thread scripts/test/unit/inject-zero-coverage.js
Add a Notes column to the README commands table and omit blank lines
from zero-coverage lcov DA/LF counts in inject-zero-coverage.js.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 28 out of 30 changed files in this pull request and generated no new comments.

madhurkulshrestha-hyland and others added 2 commits May 29, 2026 17:15
Use dev-server transform hook for coverage flag injection and add
empty Notes cells to all README command table rows.

Co-authored-by: Cursor <cursoragent@cursor.com>
Document --grep and setup-first entry files; warn that --files on a
suite alone skips test/setup.js and breaks globals.

Co-authored-by: Cursor <cursoragent@cursor.com>
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants