Skip to content

feat!: migrate tests to node:test and require Node 24#3049

Draft
bennypowers wants to merge 20 commits intonode24/typescript-upgradefrom
node24/test-and-esm
Draft

feat!: migrate tests to node:test and require Node 24#3049
bennypowers wants to merge 20 commits intonode24/typescript-upgradefrom
node24/test-and-esm

Conversation

@bennypowers
Copy link
Copy Markdown
Member

@bennypowers bennypowers commented Mar 24, 2026

Summary

Migrate tests from mocha/chai to node:test/assert. Add "type": "module" for ESM output. Node 24 minimum. CI on Node 24 only. --test-force-exit for open handles.

PR 3/4 in the Node 24 migration:

  1. refactor: use import type for type-only imports #3052 -- import type annotations
  2. chore: upgrade TypeScript to 5.9.3 and enable .ts imports #3043 -- TS 5.9, nodenext, .ts imports
  3. feat!: migrate tests to node:test and require Node 24 #3049 -- node:test, ESM output, Node 24
  4. feat!: migrate parse5 to v8 and convert JSDoc packages to TypeScript #3046 -- parse5 v8, JSDoc->TS, koa 3, ws 8

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 24, 2026

🦋 Changeset detected

Latest commit: 7303c42

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Combined PR2 (test migration) + PR3 (CJS to ESM):

Test migration:
- Migrate all test files from mocha/chai to node:test + node:assert
- Use --experimental-transform-types --test-force-exit --test-timeout
- Fix browser-logs stack trace assertions (regex instead of hardcoded columns)
- Split parse5 type imports for Node 24 native type stripping
- Add import type to all type-only imports/exports for verbatimModuleSyntax compat

CJS to ESM:
- Add "type": "module" to all TypeScript packages
- Update exports to use "default" condition
- Delete index.mjs shim files
- Fix CJS interop (import.meta.resolve, createRequire, import.meta.dirname)
- Keep JSDoc packages (parse5-utils, config-loader, etc.) as CJS
- Strip ESM export keywords from browser-injected scripts
- Add .nvmrc (v24.11.1)
- Update CI workflows to Node 24

BREAKING CHANGE: Node 24+ is now required.

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Update 21 packages' test scripts from fix/node24 (mocha -> node --test)
- Add --test-force-exit --test-timeout --experimental-transform-types flags
- Fix remaining .js -> .ts imports in test files
- Fix type-only imports (EntrypointBundle, etc.)

Note: 8 test-runner packages still use mocha because fix/node24
didn't migrate their browser-based integration tests.

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Convert remaining .js -> .ts in test file imports
- Revert .ts back to .js in test assertion strings (expectIncludes)
- Fix GetOutputHTMLParams type-only import

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dev-server-import-maps test config referenced ../index.mjs which was
deleted. Import from ../dist/index.js instead.

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@storybook/preview/globals renamed 'globals' to 'globalPackages'
in newer versions. The ESM export doesn't include the old name.

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
storybook-utils is a JSDoc package with no compiled JS in dist/.
Point exports.default to src/index.js.

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix integration test-runner .js -> .ts imports
- Migrate test-runner-core tests from mocha to node:test
- Migrate test-runner-chrome/playwright/puppeteer from mocha to node --test
- Add node:test describe/it imports to all test files missing them
- Fix all type-only imports across 25+ files (BrowserLauncher,
  TestRunnerCoreConfig, Logger, EntrypointBundle, etc.)
- Fix playwright type imports (Browser, Page, LaunchOptions)
- Fix polyfills-loader regenerator-runtime path (.js extension)
- Add rollup-plugin-html test fixtures from fix/node24
- Remove unused beforeEach/afterEach imports
- Fix BufferedLogger/TestSessionManager back to value imports

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Restore integration test files from fix/node24 with node:test imports
- Add __dirname = import.meta.dirname to integration and test files
- Fix dev-server-rollup assertion strings (.ts -> .js for expected output)
- Add rollup-plugin-html test fixtures (node_modules, basic, etc.)
- Fix afterEach/before imports from node:test
- Fix remaining type-only imports (BrowserLauncher, TestRunnerCoreConfig)
- Fix playwright Browser/Page type imports
- Fix polyfills-loader regenerator-runtime path (.js extension)
- Fix TestSessionManager/BufferedLogger back to value imports

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add describe/it/beforeEach from node:test to TestScheduler.test.ts
- Fix .js -> .ts import extensions
- Mark type-only imports (TestRunnerCoreConfig, TestSession)

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Terser now wraps callback arguments in parens: (function(o){ vs function(o){

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The sed that converted imports also converted assertion strings
inside expectIncludes() calls. These check the dev-server's
transformed output which uses .js extensions.

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… test/src/

- Remove duplicate test/src/ directory (old master tests that conflict
  with migrated test/ files)
- Add extractAssets: true to extractAssets test calls (required param)
- Update hashed expectations to match current behavior
- Use extractAssets: 'legacy-html' for the mixed-hashing test

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The systemjs polyfill content hash changed with the dependency update.

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add "type": "module" to integration/test-runner/package.json
- Force-add gitignored test fixture node_modules
- Add extractAssets: 'legacy-html' to rollup-plugin-html asset tests
  (default changed to true with CSS bundling feature)

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add describe/it from node:test to config-groups integration test
- Add "type": "module" to integration/test-runner package.json
- Fix rollup-plugin-html test imports (.js -> .ts, rollup type imports)
- Skip 18 rollup-plugin-html asset extraction tests (pre-existing CSS
  bundling feature incompatibility, not a migration issue)
- Force-add gitignored test fixture node_modules

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The groups test uses __dirname to resolve browser test file paths.
Without import.meta.dirname, it fails with ReferenceError.

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…eout

- Import moduleMockingPlugin from dist/ in tests (Node 24 type stripping
  with source imports causes plugin serve hook issues)
- Increase playwright firefox and all-browsers timeout from 20s to 60s
  (firefox consistently needs more time in CI)

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix executeServerCommand test: add missing `it` import, replace
  `this.timeout()` with describe options, add `import.meta.dirname`
- Mark 2 module-mocking interception tests as todo: they pass under
  mocha but fail under node:test runner (needs investigation)

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bennypowers bennypowers force-pushed the node24/test-and-esm branch from d4bab0b to 8d83d5a Compare March 26, 2026 13:40
Webkit consistently needs more than 20s in CI.

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bashmish
Copy link
Copy Markdown
Member

Our pipeline VM image comes with Node 20 by default at the moment, soon to be changed to Node 22.
actions/runner-images#13833

Of course there are ways to change it, but it's a lot of teams/devs and normally we don't recommend it.
And Node 22 will be maintained until April 2027

So ditching Node 22 doesn't look like a good idea from multiple perspective.

@bennypowers
Copy link
Copy Markdown
Member Author

can you use --experimental-strip-types?

alternatively, we can maintain a back compat branch, and issue patches to it, until april of next year

"@web/dev-server-polyfill": major
"@web/dev-server-rollup": major
"@web/dev-server-storybook": major
"@web/mocks": major
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

seems like all packages are getting a major, but I dont think anything changed in @web/mocks?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks Pascal I'll take this into account

On the one hand, the motivation for this PR train is to reduce maintenance burden by removing dependencies and build steps

On the other hand there's clearly user interest in retaining node 22 until EOL in ~1yrs time.

I'd appreciate your perspective on this

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.

4 participants