@magic/test

Performance Tips

Follow these tips to get the most out of @magic/test:

Use the -p Flag

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

# Fast mode - no coverage, only shows failuresnpm test# ort -p

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 deterministically using a hash of the test file path.

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:

# Use 2 workerst -p --workers 2

Link: CLI & Usage for full flag reference.