@magic/test
Test Isolation
@magic/test supports test isolation to prevent tests from affecting each other. Tests in the same suite can share state, but you can isolate them:
export default [// This test runs in isolation from others{fn: () => {const state = { counter: 0 }state.counter++return state.counter},expect: 1,info: 'isolated test with local state',},]
__isolate
Global Isolation Mode:
By default, tests in the same file share global state. To enable strict isolation where each test gets a fresh environment, add the __isolate export at the top of your test file:
export const __isolate = trueexport default [{ fn: () => (global.test = 1), expect: 1 },{ fn: () => global.test === undefined, expect: true, info: 'fresh global state' },]
each test starts with fresh globals.
Programmatic Detection
suiteNeedsIsolation(tests) tells you if a suite requires isolation:
import { suiteNeedsIsolation } from '@magic/test'const needsIsolation = suiteNeedsIsolation(tests)
for custom runners / test tooling.