Repository navigation
test: run execution tests in Node with Jasmine instead of Karma - #1719
Merged
Merged
Conversation
Each test's main.js is now built for Node (target: 'node', inline source
map) using the module/resolve/resolveLoader settings from its
webpack.config.js, the same parts Karma used, and the bundle is run with
Jasmine 7 in-process. A test fails on build errors, failing specs, or no
specs running. --watch rebuilds and re-runs specs in a fresh process;
--debug still pauses on port 5858, now covering ts-loader and the specs.
- Remove karma, karma-chrome-launcher, karma-jasmine,
karma-mocha-reporter, karma-sourcemap-loader, karma-webpack, the
per-test karma.conf.js files and test/karmaConfig.js. Add jasmine 7
and @types/jasmine 7.
- Karma ran tests even when the build had errors, which hid two:
- basic: fix `declare module externalLib` (TS1540 on TypeScript 7)
to `declare namespace`.
- resolveModuleName: the option is inert on the TypeScript 7 API, so
skip it alongside loaderOptions until the API supports it.
- allowJs-entryFileIsJs gets a main.js like the other tests.
- CI no longer installs karma-webpack@4 for the webpack 4 runs.
- Update README, AGENTS.md and knip.json.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
Benchmark (macOS)
PR branch = |
Benchmark (Ubuntu)
PR branch = |
Benchmark (Windows)
PR branch = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1718. Please review and merge that first, after which GitHub will retarget this PR to
next.Replaces Karma and headless Chrome with a Node-based runner. No test needed a browser: the two React specs use the shallow renderer, and the only uses of
documentare in app entry files that the specs never load.How a test now runs
New
test/execution-tests/run-specs.js, run from each test's directory byrun-tests.js:main.js(which loads its*.tests.tsspecs withrequire.context) withtarget: 'node'anddevtool: 'inline-source-map', into a temporary folder that's deleted afterwards. Themode,module,resolveandresolveLoadersettings come from the test'swebpack.config.js, the same partstest/karmaConfig.jspassed to Karma.exitOnCompletion = false). Source maps are enabled, so failure stacks point at the TypeScript source, e.g.webpack:///test/app.tests.ts:9:52.incomplete, as it does when a focusedfit/fdescribeis left in.--watch(with--single-test) uses webpack's watch mode and runs the specs in a fresh child process after each successful build, so Jasmine's globals and the module cache start clean. Ctrl+C deletes the temporary folder.--debugstill runsnode --inspect-brk=5858, so the VS Code "Run open execution test" config works unchanged. The build and the specs now run in one process, so breakpoints work in bothsrc/and the specs. Under Karma, the specs ran in Chrome.main.js(justoptionsCaching) are still built byrun-webpack.js, as before.allowJs-entryFileIsJswas the one test whosekarma.conf.jslisted spec files with a glob instead ofmain.js. It now has amain.jslike the rest.Build errors now fail the test
Karma ran the specs even when webpack reported errors, which hid two broken tests:
basic:lib/externalLib.d.tsuseddeclare module externalLib { ... }, which TypeScript 7 rejects (TS1540). It's nowdeclare namespace externalLib.resolveModuleName: theresolveModuleNameloader option is accepted but does nothing on the TypeScript 7 API (as Support TypeScript 7.1 API #1704 notes), sofoo/bar/bazdon't resolve for type-checking (4 × TS2307). The specs passed only because webpack's own alias resolved the modules at runtime. It's now skipped, with the same reason asloaderOptions(which covers the also-inertgetCustomTransformers). The two skips share anunsupportedTestsmap inrun-tests.js, so both can be turned back on if the API adds these hooks.Dependencies
karma,karma-chrome-launcher,karma-jasmine,karma-mocha-reporter,karma-sourcemap-loader,karma-webpack(181 packages out ofnode_modules), the 26 per-testkarma.conf.jsfiles andtest/karmaConfig.js.jasmine@^7.0.0, and@types/jasminemoves from^4.6.6to^7.0.0to match. All the existing specs type-check and run unchanged on Jasmine 7.webpack@^4.47.0, withoutkarma-webpack@^4.0.2.knip.json:ignoreDependenciesdrops the Karma packages and addsjasmine.Docs
test/execution-tests/README.mdnow describesmain.js, whatrun-specs.jsdoes, when a test fails, that specs run in Node (so no browser APIs), and how watch and debug work.AGENTS.mdis updated to match, and no longer mentionslocalhost:9876.Notes
target: 'node'instead of Karma'swebchanges how webpack resolves packages: it ignores thebrowserfield, and code-split chunks load withrequireinstead of script tags. Every test passes either way. If a future test needs the browser build of a package, it can setresolve.aliasFields: ['browser']in its webpack config, andrun-specs.jspasses that through.karma-jasminedid. The default reporter prints dots plus failure details instead of each spec's name.Testing (local, macOS, Node 26, TypeScript 7.1.0-beta)
loaderOptionsandresolveModuleNameskipped), with the same number of specs per suite as under Karma. 16s, down from 35s.node16-file-suffixandoptionsCachingalso skipped, viatest.json).expect, a type error in a spec, and amain.jsthat matches no specs each exit with 1.--watch: re-ran after a spec was edited, and cleaned up on Ctrl+C.--debug: pauses with the debugger listening on 5858.lint,knip,format:checkand the threecheck:scripts.🤖 Generated with Claude Code