jest-cli-middleware

1.1.1 • Public • Published

#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
  • 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 different Environments you want to handle.
  • The config object have the following props:
    • jestEvt: string is just the name of the Environment
    • 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.
    • pathTransformers?: {matcher: string, substitue: string}[] is an array of transformer objects: this rewrite the --runByPath argument value, each transformer rule catch a matcher string and replace it by the substitute.
    • 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.

Readme

Keywords

none

Package Sidebar

Install

npm i jest-cli-middleware

Weekly Downloads

1

Version

1.1.1

License

MIT

Unpacked Size

6.86 kB

Total Files

6

Last publish

Collaborators

  • wsu