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.
-
Name the load test files
<name>.load.<ext>, such assrc/api.load.ts. Put them in the source folder with the other tests. -
Create a second config that spreads
configs.nodeLoadover your preset:jest.load.config.mjs import { configs } from '@repobuddy/jest'export default {preset: '@repobuddy/jest/presets/ts-esm',...configs.nodeLoad,}Your
testRegexandcoveragePathIgnorePatternsreplace the preset’s. -
Add a script:
{"scripts": {"test:load": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --config jest.load.config.mjs"}}Drop
NODE_OPTIONSfor a CommonJS preset.
Run both kinds in one config
Section titled “Run both kinds in one config”Pass both identifier lists to configs.configNode():
import { configs } from '@repobuddy/jest'
export default { preset: '@repobuddy/jest/presets/ts-esm', ...configs.configNode([...configs.defaultTestIdentifiers, ...configs.loadTestIdentifiers]),}Finished config
Section titled “Finished config”import { configs } from '@repobuddy/jest'
export default { preset: '@repobuddy/jest/presets/ts-esm', ...configs.nodeLoad,}Verify
Section titled “Verify”-
Check that the normal run skips the load test:
Terminal window jest --listTests -
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.
Limits
Section titled “Limits”- Only the node presets have load test support.
configs.jsdomhas a fixed glob with noloadidentifier. - Load tests can also target a Node.js major:
<name>.load.node20.ts.