Do you want to request a feature or report a bug?
What is the current behavior?
jest --watch
my tests will create new files on project directory. jest rerun when watch new files. run tests loop ......
I try set testPathIgnorePatterns
and testPathDirs
exclude the new files directory, but same way.
If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install
and yarn test
.
What is the expected behavior?
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Looks like the coverageDirectory
option should help you there.
I'm also seeing this https://github.com/danger/danger-js/pull/82, so this is how I debugged it - if you edit your node_modules
you can make this function console.log what file is triggering the restart
And as I'm interested in specific answers too, my problem was that something was making my fixtures change ( I assume it's the typescript compiler )
I fixed it by doing this in the package.json
...
"coveragePathIgnorePatterns": [
"/node_modules/",
"(.test)\\.(ts|tsx|js)$",
"/distribution/.*\\.(ts|js)$"
]
...
This should fix it: https://github.com/facebook/jest/pull/2362
const onFileChange = (_, filePath: string) => {
filePath = path.join(root, filePath);
const coverageDirectory =
config.coverageDirectory ||
path.resolve(config.rootDir, 'coverage');
const isValidPath =
config.testPathDirs.some(dir => filePath.startsWith(dir)) &&
!filePath.includes(coverageDirectory);
Look at this condition !filePath.includes(coverageDirectory)
, the change filepath must includes coverageDirectory.
But coverageDirectory
option should output jest coverage files.
I see you use os.tmpdir() to avoid this problem.
Jest 19 is out now.
I'm running into this, I'm unable to use jest watch because my test files clean up the test output dirs using afterAll
and watch doesn't like that at all.
D:\git\modular-css>npm test cli -- --watch
> [email protected] test D:\git\modular-css
> jest "cli" "--watch"
PASS packages\cli\test\cli.test.js
/cli.js
√ should show help with no args (304ms)
√ should default to outputting to stdout (348ms)
√ should support outputting to a file (342ms)
√ should support outputting compositions to a file (336ms)
√ should return the correct error code on invalid CSS (338ms)
Snapshot Summary
› 1 obsolete snapshot found, press `u` to remove them.
Test Suites: 1 passed, 1 total
Tests: 5 passed, 5 total
Snapshots: 4 passed, 4 total
Time: 2.835s, estimated 3s
Ran all test suites matching /cli/.
Watch Usage
› Press a to run all tests.
› Press o to only run tests related to changed files.
› Press u to update failing snapshots.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press q to quit watch mode.
› Press Enter to trigger a test run.
events.js:163
throw er; // Unhandled 'error' event
^
Error: EPERM: operation not permitted, lstat 'D:\git\modular-css\packages\cli\test\output\classes.json'
Ideally I can tell jest to ignore all output
dirs for watching files, but coveragePathIgnorePatterns
description doesn't make it sound like the right thing.
Is coveragePathIgnorePatterns
really the right approach?
Doesn't seem like it, I get the same error with the following added to my package.json
.
"jest": {
"coveragePathIgnorePatterns": [
"node_modules",
"output"
]
}
Same here using Jest 19.0.2, stuck in an infinite watch loop without --coverage
, my tests are in src/
and creates files in tests-data/
. Using testPathIgnorePatterns: [/tests-data/, /node_modules/]
doesn't seems to do the trick, neither do coveragePathIgnorePatterns
.
watchPathIgnorePatterns is the current way.
I actually have that set up already, but it still doesn't work, I get crashes any time I try to use jest --watch
.
I am using a monorepo. I have a fixture
folder where I create temporary files used by some tests. I can't get watchPathIgnorePatterns
working. Does not matter if I keep on the top level of the jest.config.js
, or inside specific project entry in projects
. If I run yarn jest --watch SomeTestFile.test
the runner keeps restarting. The only way I can get it to work is via changing the name of the fixture folder to .fixtures
.
I also tried to use an absolute path, with 1-1 match of the file causing the problem, also does not help...
My intended setup is this:
module.exports = {
projects: [
'workspaces/hush-hush',
'workspaces/queuing-service',
'workspaces/telepath',
'workspaces/idbox-react-ui',
'workspaces/utils',
{
rootDir: 'workspaces/idservice',
testEnvironment: 'node'
},
{
rootDir: 'workspaces/nameservice',
testEnvironment: 'node'
},
{
testMatch: ['<rootDir>/dummy']
}
],
collectCoverage: true,
collectCoverageFrom: [
'source/**/*.js',
'src/**/*.js',
'pages/*.js',
'components/**',
'!pages/_app.js',
'!**/jest.config.js',
'!**/_document.js',
'!**/*.test.js',
'!**/__mocks__/**.js',
'!**/node_modules/**',
'!**/.next/**'
],
coverageReporters: [
'text-summary',
'lcov'
],
watchPathIgnorePatterns: [
'<rootDir>/fixtures/idservice/'
]
}
My tests dynamically create a fixture file in <rootDir>/fixtures/idservice/
- in this case in the root of the monorepo, not in the root of the workspace. Since this does not seem to work, I thought maybe I need to use the root of the workspace itself, so I put watchPathIgnorePatterns
inside projects
entry like this:
module.exports = {
projects: [
// ....
{
rootDir: 'workspaces/idservice',
testEnvironment: 'node',
watchPathIgnorePatterns: [
'<rootDir>/fixtures/idservice/'
]
},
and then have the fixtures
folder in the workspace root, but this does not seem to work either. I tried different values, absolute paths, nothing seems to work. What am I doing wrong?
The link to repo is here: https://github.com/identity-box/identity-box
I am using jest version 25.1.0
.
Most helpful comment
watchPathIgnorePatterns is the current way.