@lottiefiles/jest-config
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@lottiefiles/jest-config

Shared configuration for jest.

Table of contents

Installation

  1. Install the @lottiefiles/jest-config to the project with pnpm.
pnpm add -D @lottiefiles/jest-config
  1. Create a jest.config.cjs file in the project with the contents:
const { createConfig } = require('@lottiefiles/jest-config');

const packageJson = require('./package.json');

module.exports = {
  ...createConfig(),

  name: packageJson.name,
  displayName: packageJson.name,
};

Install Dependencies

The following must be installed as a dev dependency in your project.

Peer Dependencies

Package Name Version
esbuild *
jest *

Configuration

Monorepos

The recommended setup for a monorepo project is:

  1. Install jest and esbuild as a workspaces root dev dependency.
pnpm add -DW jest @types/jest esbuild
  1. Create a jest.config.cjs in the workspace root.
module.exports = {
  // Setup projects
  projects: ['<rootDir>/packages/*'],
};
  1. Install @lottiefiles/jest-config as a project dev dependency in each of the projects you are setting up jest for.
pnpm add -D @lottiefiles/jest-config
  1. Create a jest.config.cjs file in each of the projects.
const { createConfig } = require('@lottiefiles/jest-config');

const packageJson = require('./package.json');

module.exports = {
  ...createConfig(),

  name: packageJson.name,
  displayName: packageJson.name,
};

You can then customize this file to fit the needs of each project individually.

ESM projects

  1. Pass in the transform format and transform target arguments to the createConfig function to configure jest for processing and treating the files as ESM.
...createConfig({
    transformFormat: 'esm',
    transformTarget: 'es2020'
  }),
  1. Make sure you invoke jest with running node with ES module support. You can do this by setting the NODE_OPTIONS environment variable to --experimental-vm-modules.

For e.g., the "test" script command can be:

{
  // ...
  "scripts": {
    "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest"
  }
}

Tips and Tricks

Mocking objects and functions, with dynamic return values

Use jest-mock-extended

Recording HTTP calls

Use PollyJS

Running heavy and long running tasks under forked processes in parallel

Use jest-worker

Creating spies for classes

Use jest-auto-spies

Starting a server before running tests

Use jest-dev-server

Running tests all in a browser environment

Use Playwright Test instead of Jest. See playwright.dev

Changelog

See CHANGELOG.md for the latest changes.

Readme

Keywords

Package Sidebar

Install

npm i @lottiefiles/jest-config

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

15.2 kB

Total Files

11

Last publish

Collaborators

  • aidosmf
  • jawish
  • karamalie
  • sam-osb