Skip to content

test: run the tests with expect-node - #869

Merged
mshima merged 2 commits into
yeoman:mainfrom
mshima:test-expect-node
Oct 21, 2026
Merged

mshima merged 2 commits into
yeoman:mainfrom
mshima:test-expect-node

Conversation

@mshima

@mshima mshima commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Run the tests with expect-node, node:test with the expect and mock API esmocha gives over mocha, in place of esmocha and c8.

  • The environment tests a lot how modules load (require of ES modules, the import() fallback, .cjs/.mjs/.ts fixtures, sibling modules): with node:test they load as node loads them, without a transform, the TypeScript run by the type stripping of node.
  • The API stays the one of esmocha: the imports of esmocha become the ones of expect-node, esmocha becoming exnode; the expect of Jest and jest-mock are the same, and the snapshot file is read as it is.
  • The module mocks: every export mocked without an implementation (exnode.mock<typeof import('execa')>('execa')), the exports given merged over the module (fly-import), all with reimport: a worker keeps the modules the previous test files imported, so the module under test imported by one of them would keep the module itself (with 2 or 4 workers, the actual fly-import installed a generator, the run taking about 110 s).
  • compatibility: 'mocha' keeps this.timeout, this.skip and the done tests; xit becomes it.skip.
  • workers run the test files by processes reused, like mocha --parallel; the coverage of src is node's. The run takes 7.9 to 9.6 s with 1 to 8 workers or a process per test file, test/resolver.ts alone taking about 6 s.
  • generator failing task emits error is skipped with yeoman-generator 4: it leaves the rejection of a failing task unhandled after the environment emits the error, which node:test reports and mocha ignored. The other versions cover the behavior.

Comparison

esmocha + c8 expect-node
tests 994 passing, 17 pending 993 passing, 18 skipped
time 9.8 s 8.3–8.5 s
statements / lines 93.5% 94.0%
branches 88.9% 89.2%
functions 92.1% 91.1% (counted otherwise by node)

Test plan

  • npm test (eslint, prettier, tsc, the tests with coverage)

🤖 Generated with Claude Code

The tests run with expect-node, node:test with the expect and mock API of
esmocha, in place of esmocha and c8: the modules of the code load as node
loads them, without a transform. The imports of esmocha become the ones of
expect-node (esmocha is exnode), the module mocks mock every export without
an implementation, and reimport where the module under test is imported
before them; the mocha compatibility keeps this.timeout, this.skip and done.
The test of a failing task is skipped with yeoman-generator 4, which leaves
its rejection unhandled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@socket-security

socket-security Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedexpect-node@​0.3.37810010093100

View full report

With the workers, a test file runs after others in a process that keeps the
modules they imported: the module under test imported by one of them kept the
modules themselves, like the actual fly-import installing a generator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mshima
mshima merged commit f88c714 into yeoman:main Oct 21, 2026
15 of 16 checks passed
@mshima
mshima deleted the test-expect-node branch October 21, 2026 13:09
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.

1 participant