Collapse pnpm test scripts into a single helper invocation#93097
Merged
Conversation
Each `pnpm test-*` script used to chain through several `pnpm run` + `cross-env` hops (e.g. test-dev-turbo -> with-turbo -> test-dev-inner -> testheadless -> testonly -> jest), adding a few hundred ms of Node/pnpm startup per hop. Route every test script through a new scripts/run-jest.sh that parses --mode/--bundler/--experimental/--headless flags, exports the matching env vars, and execs jest directly. Also drops the internal *-inner intermediates which are no longer needed. Public script names (test-dev-turbo, testonly-start-webpack, testheadless, testonly, etc.) are preserved so AGENTS.md and the contributing docs continue to work unchanged. Co-Authored-By: Claude <noreply@anthropic.com>
lukesandberg
commented
Apr 21, 2026
lukesandberg
commented
Apr 21, 2026
…est.sh. Adds a comment explaining that the bare `jest` invocation in scripts/run-jest.sh relies on being called from a pnpm/package-runner script (which prepends node_modules/.bin to $PATH). Also replaces the last `cross-env HEADLESS=true jest --runInBand` (testheadless) with `scripts/run-jest.sh --headless --` so there are no more cross-env hops in the test script chain. Co-Authored-By: Claude <noreply@anthropic.com>
lukesandberg
commented
Apr 21, 2026
sokra
approved these changes
Apr 21, 2026
Contributor
Author
Merge activity
|
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What?
Every
pnpm test-*/pnpm testonly-*script in the rootpackage.jsonis now a single direct invocation of a newscripts/run-jest.shhelper instead of chaining through severalpnpm run+cross-envlayers.Why?
Each hop through
pnpm run/cross-envspins up its own Node process and takes a few hundred milliseconds before anything useful happens. For example,pnpm test-dev-turboused to walk through five layers:Measured overhead (same machine, same stubbed jest invocation —
jest --version)jest --version(baseline, direct)pnpm test-dev-turbo --version(new)pnpm → bash → jestpnpm test-dev-turbo --version(old)pnpm → cross-env → pnpm → cross-env → pnpm → cross-env → pnpm → jestThat's ~2 seconds per test invocation shaved off, and ~85% reduction in wrapper overhead (from ~2414 ms to ~368 ms). The remaining ~368 ms is essentially just one
pnpm runstartup, which is unavoidable while we keep thepnpm test-*entry points.Real-world impact: for a ~72 s e2e test run this is ~3%, but for fast unit-test files (often <5 s) this is closer to 30-40%, and it adds up quickly in CI jobs that shell out to these scripts in a loop.
How?
scripts/run-jest.shparses named flags andexecs jest directly:--mode=<dev|start|deploy>→ setsNEXT_TEST_MODE--bundler=<webpack|turbo|rspack>→ setsIS_WEBPACK_TEST=1/IS_TURBOPACK_TEST=1/NEXT_RSPACK=1 NEXT_TEST_USE_RSPACK=1--experimental→ sets__NEXT_CACHE_COMPONENTS=true __NEXT_EXPERIMENTAL_APP_NEW_SCROLL_HANDLER=true--headless→ setsHEADLESS=true--terminates flag parsing; everything after is forwarded verbatim to jest so existing workflows likepnpm test-dev-turbo path/to/foo.test.ts -t "pattern"keep working.test-*/testonly-*entry inpackage.json(includingtestheadless) now reads likescripts/run-jest.sh --mode=dev --bundler=turbo --headless --. No morepnpm run/cross-envindirection at the top level.test-dev-inner,test-dev-experimental-inner,test-start-inner,test-start-experimental-inner,test-deploy-inner,testonly-dev-inner,testonly-start-inner,testonly-deploy-inner,test-inner). These were only called by other package.json scripts and not referenced anywhere else in the repo.testonly,testheadless, and all publictest-*/testonly-*names soAGENTS.md,contributing/core/testing.md,.conductor/, and.agents/skills/work unchanged.with-webpack,with-turbo,with-rspack, andwith-experimentalprefix scripts remain for ad-hoc use; they are just no longer in the hot path of the test scripts.scripts/run-jest.shinvokes a barejest, which resolves via$PATH(pnpm prependsnode_modules/.bin/when running a package script). The helper is documented as only supported when invoked through a package runner.Verification
Ran a small e2e test through the new chain in both dev+turbopack and start+webpack modes. Output confirms env vars propagate correctly (
PASS Turbopack .../PASS webpack ..., pluspnpm next --turbopackvspnpm next startin the logs):CI is unaffected: every workflow invokes
node run-tests.js ...directly, never through these pnpm scripts.