Ignore files in jest watch mode
kumar303 opened this issue · 7 comments
Do you want to request a feature or report a bug?
feature
What is the current behavior?
When I run jest --watch
it watches all files and re-runs the tests when one of them changes.
What is the expected behavior?
This works as expected except when we use a webpack plugin that generates a webpack-assets.json
file periodically. After editing a code file, the auto-generated assets file causes the tests to run twice which is slower than it needs to be.
It would be really helpful if I could configure the jest watcher to ignore changes to the webpack-assets.json
file.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
$ jest --version
v20.0.4
$ yarn --version
0.24.6
$ node --version
v6.10.3
$ watchman --version
4.7.0
Mac OS X 10.12.5
I know that #2516 was fixed but that solved it for code coverage only. It would be great to have a generic solution to this where we could just ignore files based on a list of patterns.
Jest config
module.exports = {
collectCoverageFrom: ['src/**/*.{js,jsx}'],
coveragePathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/src/core/server/webpack-isomorphic-tools-config.js',
'<rootDir>/src/locale/',
],
moduleDirectories: [
'src',
'node_modules',
],
moduleFileExtensions: [
'js',
'json',
'jsx',
],
moduleNameMapper: {
// Prevent un-transpiled react-photoswipe code being required.
'^photoswipe$': '<rootDir>/node_modules/photoswipe',
// Use the client-side logger by default for tests.
'^core/logger$': '<rootDir>/src/core/client/logger',
// Alias tests for tests to be able to import helpers.
'^tests/(.*)$': '<rootDir>/tests/$1',
// Replaces the following formats with an empty module.
'^.+\\.(scss|css|svg|woff|woff2|mp4|webm)$': '<rootDir>/tests/emptyModule',
},
setupTestFrameworkScriptFile: '<rootDir>/tests/setup.js',
testPathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/(assets|bin|config|coverage|dist|docs|flow|locale|src)/',
],
testMatch: [
'**/[Tt]est(*).js?(x)',
'**/__tests__/**/*.js?(x)',
],
transform: {
'^.+\\.js$': 'babel-jest',
// This transforms images to be a module that exports the filename.
// Tests can assert on the filenname.
'^.+\\.(jpg|jpeg|gif|png)$': '<rootDir>/tests/fileTransformer',
},
transformIgnorePatterns: [
'<rootDir>/node_modules/',
],
verbose: false,
};
Have you can tried adding the file to the testPathIgnorePatterns
http://facebook.github.io/jest/docs/configuration.html#testpathignorepatterns-array-string
I did try that but as far as I could tell it didn't affect the watcher
+1
+1
Looking at source of jest-cli/watch.js
, filtering (in SearchSource
) is applied after watcher decides if any file was changed or not.
Trying to fix it in PR. Please correct me if I'm wrong.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.