Skip to content

Commit 61bd249

Browse files
committed
feat: put the test file isolation behind a build option
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.
1 parent 721033b commit 61bd249

5 files changed

Lines changed: 223 additions & 448 deletions

File tree

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,28 @@ Object.assign(globalThis, { Headers, Response });
198198

199199
The module is transformed and type checked like the test files are and it is not
200200
included in the npm package. It is loaded once for each of the emitted script
201-
and ESM output, before each test file.
201+
and ESM output, before any test file.
202+
203+
### Test File Isolation
204+
205+
All the test files run in the same process by default, so the module state of a
206+
test file can affect the next one. For example, the global hooks of
207+
`@std/testing/bdd` error with "Cannot add global hooks after a global test is
208+
registered" when a second test file uses them.
209+
210+
Set the `testIsolation` build option to `"process"` to run each test file in its
211+
own process, which is what `deno test` does by running each file in its own
212+
isolate:
213+
214+
```ts
215+
await build({
216+
// ...etc...
217+
testIsolation: "process",
218+
});
219+
```
220+
221+
This is slower because it starts a process per test file, and a preload module
222+
is loaded before each test file rather than once per output.
202223

203224
### Polyfills
204225

0 commit comments

Comments
 (0)