Skip to content

Should we switch SWC or Esbuild for the Test Runners? #1042

Open

Description

@iHiD

@SleeplessByte As discussed on whatsapp! Two potentially alternatives, both faster, only real difference is some error messages change.

Draft PRs:

To my eyes, both seems good with like minimal changes for a 25% performance improvement. I don't think the error messages massive matter. Maybe SWC is better as it's slightly smaller, and we can use the same thing on TS from what I understood from your whataspp?

Let me know if there's a right/wrong decision here pls. And if we go with SWC, I'll get the console.log thing fixed there.

Activity

  1. SleeplessByte commented on Nov 21, 2026

    @SleeplessByte
    Member

    What i think would be worth to explore before going either direction is to see:

    1. Which one would translate well to the typescript repo? That repo has been reworked over time to be close to this one for easier maintenance. That's not necessarily a goal if we go the approach we are exploring (WhatsApp comments) but for Claude it would be easier if it's layered like that.
    2. The exceptions it's using Babel for should be explored if they can be addressed by either tool. Having both tools in this case would not be great as we would have to deal with quircks in both.
    3. The web based test runner needs to be taken into account with this change. It mocks a few things to be able to run in the browser but Claude can likely figure out the commonality with these.
    4. A reason we used Babel is because we tell people to install lts node which they then don't update. Babel was transpiling down to the node version or at least that was the idea when we started. That evolved over time. The question is if this is necessary at all and if core js is needed still or not.
    5. It's not been there for long but node I believe now understands es6 modules and they are baseline widely available now as well. This is the moment to switch to that. Doing these changes serially is suboptimal.

    Link what you and them AI think. Feel free to post in this issue tables of pros and cons. Just like the PR, forwarded content would be good to be marked as [NoRag] By AI. Use a GitHub interstitial.

    I'm fine in reducing DX slightly for these repos as they may not necessarily be touched by me directly.

  2. exercism-agent commented on Nov 23, 2026

    @exercism-agent
    Contributor

    @SleeplessByte A quick update on where this has got to.

    Per your conversations with @iHiD, we've moved away from swapping Babel for SWC or esbuild (those drafts are closed), and are now trying Node's built-in test runner with native ES modules instead:

    Still to try: the TypeScript version runs as CommonJS and is laid out differently from the JavaScript one, so we're now moving it to ES modules with the same files and structure, to keep the two runners as alike as possible. It also still loads the TypeScript compiler to find the tests, which we're removing.

    Both are drafts, up so you can see the direction. Nothing needs merging yet.

    If anything here looks fundamentally wrong to you (for example, any of the changes a student would see), that would be helpful to know. Otherwise I'll continue iterating and let you know when I think things are ready for you to look at if you want to.

  3. SleeplessByte commented on Nov 23, 2026

    @SleeplessByte
    Member

    Yes cool. I'll merge 1044 for now, as that was just waiting on data.

    Gimme some time to review the rest. I am 100% on making TS effectively extend the JS and thus also the browser one have similar interface. Easier to understand, easier to maintain, and easier to add a feature across all four (both browser and both system runners).

    What would help is if every JS idea is tested against TS (and of course still written in TS), so that approving a JS one is effectively also approving a TS one, and not that we do JS changes and find out it doesn't work in TS.

    Note: for TS tstsyche is the idea to teach people types fully. I will work this spring on a full track for typescript. Was not able to do that because of the lack-of-speed of node runner + tstsyche. So optimizing this that we can have both on an exercise (maybe run in parallel?) would be aswesome. There should be an example already... somewhre.

  4. exercism-agent commented on Nov 24, 2026

    @exercism-agent
    Contributor

    @SleeplessByte Thanks. On the type tests: exercism/typescript-test-runner#107 (draft, on top of #106) runs tstyche in the same process as the type check, reusing the files tsc has already parsed. tstyche was loading its own copy of TypeScript and parsing the DOM and Node types twice, which took about 3s on its own. An exercise with both runtime tests and type tests (lasagna) now runs in 2.4s instead of 5.2s, and the type tests add about 0.3s. Running tstyche in parallel saved nothing on the 2-CPU production machines. One change: the type tests now use the exercise's tsconfig, as they do locally, where before they used tstyche's defaults.

    Every JS change now has its TS counterpart:

    JS TS
    #1043 compile cache and prefetch exercism/typescript-test-runner#104
    #1044 --detectOpenHandles doesn't apply (the TS runner never used it)
    #1045 --forceExit exercism/typescript-test-runner#106 (--test-force-exit)
    #1046 acorn exercism/typescript-test-runner#106
    #1047 node --test and ES modules exercism/typescript-test-runner#106

    From here, I'll make each change in both runners together.

  5. SleeplessByte commented on Nov 24, 2026

    @SleeplessByte
    Member

    Okay.

    What's the order of reviewing and merging that's optimal?

  6. exercism-agent commented on Nov 24, 2026

    @exercism-agent
    Contributor

    @SleeplessByte This order works best:

    TypeScript, in stack order, as each PR builds on the one before:

    1. Report missing tests from the main Jest run (~13% faster) typescript-test-runner#103 (one Jest run instead of two)
    2. Warm up the image and prefetch files at the start of each run (~2.8x faster with all PRs) typescript-test-runner#104 (compile cache and prefetch)
    3. Write the JavaScript from the type check, and run Jest without a transformer (draft) typescript-test-runner#105 (tsc writes the JavaScript)
    4. Run the tests with Node's built-in test runner instead of Jest typescript-test-runner#106 (node --test and ES modules)
    5. Run the type tests in the same process as the type check typescript-test-runner#107 (type tests in the same process)

    JavaScript:

    1. Find the tests in the test file with acorn #1046 (find tests with acorn). It stands on its own.
    2. Run the tests with Node's built-in test runner and native ES modules #1047 (node --test and ES modules). Its setup, Jest API and reporter files are the same as TS Bump docker/login-action from 1.13.0 to 1.14.0 #106's, so it's easiest to review the two together.

    #1043 (compile cache) and #1045 (--forceExit) speed up the current Jest setup. #1047 already passes --test-force-exit, so if you're happy with the node --test direction, #1045 isn't needed, and I'll redo #1043's cache on top of #1047. If you'd rather have a quick win first, both can merge now.

  7. SleeplessByte commented on Nov 24, 2026

    @SleeplessByte
    Member

    Node --test is fine if you can confirm that it's no longer experimental in LTS

  8. exercism-agent commented on Nov 24, 2026

    @exercism-agent
    Contributor

    @SleeplessByte node --test itself is stable: Node marked the test runner stable in v20.0.0, and in the current LTS (24) the parts the runners rely on have no experimental status. That covers test/describe, reporters, --test-timeout, --test-force-exit, and --test-isolation, which dropped its --experimental- prefix in v23.6.0. (Source: https://nodejs.org/docs/latest-v24.x/api/test.html and https://nodejs.org/docs/latest-v24.x/api/cli.html.)

    Three smaller APIs used by the drafts aren't stable yet:

    • mock.module (--experimental-test-module-mocks, "Early development"). Only fruit-picker's jest.mock uses it in JavaScript. If we'd rather avoid it, fruit-picker's test could be changed to inject the dependency instead of mocking the module.
    • module.registerHooks ("Release candidate" since v24.13.1). Both runners use it so that @jest/globals resolves to the runner's Jest API and imports without .js keep working. The first part could be a small real package in the image instead. The second would need the track's test files to import with .js, which is a mechanical change across the exercises.
    • module.stripTypeScriptTypes ("Release candidate"). Only the TypeScript runner uses it, to find the tests. It can switch to TypeScript's own parser, which is already loaded for the type check.

    I'd remove the last one either way. Would you like me to remove the other two as well, including the track changes, so that nothing experimental is left?

  9. SleeplessByte commented on Nov 24, 2026

    @SleeplessByte
    Member

    Yes. We cannot use experimental because it has calling impact for cli users.

    1. For mock we can continue to use jest.mocks or write our own.
    2. We should rewrite all imports. Typescript wants it too anyway so let's go consistency
    3. We don't want to strip types but transpile so let's keep using TSC.

    Removing everything else indeed. This will be the way. Switching to the node runner should be one PR. The big extension rewrite a single commit.

    Now another question: we used Babel to transpile new features to the users' node. Why do we no longer need that and can we also drop core-js or is that something we should keep?

  10. exercism-agent commented on Nov 24, 2026

    @exercism-agent
    Contributor

    @SleeplessByte Thanks. This is the plan:

    On Babel and core-js: the preset targets node: 'current', which in the runner is the image's Node (24). So Babel only ever converted ES modules to CommonJS for Jest, and transpiled no syntax. core-js only adds built-ins that the image's Node doesn't have yet. On Node 24 that is Error.isError, Math.sumPrecise, the Uint8Array base64 and hex methods, and fixes to structuredClone. Without core-js, a solution using one of those will fail with "is not a function". Students running the tests locally use the track's own Babel setup, so the runner's change doesn't affect them.

    We can drop core-js completely, or preload only those few polyfills, which costs almost nothing. Let me know which you would prefer.

  11. SleeplessByte commented on Nov 24, 2026

    @SleeplessByte
    Member

    Babel was used to find which modules to load. Is there a more efficient way to do that?

    And to confirm. This also means we're going full es modules!?

  12. exercism-agent commented on Nov 24, 2026

    @exercism-agent
    Contributor

    @SleeplessByte Yes, Babel's useBuiltIns: 'usage' read each file and added imports for the core-js modules it used. A cheaper way is to preload, on every run, the eleven core-js modules for built-ins Node 24 doesn't have yet, with --import. That doesn't need any parsing. Locally that adds about 20ms to a run. Once the image moves to a newer Node, the list gets shorter.

    And yes, this is full ES modules. Node loads the test file and the solution as native ES modules and resolves their imports itself, with nothing converting them first.

  13. exercism-agent commented on Nov 24, 2026

    @exercism-agent
    Contributor

    @SleeplessByte The changes are up:

    One thing needs your decision. Node's syntax detection is marked "Release candidate" in the Node 24 and 26 docs. It is on by default, with no flag or warning, and the JavaScript runner relies on it, so that grep's CommonJS test file and CommonJS solutions keep working. To avoid it, the runner would set "type": "module". Then grep's test file would need to use import, and CommonJS solutions (13 of 11,083 in a week) would fail to load. Let me know which you would prefer.

  14. SleeplessByte commented on Nov 24, 2026

    @SleeplessByte
    Member

    Release candidate is fine.

    Include the Babel load to the prs please.

  15. exercism-agent commented on Nov 24, 2026

    @exercism-agent
    Contributor

    @SleeplessByte Both are in now, in #1047 and exercism/typescript-test-runner#106:

    • core-js: the runners load the polyfills for the 15 built-ins missing from Node 24 on every run, without reading the files. That adds about 15ms. TypeScript moves from core-js 3.37 to 3.49, to match JavaScript, so Math.sumPrecise now works there too.
    • Release candidate APIs: the runners now use module.registerHooks for imports and jest.mock. That replaced the code that rewrote the imports in the files on disk, and the two runners' hooks are nearly identical. Nothing writes to the student's files any more.

    All the example solutions give the same results as on main (for JavaScript, with the track's test files from before and after exercism/javascript#2877).

  16. SleeplessByte commented on Nov 24, 2026

    @SleeplessByte
    Member

    Great. I will review. In the meanwhile, please Create an extra follow-up pr that keeps the import list up to date:

    1. A script that lists them is best
    2. During the same major version of lts node we only add.
    3. Lets always target the lowest LTS until the highest current Stable (so never uneven numbers).
    4. If an old lts falls out of maintenance, core js imports only targeting them can be removed
    5. This should run as a target dispatch workflow, when the core js version changes, and on Cron
    6. The result should be a PR that fixes it (should run that check script and use it's results).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions