@jjangga0214/jest-config
v5.2.0
Published
A sharable config package and development environment for jest
Downloads
58
Maintainers
Readme
@jjangga0214/jest-config
A sharable config package for jest.
Installation
npm install --save-dev @jjangga0214/jest-config
# or
yarn add --dev @jjangga0214/jest-config
# or
pnpm add --save-dev @jjangga0214/jest-config
And you should also install peerDependencies
manually.
Check out package.json or npm info
.
# This does not install them all. This just show them on terminal.
npm info "@jjangga0214/jest-config@latest" peerDependencies
Or install them all by install-peerdeps
.
# For npm
npx install-peerdeps --dev @jjangga0214/jest-config
# For yarn
npx install-peerdeps --yarn --dev @jjangga0214/jest-config
# For pnpm
npx install-peerdeps --pnpm --dev @jjangga0214/jest-config
Notes
- For
transform
,@swc/jest
is preconfigured. You can override it, byts-jest
,esbuild
,babel
, ortsc
for example. extensionsToTreatAsEsm
is preconfigured. If your project is not ESM typescript, override it.moduleNameMapper
is preconfigured, even when you're not usingproduceConfig()
. If your project is not ESM typescript, override it.
Usage
For a project not using an alias
If your project is pure javascript or does not need Typescript paths mapping and jest's moduleNameMapper
, then you can just import a config(json) directly.
import config from '@jjangga0214/jest-config'
export default config
Otherwise, consider produceConfig
(function).
import { produceConfig } from '@jjangga0214/jest-config'
For a single-project repo
jest.config.js:
import { createRequire } from 'node:module'
import { produceConfig } from '@jjangga0214/jest-config'
const require = createRequire(import.meta.url)
// `./tsconfig.json` should not have comment in order to import.
const tsConfig = require('./tsconfig.json')
export default {
...produceConfig({ tsConfig }),
// And possibly override other fields.
// transform: {
// '.(ts|tsx)': 'ts-jest',
// },
}
For a monorepo
jest.config.js at the root:
For monorepo, you probably want to configure projects
.
import { createRequire } from 'node:module'
import { produceConfig } from '@jjangga0214/jest-config'
const require = createRequire(import.meta.url)
// `./tsconfig.json` should not include comment to be imported.
const tsConfig = require('./tsconfig.json')
export const config = {
...produceConfig({ tsConfig }),
// And possibly override other fields.
// transform: {
// '.(ts|tsx)': 'ts-jest',
// },
};
export default {
...config,
projects: [
'<rootDir>',
'<rootDir>/packages/*',
'<rootDir>/backends/*',
'<rootDir>/frontends/*',
'<rootDir>/libs/*',
'<rootDir>/workflows/*',
],
}
jest.config.js in each sub-project:
import { config } from '../../jest.config.js'
export default {
...config,
// And possibly override other fields.
}
However, for monorepo with certain situations, it is OK that you don't depend on projects
. You may be able to treat your monorepo like a single project repo. JEST may still work well.
There is an issue of projects
: https://github.com/facebook/jest/issues/12230