@cprussin/jest-config
v1.4.1
Published
A jest config that sets up runners for unit tests, integration tests, eslint, and prettier
Downloads
1,386
Maintainers
Readme
@cprussin/jest-config v1.4.1 • Docs
@cprussin/jest-config v1.4.1
This package contains a set of jest configs that set up runners for running unit tests, integration tests, eslint, and prettier.
Installing
Use the package manager of your choice to install:
- npm:
npm install --save-dev @cprussin/jest-config
- pnpm:
pnpm add -D @cprussin/jest-config
- yarn:
yarn add -D @cprussin/jest-config
Usage
- Set up your
jest.config.js
, for example:
export { base as default } from "@cprussin/jest-config";
Run
jest
to run format checks, lint checks, unit tests, and integration tests, or use--selectProjects
to run a subset of checks.Add scripts to your
package.json
if you'd like. For instance:
{
"scripts": {
"test:format": "jest --selectProjects format",
"test:integration": "jest --selectProjects integration",
"test:lint": "jest --selectProjects lint",
"test:unit": "jest --coverage --selectProjects unit"
}
}
Projects
Configurations exported with this package will set up the following jest projects:
format
: Check code style with prettier usingjest-runner-prettier
.integration
: Tests that run out of theintegration-tests
directory. Functionally not much different thanunit
, but you can have a separate configuration, different pipeline dependencies, etc.lint
: Run eslint checks usingjest-runner-eslint
.unit
: Need I say more?
Running jest
will run all four projects. You can run a subset of the
projects using jest's --selectProjects
argument, as usual.
Options
If you need to, you can extend or wrap the configs generated here by calling the config you want and passing an object as an argument that describes your modifications. The object can have any combination of the following keys:
format
: Specify extensions or wrappers for theformat
project.global
: Specify extensions or wrappers for the top-level jest config.integration
: Specify extensions or wrappers for theintegration
project.lint
: Specify extensions or wrappers for thelint
project.unit
: Specify extensions or wrappers for theunit
project.
The value for each of those keys should be an object containing either or
both of config
, an object whose values will be spread into the relevant
project or global config, and wrapper
, a function that should take the
config and return a promise containing the final config. For example:
import { base } from "@cprussin/jest-config";
export default base({
global: {
wrapper: async (oldGlobalConfig) => doSomethingAsyncWith(oldGlobalConfig),
config: {
passWithNoTests: true,
},
},
unit: {
wrapper: async (oldUnitConfig) => doSomethingAsyncWith(oldUnitConfig),
},
format: {
config: {
testPathIgnorePatterns: ["foo/*"],
},
},
});
Note that the extensions will be spread before calling the wrapper (so the
values in the config
option will be present in the argument to the
wrapper
).