{"id":15130,"library":"jest-watcher","title":"Jest Watcher","description":"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.","status":"active","version":"30.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/jestjs/jest","tags":["javascript","typescript"],"install":[{"cmd":"npm install jest-watcher","lang":"bash","label":"npm"},{"cmd":"yarn add jest-watcher","lang":"bash","label":"yarn"},{"cmd":"pnpm add jest-watcher","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core Jest functionality; jest-watcher is an internal package used by the main Jest runner.","package":"jest","optional":false},{"reason":"For defining and managing Jest's configuration, including watch plugins.","package":"jest-config","optional":false}],"imports":[{"note":"Used for creating custom interactive watch mode plugins. Extend this class to implement custom logic triggered by key presses in watch mode.","symbol":"BaseWatchPlugin","correct":"import { BaseWatchPlugin } from 'jest-watcher';"},{"note":"The main Jest configuration type. Often imported for type-safe `jest.config.ts` files, particularly when using `defineConfig`.","symbol":"Config","correct":"import type { Config } from 'jest';"},{"note":"Introduced in Jest 30.3.0, this helper provides type-safe configuration for `jest.config.ts` files. It's exported from `jest-config`, not the top-level `jest` package.","wrong":"import { defineConfig } from 'jest';","symbol":"defineConfig","correct":"import { defineConfig } from 'jest-config';"}],"quickstart":{"code":"import type { Config } from 'jest';\nimport { BaseWatchPlugin } from 'jest-watcher';\nimport type {\n  JestHookSubscriber,\n  WatchPlugin,\n  UsageInfo,\n  GlobalConfig,\n  UpdateConfigCallback,\n} from 'jest-watcher';\n\n// A minimal custom watch plugin that just logs a message\nclass MyCustomWatchPlugin extends BaseWatchPlugin implements WatchPlugin {\n  is);","lang":"typescript","description":"Demonstrates how to create and register a basic custom Jest watch plugin using TypeScript, logging a message when its key is pressed."},"warnings":[{"fix":"Upgrade Node.js to a compatible version (e.g., Node.js 20 LTS or later).","message":"Jest 30.x has dropped support for older Node.js versions. Ensure your environment is running Node.js 18.14.0, 20.x, 22.x, or 24.x and above.","severity":"breaking","affected_versions":">=30.0.0"},{"fix":"Update TypeScript to version 5.4 or higher in your project's `devDependencies`.","message":"The minimum compatible TypeScript version is now 5.4. Projects using Jest's type definitions must update their TypeScript installation.","severity":"breaking","affected_versions":">=30.0.0"},{"fix":"Update your tests to use the canonical matcher names. ESLint with `eslint-plugin-jest` can help automate this via the `no-alias-methods` rule.","message":"Several deprecated `expect` matcher aliases (e.g., `toBeCalled` for `toHaveBeenCalled`) have been fully removed. These were deprecated since Jest 26.","severity":"breaking","affected_versions":">=30.0.0"},{"fix":"Run Jest with the `-u` or `--updateSnapshot` flag to regenerate all snapshots (e.g., `jest -u`). Review changes before committing.","message":"Snapshot header formats have changed in Jest 30, requiring all existing snapshots to be regenerated.","severity":"breaking","affected_versions":">=30.0.0"},{"fix":"Update any scripts or CI configurations that use `--testPathPattern` to `--testPathPatterns`.","message":"The `--testPathPattern` CLI option has been renamed to `--testPathPatterns` for consistency.","severity":"breaking","affected_versions":">=30.0.0"},{"fix":"Avoid directly importing or referencing internal Jest paths. Use official APIs and exposed modules only.","message":"Jest 30 bundles its modules into single files, which might break tools that relied on reaching into Jest's internal file structure.","severity":"gotcha","affected_versions":">=30.0.0"},{"fix":"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.","message":"Jest 30 introduces `globalsCleanup` to detect and report global variables not cleaned up between test files, which can cause memory leaks. Default is 'soft'.","severity":"gotcha","affected_versions":">=30.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"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.","cause":"Jest's transformer (e.g., Babel, ts-jest) is not processing a file, often in `node_modules`, or a non-JavaScript file is being imported.","error":"Jest encountered an unexpected token"},{"fix":"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.","cause":"Unresolvable `import`/`export` paths in modules, potentially due to bad merges or misconfigured module resolution.","error":"Determining Test Suites to Run (Watcher hangs or fails to find tests)"},{"fix":"Explicitly set the `testEnvironment` in `jest.config.js` to `'node'` if testing server-side code, or ensure `'jsdom'` is correctly configured for browser environments.","cause":"Jest's test environment is misconfigured, leading to unexpected browser-like security errors in Node.js tests.","error":"Error: Cross origin http://localhost forbidden"},{"fix":"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`.","cause":"Open handles (timers, network connections, etc.) are left active after tests complete, preventing Jest from exiting cleanly.","error":"Jest did not exit one second after the test run completed. This usually means that there are asynchronous operations that weren't stopped in your tests."}],"ecosystem":"npm"}