Conversation
nev21
commented
Feb 24, 2026
- add shared worrker adapter/runner
- switch worker Karma to mocha + karma-typescript and update globs
- drop unused karma-* deps and refresh rush shrinkwrap
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #519 +/- ##
==========================================
- Coverage 98.89% 98.71% -0.18%
==========================================
Files 108 111 +3
Lines 2981 3198 +217
Branches 622 674 +52
==========================================
+ Hits 2948 3157 +209
- Misses 33 41 +8 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR optimizes worker test execution by replacing the previous karma-rollup-preprocessor + karma-mocha-webworker setup with a more efficient mocha + karma-typescript configuration. This change addresses performance issues that required excessive memory allocation (16GB) and reduces test execution delays by implementing a custom worker adapter/runner infrastructure.
Changes:
- Removed unused karma dependencies (karma-coverage, karma-coverage-istanbul-reporter, karma-mocha-webworker, karma-rollup-preprocessor) and eliminated the need for NODE_OPTIONS memory limit workaround
- Added custom worker test infrastructure (worker-adapter.js and worker-test-runner.js) to bridge Karma and Web Worker environments
- Added environment validation tests for browser, node, and worker contexts to ensure tests run in the correct environment
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Removed unused karma dependencies and eliminated NODE_OPTIONS memory limit from worker test scripts |
| karma.worker.conf.js | Switched from rollup preprocessor to karma-typescript with updated file patterns and coverage configuration |
| karma.worker.esnext.conf.js | Same changes as worker.conf.js but configured for ESNext target |
| karma.debug.worker.conf.js | Debug configuration updated to use karma-typescript instead of rollup |
| karma.debug.worker.esnext.conf.js | Debug ESNext configuration updated to use karma-typescript |
| common/test/worker-adapter.js | New file implementing the main-thread adapter that creates workers and bridges test results to Karma |
| common/test/worker-test-runner.js | New file implementing the worker-thread runner that loads and executes tests in worker context |
| lib/test/src/worker/isWorker.test.ts | New test file validating worker environment detection |
| lib/test/src/node/isNode.test.ts | New test file validating node environment detection |
| lib/test/src/browser/isBrowser.test.ts | New test file validating browser environment detection |
nevware21-bot
left a comment
There was a problem hiding this comment.
Approved by nevware21-bot
89aa919 to
65ed40e
Compare
- add shared worrker adapter/runner - switch worker Karma to mocha + karma-typescript and update globs - drop unused karma-* deps and refresh rush shrinkwrap
| */ | ||
|
|
||
| import { assert } from "@nevware21/tripwire-chai"; | ||
| import { hasDocument, hasWindow, isNode, isWebWorker } from "@nevware21/ts-utils"; |
There was a problem hiding this comment.
These tests import environment helpers from the published package entrypoint ("@nevware21/ts-utils"), while the rest of the test suite consistently imports from the local source tree (e.g., browser.environment.test.ts imports from "../../../src/helpers/environment"). Importing from the package here can unintentionally test the prebuilt dist output instead of the code under test and can mask source-only changes. Consider switching these imports to the matching local src module path.
| import { hasDocument, hasWindow, isNode, isWebWorker } from "@nevware21/ts-utils"; | |
| import { hasDocument, hasWindow, isNode, isWebWorker } from "../../../src/helpers/environment"; |
| // Default to using edge locally -- choose your own browser as required | ||
| process.env.CHROME_BIN = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"; | ||
| //process.env.CHROME_BIN = require("puppeteer").executablePath(); |
There was a problem hiding this comment.
CHROME_BIN is hard-coded to a Windows-specific Edge install path. This makes the debug worker config fail on macOS/Linux (and on Windows machines with Edge in a different location). Prefer using an environment override if provided, and otherwise default to Puppeteer’s executablePath so the config is portable.
| // Default to using edge locally -- choose your own browser as required | |
| process.env.CHROME_BIN = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"; | |
| //process.env.CHROME_BIN = require("puppeteer").executablePath(); | |
| // Prefer an environment-provided CHROME_BIN; otherwise, fall back to Puppeteer's executablePath for portability | |
| if (!process.env.CHROME_BIN) { | |
| try { | |
| process.env.CHROME_BIN = require("puppeteer").executablePath(); | |
| } catch (e) { | |
| // If puppeteer is not available, leave CHROME_BIN undefined and let Karma use its defaults | |
| } | |
| } |
| "test:worker": "karma start karma.worker.conf.js --single-run", | ||
| "test:worker_esnext": "karma start karma.worker.esnext.conf.js --single-run", |
There was a problem hiding this comment.
The worker test scripts no longer use cross-env (the NODE_OPTIONS wrapper was removed), but cross-env remains in devDependencies. If it’s no longer used elsewhere in the repo, consider removing it to reduce dependency footprint and avoid carrying an unused tool.
| case "complete": | ||
| karma.complete(msg.coverage ? { coverage: msg.coverage } : {}); | ||
| break; |
There was a problem hiding this comment.
After receiving the worker "complete" message, the Web Worker is left running. In watch/debug sessions this can leak workers and keep resources alive. Consider terminating the worker after calling karma.complete (and similarly on error paths).
| */ | ||
|
|
||
| import { assert } from "@nevware21/tripwire-chai"; | ||
| import { hasDocument, hasWindow, isNode, isWebWorker } from "@nevware21/ts-utils"; |
There was a problem hiding this comment.
These tests import environment helpers from the published package entrypoint ("@nevware21/ts-utils"), while the rest of the test suite consistently imports from the local source tree (e.g., node.environment.test.ts imports from "../../../src/helpers/environment"). Importing from the package here can unintentionally test the prebuilt dist output instead of the code under test and can mask source-only changes. Consider switching these imports to the matching local src module path.
| import { hasDocument, hasWindow, isNode, isWebWorker } from "@nevware21/ts-utils"; | |
| import { hasDocument, hasWindow, isNode, isWebWorker } from "../../../src/helpers/environment"; |
| */ | ||
|
|
||
| import { assert } from "@nevware21/tripwire-chai"; | ||
| import { hasDocument, hasWindow, isNode, isWebWorker } from "@nevware21/ts-utils"; |
There was a problem hiding this comment.
These tests import environment helpers from the published package entrypoint ("@nevware21/ts-utils"), while the rest of the worker/common test suite imports from the local source tree (e.g., worker.environment.test.ts imports from "../../../src/helpers/environment"). Importing from the package here can unintentionally test the prebuilt dist output instead of the code under test and can mask source-only changes. Consider switching these imports to the matching local src module path.
| import { hasDocument, hasWindow, isNode, isWebWorker } from "@nevware21/ts-utils"; | |
| import { hasDocument, hasWindow, isNode, isWebWorker } from "../../../src/helpers/environment"; |
| // Default to using edge locally -- choose your own browser as required | ||
| process.env.CHROME_BIN = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"; | ||
| //process.env.CHROME_BIN = require("puppeteer").executablePath(); |
There was a problem hiding this comment.
CHROME_BIN is hard-coded to a Windows-specific Edge install path. This makes the debug worker ESNext config fail on macOS/Linux (and on Windows machines with Edge in a different location). Prefer using an environment override if provided, and otherwise default to Puppeteer’s executablePath so the config is portable.
| // Default to using edge locally -- choose your own browser as required | |
| process.env.CHROME_BIN = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"; | |
| //process.env.CHROME_BIN = require("puppeteer").executablePath(); | |
| // Default to using a local Chromium-based browser. Allow override via CHROME_BIN and | |
| // fall back to Puppeteer's detected executablePath for portability across platforms. | |
| var puppeteer; | |
| if (!process.env.CHROME_BIN) { | |
| try { | |
| puppeteer = require("puppeteer"); | |
| if (puppeteer && typeof puppeteer.executablePath === "function") { | |
| process.env.CHROME_BIN = puppeteer.executablePath(); | |
| } | |
| } catch (e) { | |
| // eslint-disable-next-line no-console | |
| console.warn("puppeteer is not available; using system Chrome/Chromium resolution"); | |
| } | |
| } |
| case "error": | ||
| console.error("[worker-adapter] Worker error: " + msg.error); | ||
| karma.error("[worker-test] " + msg.error); | ||
| karma.complete({}); | ||
| break; |
There was a problem hiding this comment.
On the worker "error" message, the worker is not terminated. Consider terminating the worker after reporting the error/complete to avoid leaking a broken worker instance in watch/debug runs.
| sendMessage({ | ||
| type: "complete", | ||
| coverage: self.__coverage__ | ||
| }); |
There was a problem hiding this comment.
The worker sends the final "complete" message but does not close itself, so it can remain alive and retain memory after the run. Consider calling self.close() (after posting the complete message) to terminate cleanly.
| }); | |
| }); | |
| self.close(); |
nevware21-bot
left a comment
There was a problem hiding this comment.
Approved by nevware21-bot