Execute commands on start or when the all tests pass.
Requires jest@23+
.
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.
# 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