@repobuddy/jest
@repobuddy/jest replaces a hand-written Jest config with one preset line. Pick the preset that matches the
language, the module format, and the test environment of the project. The package also exports the pieces each preset
is built from, a toSatisfies matcher, and a function that lists the packages a Jest config needs.
Install
Section titled “Install”# npmnpm install -D @repobuddy/jest
# yarnyarn add -D @repobuddy/jest
# pnpmpnpm add -D @repobuddy/jest
# rushrush add -p @repobuddy/jest --devThen install the peers your preset needs:
| Package | Peer range | Optional peer | Needed by |
|---|---|---|---|
jest |
>=29.5.0 |
no | every preset |
@swc/jest |
^0.2.31 |
no | ts-esm, jsdom-ts-esm, and ts / jsdom-ts in an ESM package |
ts-jest |
^29 |
yes | ts-cjs, jsdom-ts-cjs, and ts / jsdom-ts in a CommonJS package |
jest-esm-transformer-2 |
^1 |
yes | ts-cjs, jsdom-ts-cjs, js-cjs |
jest-watch-suspend |
^1 || ^2 |
yes | watch and every -watch preset |
jest-watch-toggle-config |
^3 |
yes | watch and every -watch preset |
jest-watch-typeahead |
^3.0.0 |
yes | watch and every -watch preset |
identity-obj-proxy |
^3.0.0 |
yes | fields.knownModuleNameMappers.cssAll only |
@swc/jest itself needs @swc/core (its own peer dependency). The jsdom presets also need jest-environment-jsdom,
which @repobuddy/jest does not declare. Each preset page lists the exact packages it references.
To list what a config needs, run buddy check-deps or call
extract.extractPackages().
Use a preset
Section titled “Use a preset”export default { preset: '@repobuddy/jest/presets/ts-watch',}ESM presets need Jest’s ESM support. Run Jest with NODE_OPTIONS=--experimental-vm-modules, as the
TypeScript with ESM guide shows.
Choose a preset
Section titled “Choose a preset”| Language | Module format | Environment | Preset | Transform |
|---|---|---|---|---|
| TypeScript | from package.json type |
Node.js | ts |
as ts-esm or ts-cjs |
| TypeScript | ESM | Node.js | ts-esm |
@swc/jest |
| TypeScript | CommonJS | Node.js | ts-cjs |
ts-jest, jest-esm-transformer-2 for JS |
| JavaScript | ESM | Node.js | js-esm |
Jest’s default (babel-jest) |
| JavaScript | CommonJS | Node.js | js-cjs |
jest-esm-transformer-2 |
| TypeScript | from package.json type |
jsdom | jsdom-ts |
as jsdom-ts-esm or jsdom-ts-cjs |
| TypeScript | ESM | jsdom | jsdom-ts-esm |
@swc/jest |
| TypeScript | CommonJS | jsdom | jsdom-ts-cjs |
ts-jest, jest-esm-transformer-2 for JS |
| any | any | any | watch |
none: watch plugins only, for the root of a multi-project config |
Every preset except watch has a -watch variant (ts-watch, jsdom-ts-cjs-watch, and so on) that adds five watch
plugins. See watch for the list. The presets index
has every name.
Support
Section titled “Support”| Area | Support | Source |
|---|---|---|
| Jest | jest >=29.5.0 (peer). This repository tests with Jest 30. |
packages/jest/package.json |
| Node.js | No engines field. Node-version test files cover Node.js 14 up to the running major. |
packages/jest/src/configs/node.ts |
| Package format | ESM (esm/) and CommonJS (cjs/) builds of every entry. |
packages/jest/package.json exports |
| Project module format | ESM (-esm presets) and CommonJS (-cjs presets). ts and jsdom-ts choose from package.json type. |
packages/jest/src/presets/ |
| Environments | node (node and js presets) and jsdom (jsdom presets). |
packages/jest/src/configs/node.ts, jsdom.ts |
| TypeScript transforms | @swc/jest for ESM, ts-jest with isolatedModules: true for CommonJS. ts-jest for ESM through fields.knownTransforms.tsJestEsm(). |
packages/jest/src/configs/typescript.ts, src/fields/transform.ts |
| ESM dependencies in CommonJS | jest-esm-transformer-2 with transformIgnorePatterns: [] transforms ESM packages in node_modules. |
packages/jest/src/configs/typescript.ts, javascript.ts |
| Source folder | First of src, source, ts, js that exists in the working directory; src otherwise. |
packages/jest/src/configs/source.ts |
| Monorepo | Run Jest in each package, or use projects with one preset per project and watch at the root. Detection runs in the working directory: see the monorepo guide. |
packages/jest/src/presets/watch/jest-preset.ts |
Not supported
Section titled “Not supported”- JavaScript in jsdom. Every jsdom preset is a TypeScript preset. Compose
configs.jsdomwithconfigs.jsEsmorconfigs.jsCjsyourself (see customize a preset). - Other environments, such as
happy-domor a real browser. The package knows onlynodeandjsdom. - A Babel preset. No preset configures Babel.
js-esmsets notransform, so Jest’s defaultbabel-jeststays in place. ts-jestfor ESM as a preset. The ESM presets use@swc/jest. Build thets-jestvariant fromconfigsandfields.- Per-project detection in a multi-project config. Each preset reads the source folder and
package.jsontypefrom the directory Jest runs in, not from each project’srootDir. - A
@repobuddy/jest/resolverentry. The resolver is reachable only asresolverfrom the main entry (seeresolver). - Load tests in the jsdom presets.
*.load.*files run only throughconfigs.nodeLoad.
Next steps
Section titled “Next steps”- Guides: TypeScript with ESM, TypeScript with CommonJS, DOM tests with jsdom, monorepo, load tests, customize a preset.
- Reference: presets, API, test file names.