1.1.1 • Published 3 years ago
jest-cli-middleware v1.1.1
#Jest CLI Middleware Jest cli middleware is a cli you can use over standard Jest-cli or React-scripts to gain some flexibility, especially with IDE integrations. J.C.M allow you to:
JCM can handle testing
Environmentsdiscriminated by the path of the files and change the cli and it's args according to some rules with the same JEST IDE Config, (example):- Run back-end tests (which are in a "server" folder) with jest-cli and --runByPath
Transformations. - Run front-end tests (which are in the "CRA" folder) with react-scripts
- JCM takes care of the Working directory automatically for your different
Environments
- Run back-end tests (which are in a "server" folder) with jest-cli and --runByPath
JCM handles
Transformationsto -runByPath argument passed by the IDE CLI call:- This allows you to write your tests with typescript, click the IDE button to run a specific test, and have jest called with the JS file.
- Transformations rules are completely configurable, and they can be different from one to another
Environment
#Installation & Configuration
Installation
With yarn
yarn add jest-cli-middlewareWith npm
npm install jest-cli-middlewareConfiguration
Create the config file
JCM get its configuration from a .jcmrc file with JSON syntax. This config file has to be in the package.json folder.
Configuration file Syntax explained from an example
[
{
"jestEvt": "clientApp",
"pathMatch": "./client",
"pathTransformers": [],
"cliScript": "./node_modules/react-scripts/scripts/test.js"
},
{
"jestEvt": "server",
"pathMatch": "./server",
"pathTransformers": [{
"matcher": "server/src",
"substitute": "server/dist"
}, {
"matcher": ".ts",
"substitute": ".js"
}, {
"matcher": ".jsx",
"substitute": ".jsx"
}],
"cliScript": "./node_modules/jest-cli/bin/jest.js"
}
]- The
configsobject is an array of all the differentEnvironmentsyou want to handle. - The
configobject have the following props:jestEvt: stringis just the name of theEnvironmentpathMatch: stringis the absolute or relative path of a folder containing all the test you want to run with this config. (ex: path of your CRA)- relative path are based from node
working directory, which depends on your shell's actual directory at the moment you run JCM; or your IDE configuration if you run JCM from it.
- relative path are based from node
pathTransformers?: {matcher: string, substitue: string}[]is an array oftransformerobjects: this rewrite the--runByPathargument value, each transformer rule catch amatcherstring and replace it by thesubstitute.cliScript: stringis the absolute or relative path of the CLI you want to finally run.- relative path are based on the path given to
pathMatchproperty.
- relative path are based on the path given to