Jest Watcher is a core sub-package of the Jest testing framework, providing the interactive command-line interface (CLI) for running tests in 'watch' mode. It enables developers to receive instant feedback on code changes by automatically re-running relevant tests, filtering by filename or test name, and focusing on failed tests. The current stable version is 30.3.0. While Jest v30's major release cycle was notably long (three years), the project aims for more frequent major releases going forward, with minor and patch versions released regularly. Key differentiators include its tight integration with the broader Jest ecosystem for features like snapshot testing and code coverage, offering a dynamic and responsive development workflow compared to static, manual test execution.
npm install jest-watcherVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to create and register a basic custom Jest watch plugin using TypeScript, logging a message when its key is pressed.
Upgrade Node.js to a compatible version (e.g., Node.js 20 LTS or later).
Update TypeScript to version 5.4 or higher in your project's `devDependencies`.
Update your tests to use the canonical matcher names. ESLint with `eslint-plugin-jest` can help automate this via the `no-alias-methods` rule.
Run Jest with the `-u` or `--updateSnapshot` flag to regenerate all snapshots (e.g., `jest -u`). Review changes before committing.
Update any scripts or CI configurations that use `--testPathPattern` to `--testPathPatterns`.
Avoid directly importing or referencing internal Jest paths. Use official APIs and exposed modules only.
Address reported global variable leaks by ensuring proper cleanup in test setups/teardowns. Configure `globalsCleanup: 'off'` in `jest.config.js` to disable, or `'on'` for strict enforcement.
Adjust `transformIgnorePatterns` in `jest.config.js` to transpile the problematic module, or use `moduleNameMapper` to mock non-JS assets. Ensure Babel/TypeScript configuration is correct.
Inspect module resolution paths and ensure all imports are correct. Adding `console.error` in the resolver logic might help pinpoint the exact file causing the issue.
Explicitly set the `testEnvironment` in `jest.config.js` to `'node'` if testing server-side code, or ensure `'jsdom'` is correctly configured for browser environments.
Run Jest with `--detectOpenHandles` to identify the source of the open handles. Ensure all asynchronous operations are properly awaited or cleaned up in your tests or `setupFilesAfterEnv`.