Skip to content

Run load tests

Files named <name>.load.<ext> are load tests. The node presets recognize them but leave them out of a normal run, and always leave them out of coverage. This guide adds a second config that runs them.

  1. Name the load test files <name>.load.<ext>, such as src/api.load.ts. Put them in the source folder with the other tests.

  2. Create a second config that spreads configs.nodeLoad over your preset:

    jest.load.config.mjs
    import { configs } from '@repobuddy/jest'
    export default {
    preset: '@repobuddy/jest/presets/ts-esm',
    ...configs.nodeLoad,
    }

    Your testRegex and coveragePathIgnorePatterns replace the preset’s.

  3. Add a script:

    {
    "scripts": {
    "test:load": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --config jest.load.config.mjs"
    }
    }

    Drop NODE_OPTIONS for a CommonJS preset.

Pass both identifier lists to configs.configNode():

jest.config.mjs
import { configs } from '@repobuddy/jest'
export default {
preset: '@repobuddy/jest/presets/ts-esm',
...configs.configNode([...configs.defaultTestIdentifiers, ...configs.loadTestIdentifiers]),
}
jest.load.config.mjs
import { configs } from '@repobuddy/jest'
export default {
preset: '@repobuddy/jest/presets/ts-esm',
...configs.nodeLoad,
}
  1. Check that the normal run skips the load test:

    Terminal window
    jest --listTests
  2. Check that the load config finds only load tests:

    Terminal window
    jest --config jest.load.config.mjs --listTests

In the ts-cjs fixture, the normal run lists 14 files and not nodejs.load.ts. A config of ts plus configs.nodeLoad lists only nodejs.load.ts.

  • Only the node presets have load test support. configs.jsdom has a fixed glob with no load identifier.
  • Load tests can also target a Node.js major: <name>.load.node20.ts.