Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ignore files in jest watch mode #3923

Closed
kumar303 opened this issue Jun 27, 2017 · 7 comments
Closed

Ignore files in jest watch mode #3923

kumar303 opened this issue Jun 27, 2017 · 7 comments

Comments

@kumar303
Copy link

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,
};
@rogeliog
Copy link
Contributor

Have you can tried adding the file to the testPathIgnorePatterns http://facebook.github.io/jest/docs/configuration.html#testpathignorepatterns-array-string

@kumar303
Copy link
Author

I did try that but as far as I could tell it didn't affect the watcher

@Fr33maan
Copy link

Fr33maan commented Aug 6, 2017

+1

1 similar comment
@aisensiy
Copy link
Contributor

+1

@tricoder42
Copy link

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.

@aisensiy
Copy link
Contributor

#4331
Add a new argument to add ignore files in watch mode.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants