@magic/test

Performance Tips

make runs faster:

Use the -p Flag

Run tests in production mode to skip coverage and get faster output:

# fast mode - no coverage, only shows failurest -p# or via the recommended npm scriptnpm test

Shard Large Test Suites

Split tests across multiple processes to speed up large suites:

# Split tests across 4 processest --shards 4 --shard-id 0

tests are distributed with a hash of the file path — same file, same shard.

Minimize Async Overhead

Async tests are slower than sync tests. Use sync where possible:

# Slower: unnecessary asyncexport default {  fn: async () => true,  expect: true,}# Faster: sync testexport default {  fn: () => true,  expect: true,}

Use Local State Instead of Globals

Global state requires isolation overhead. Local state is naturally isolated:

# Slower: global state requires isolationexport const __isolate = true# Faster: local state is naturally isolatedexport default [  {    fn: () => {      const counter = 0      return ++counter    },    expect: 1,  },]

Batch Related Tests

Single suite with multiple tests is faster than multiple suites:

# Faster: single suite with multiple testsexport default [  { fn: () => add(1, 2), expect: 3 },  { fn: () => add(0, 0), expect: 0 },  { fn: () => add(-1, 1), expect: 0 },]

Worker Concurrency

Control max parallel workers with the --workers flag. Default is auto-detect CPU count:

Control max parallel workers with the --workers flag. The auto default spawns max(1, min(CPUs - 2, 4)) workers, and throttles itself on a busy machine (MAGIC_TEST_ADAPTIVE=0 or CI disables it):

# use 2 workerst -p --workers 2

Be nice

on a busy machine the run is wrapped in nice (default 10) so your own work stays responsive. --nice 0 disables it:

t --nice 5t --nice 0

Compile cache

svelte and ts compilation is cached persistently between runs. Set MAGIC_TEST_COMPILE_CACHE=0 to restore the old always-recompile behavior:

MAGIC_TEST_COMPILE_CACHE=0 t -p

see CLI & Usage for the full flag reference.