@lottiefiles/jest-config
v1.0.0
Published
Shared Jest config for LottieFiles projects
Downloads
53
Readme
@lottiefiles/jest-config
Shared configuration for jest.
Table of contents
Installation
- Install the @lottiefiles/jest-config to the project with pnpm.
pnpm add -D @lottiefiles/jest-config
- 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:
- Install
jest
andesbuild
as a workspaces root dev dependency.
pnpm add -DW jest @types/jest esbuild
- Create a
jest.config.cjs
in the workspace root.
module.exports = {
// Setup projects
projects: ['<rootDir>/packages/*'],
};
- Install
@lottiefiles/jest-config
as a project dev dependency in each of the projects you are setting upjest
for.
pnpm add -D @lottiefiles/jest-config
- 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
- Pass in the transform format and transform target arguments to the
createConfig
function to configurejest
for processing and treating the files as ESM.
...createConfig({
transformFormat: 'esm',
transformTarget: 'es2020'
}),
- 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
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.