1.1.1 • Published 2 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
Environments
discriminated 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
Transformations
to -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-middleware
With npm
npm install jest-cli-middleware
Configuration
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
configs
object is an array of all the differentEnvironments
you want to handle. - The
config
object have the following props:jestEvt: string
is just the name of theEnvironment
pathMatch: string
is 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 oftransformer
objects: this rewrite the--runByPath
argument value, each transformer rule catch amatcher
string and replace it by thesubstitute
.cliScript: string
is the absolute or relative path of the CLI you want to finally run.- relative path are based on the path given to
pathMatch
property.
- relative path are based on the path given to