feat: add a testIsolation build option to run each test file in its own process - #514
Merged
Merged
Conversation
A test file's module state leaked into the next one because they were all loaded into the same process. With `@std/testing/bdd` this meant the global hooks of the second file either errored with "Cannot add global hooks after a global test is registered" or silently registered tests that never ran. `deno test` gives each test file its own isolate, so do the equivalent by spawning a process per file. Closes denoland#432
- make the fixture actually fail without the fix by having the second test file be the one that adds a global hook - forward the node arguments of the parent process to each child - report a spawn failure and an unknown file index - update the docs for the preload module running before each test file
Running each test file in its own process starts a process per test file, so make it opt in with `testIsolation: "process"` and keep running them all in the same process by default.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #432
The test runner loads every test file into the same process, so a test file's module state leaks into the next one. With
@std/testing/bddthe second file's global hooks hitTestSuiteInternal.started:...or, when the first file already created the global suite, the hooks silently attach to the already drained global test so those tests never run:
deno testgives each test file its own isolate. Since doing the equivalent means starting a process per test file, it's opt in:The generated runner then re-spawns itself once per test file. The children inherit stdio so the output is the same, the node arguments of the parent are forwarded, and the parent exits non-zero when any file fails. A preload module is loaded before each test file in this mode, which is what the isolation implies.
The default (
"none") keeps the current behavior of running everything in one process, so nothing changes for anyone who doesn't opt in.Added
tests/test_hooks_project, where the second test file adds a global hook. Loading both of its output files in one process errors with the message above, and the fixture passes withtestIsolation: "process".