5.2.0 • Published 4 months ago

@jjangga0214/jest-config v5.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@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

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

5.2.0

4 months ago

5.1.1

4 months ago

5.1.0

4 months ago

5.0.0

4 months ago

4.6.1

4 months ago

4.6.0

4 months ago

4.5.1

4 months ago

4.5.0

10 months ago

4.4.0

10 months ago

4.3.0

10 months ago

4.2.1

10 months ago

4.2.0

10 months ago

4.1.0

2 years ago

4.1.2

2 years ago

4.1.1

2 years ago

3.0.2

2 years ago

3.1.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.2

2 years ago

2.3.0

2 years ago

2.2.0

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago