Narrating Prophetic Monks

    @jjangga0214/jest-config

    4.1.2 • Public • Published

    @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. Checkout 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

    Note

    Usage

    For a project not using alias

    If your project is pure javascript or does not need Typescript paths mappting and jest's moduleNameMapper, then you can just import a config(json) directly,

    import { config } from '@jjangga0214/jest-config'

    instead of produceConfig (function).

    import { produceConfig } from '@jjangga0214/jest-config'

    For a single-project repo

    jest.config.js:

    import { produceConfig } from '@jjangga0214/jest-config'
    import { createRequire } from 'module'
    
    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 }),
      // You can override other fields as well.
      // transform: {
      //   '.(ts|tsx)': 'ts-jest',
      // },
    };

    For a monorepo

    jest.config.js at the root:

    For monorepo, you probably want to configure projects.

    const { produceConfig } = require("@jjangga0214/jest-config");
    import { createRequire } from 'module'
    
    const require = createRequire(import.meta.url)
    // `./tsconfig.json` should not have comment in order to import.
    const tsConfig = require('./tsconfig.json')
    
    const baseConfig = {
      ...produceConfig({ tsConfig }),
      // You can override other fields as well.
      // transform: {
      //   '.(ts|tsx)': 'ts-jest',
      // },
    };
    
    export default {
      baseConfig,
      ...baseConfig,
      projects: [
        '<rootDir>',
        '<rootDir>/packages/*',
        '<rootDir>/backends/*',
        '<rootDir>/frontends/*',
        '<rootDir>/libs/*',
        '<rootDir>/workflows/*',
      ],
    };

    jest.config.js in each sub projects:

    import { baseConfig } from '../../jest.config.js'
    
    export default {
     ...baseConfig,
      // You can override other fields as well. 
    }

    However, for monorepo with certain situation, 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

    Install

    npm i @jjangga0214/jest-config

    DownloadsWeekly Downloads

    21

    Version

    4.1.2

    License

    MIT

    Unpacked Size

    13.9 kB

    Total Files

    4

    Last publish

    Collaborators

    • jjangga0214