Skip to content

Execute scripts during the watch cycle

License

Notifications You must be signed in to change notification settings

unional/jest-watch-exec

Repository files navigation

jest-watch-exec

NPM version NPM downloads

Circle CI Travis CI Codecov Coveralls Status

Greenkeeper Semantic Release

Visual Studio Code Wallaby.js

Execute commands on start or when the all tests pass.

Requires jest@23+.

Usage

To use jest-watch-exec, add it to the watchPlugins section of the Jest configuration:

{
  "jest": {
    "watchPlugins": [
      ["jest-watch-exec", { "on-start": "npm run build" }],
      ["jest-watch-exec", { "on-start-script": "somescript.js" }],
      // Will run the `run(): boolean | Promise<boolean>` method exposed by the module
      ["jest-watch-exec", { "on-start-module": "modulescript.js" }],
      // Will run test even if on-start | on-start-script | on-start-module fails.
      ["jest-watch-exec", { "on-start-ignore-error": true, ... }],
      // execute script when there are passing tests.
      // will not execute if the tests are filtered.
      ["jest-watch-exec", { "on-pass": "npm run build" }],
      // execute 'on-pass' even the tests are filtered.
      ["jest-watch-exec", { "on-pass": "npm run build", "exec-while-filtered": true }]
    ]
  }
}
  • on-start-ignore-error: The script is considered failed if it:
    • returns a falsy value,
    • throws an error,
    • returns a promise resolves to false, or
    • returns a rejected promise.

Contribute

# after fork and clone
npm install

# begin making changes
git checkout -b <branch>
npm run watch

# after making change(s)
git commit -m "<commit message>"
git push

# create PR