Repository navigation
Run the tests with Node's built-in test runner and native ES modules - #1047
Draft
exercism-agent[bot] wants to merge 2 commits into
Draft
exercism-agent[bot] wants to merge 2 commits into
exercism-agent[bot] wants to merge 2 commits into
Conversation
Jest took almost all of each run: it set up its runtime and loaded Babel, which compiled every file to CommonJS. Node's test runner now runs the test file as a native ES module in the same process. src/setup.mts preloads a module hook, src/jest-globals.mts provides the Jest API the track uses (on Jest's expect and jest-mock), and src/reporter.mts turns the runner's events into the results src/output.ts writes, as before. jest.mock calls run before the test file loads, as Jest hoisted them, using Node's mock.module. Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 23, 2026
Draft
A test without `done` waits one turn of the event loop for unhandled rejections. If a slow synchronous test had already used up its 5 seconds, Node's timeout fired during that wait and failed it, though Jest passed it. Such a test now skips the wait. Node reports a test file that defines no tests as one passing test, named after the file. The reporter now reports that the file failed to run, with Jest's message. Both fixes match the TypeScript runner. Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Hello 🙂 I'm working with Claude to try and get our tooling faster.
This PR and #1046 together make this project around 4x faster. I've run it in production to benchmark things in the real world against the most recent few hundred solutions, so I'm confident that it works robustly. However, I've not written the code. I have tried my hardest to get Claude to write sensible messages and comments that explains stuff, but I'd ask for your patience in the fact I'm sending AI code to you. Everything below here is from your friendly neighbourhood LLM...
This is the second of two draft PRs, on top of #1046. It follows the direction discussed in #1042: Node's built-in test runner with native ES modules. If it merges, #1044 and #1045 (Jest flags) are no longer needed.
What changed
Almost all of each run was Jest starting up: reading its config, building its haste map, creating a VM context, and loading Babel to compile the test file and solution to CommonJS. The tests themselves took a few milliseconds.
The runner now runs the test file with
node --test, as native ES modules, with no transformer. The track's test files still use Jest's API from@jest/globals, so three small files provide it:src/setup.mts, preloaded with--import, registers a module hook. The hook points@jest/globalsat the runner's Jest API, and lets relative imports leave out.js, as Jest did.src/jest-globals.mtsdefines Jest's API:describe,test,itand their skip variants, the hooks,expect(Jest's own package) andjest(jest-mock's functions plusmock). It also makes them globals, as Jest did. Tests keep Jest's 5 second timeout anddonecallbacks.src/reporter.mtsturns Node's test events into the results Jest gave, and passes them to the existingsrc/output.ts. Soresults.jsonkeeps the same shape and content.Details that keep results matching Jest:
run.shpasses--test-isolation=none, so the tests run in the runner's process. That lets the reporter read console messages, whichjest-globals.mtsrecords with Jest'sBufferedConsole, sooutput.tsstill attributes them to the right test.jest.mockdoesn't apply. Before Node loads the test file,jest-globals.mtsfinds its top-leveljest.mockcalls with acorn and runs them through Node'smock.module(--experimental-test-module-mocks). Only fruit-picker usesjest.mock.run.shno longer copies the runner'spackage.jsoninto the solution folder, so no module type is set. Node then loads a file withimportorexportas an ES module and any other file as CommonJS, so CommonJS solutions and grep's test file keep working.src/syntax-error.tsfinds them with acorn and prints the error in the same layout as Babel's code frame.setup.mtsadds--colorstoprocess.argv, soexpectcolours its messages as it did under Jest.run.shpasses--test-force-exit, which ends the process once the tests finish.Jest, Babel, core-js and the Jest reporter packages are no longer dependencies.
run.shno longer linksnode_modulesinto the solution folder, so solutions can't import packages that only the runner uses. It runs the one test file named in the exercise's config, and writes the "no tests" error itself if that file is missing.What students will see
The track needs no changes. All 169 example solutions give the same results and messages as before, and so do the seven async examples. I also ran 210 recent production solutions (30 each for bank-account, fruit-picker, grep, parallel-letter-frequency, promises, react and translation-service). 204 of the 210 give the same result for every test. The rest are covered below.
__filename,__dirnameandrequiredon't exist in a solution that usesimportorexport. One parallel-letter-frequency solution goes from pass to fail. Only 8 of 11,083 JavaScript submissions from 15 to 22 November mixedrequirewithimportorexport.importmade Node warn on stderr about the copiedpackage.json, so every test failed. That warning no longer appears, and one solution goes from fail to pass.at get balancewhere Babel's output gaveat BankAccount.balance), and an unhandled rejection's error appears once instead of twice.test timed out after 5000ms.This has been tested in production, and with all the PRs merged has reduced the median run from 4.6s to 1.1s.
🤖 Generated with Claude Code