Skip to content

fix(typescript): unique temp file names to fix run-multiple race (#5642)#5643

Merged
DavertMik merged 1 commit into
codeceptjs:4.xfrom
mirao:fix/5642-run-multiple-temp-mjs-race
Jun 17, 2026
Merged

fix(typescript): unique temp file names to fix run-multiple race (#5642)#5643
DavertMik merged 1 commit into
codeceptjs:4.xfrom
mirao:fix/5642-run-multiple-temp-mjs-race

Conversation

@mirao

@mirao mirao commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #5642.

Under run-multiple, tests intermittently fail with Cannot find module *.temp.mjs / ENOENT.

The built-in TypeScript transpiler writes each transpiled file to a fixed <source>.temp.mjs path next to the source. run-multiple forks one OS process per browsers entry, all at once, and each worker transpiles the same config/helper/include files to the same temp paths and then deletes them on cleanup. Workers race over the shared paths, so one worker's cleanup removes files another worker still needs to import.

Fix

Include process.pid plus a short random suffix in the temp file name (<source>.<pid>.<rand>.temp.mjs), so each worker writes and removes only its own files.

  • All import/require rewrites resolve through the existing transpiledFiles map, so rewritten references automatically point at the unique names — no other changes needed.
  • The names still end in .temp.mjs, so the stack-trace remapping in lib/step/base.js and fixErrorStack keep working unchanged.

Test

Added test/unit/utils/typescript_test.js: two transpilation runs of the same fixture must produce disjoint temp-file sets. It fails on the old code (temp files were shared between invocations) and passes with the fix.

🤖 Generated with Claude Code

…eceptjs#5642)

Transpiled TypeScript files were written to a fixed "<source>.temp.mjs"
path next to the source. Under run-multiple, every forked worker transpiles
the same files to the same temp paths and cleans them up independently, so
one worker's cleanup deletes files the others still need to import — surfacing
as "Cannot find module *.temp.mjs".

Include process.pid plus a random suffix in the temp file name so each worker
writes (and removes) its own files. The names still end in ".temp.mjs", so
stack-trace remapping and fixErrorStack keep working.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@DavertMik DavertMik merged commit 060d72a into codeceptjs:4.x Jun 17, 2026
11 of 13 checks passed
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.x: The test in the mode "run-multiple" sometimes fails: "Cannot find module *.temp.mjs"

2 participants