Jest: Changing a file's access time re-runs tests in watch mode

Created on 9 Oct 2018  路  3Comments  路  Source: facebook/jest

馃悰 Bug Report

When running jest --watch, changing a file's access time triggers a test re-run.

To Reproduce

Steps to reproduce the behavior:

  • Start jest --watch
  • Change the access time for a file and nothing else. Example: touch -a src/components/SomeComponent.js

Expected behavior

I don't expect Jest to re-run tests when only the access time changes. I would expect it to re-run tests when the modified time changes or new files are added, etc.

Link to repl or repo (highly encouraged)

Please provide either a repl.it demo or a minimal repository on GitHub.

Issues without a reproduction link are likely to stall.

Run npx envinfo --preset jest

Paste the results here:


  System:
    OS: macOS Sierra 10.12.6
    CPU: x64 Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz
  Binaries:
    Node: 8.11.4 - ~/.nvm/versions/node/v8.11.4/bin/node
    Yarn: 1.9.4 - /usr/local/bin/yarn
    npm: 5.6.0 - ~/.nvm/versions/node/v8.11.4/bin/npm
  npmPackages:
    jest: ^23.1.0 => 23.1.0

The chokidar file watcher always changes access time shortly after a file is modified. I'm not sure why and I'm not sure how to turn it off. Since I use chokidar in a separate shell to run flow as I edit code, this causes my tests to always run twice.

Bug

Most helpful comment

@SimenB we should be able to know when only the access time changed and do nothing in that case.

All 3 comments

Interesting! @rubennorte thoughts on this?

I don't know if it's part of the metadata we get here: https://github.com/facebook/jest/blob/19ceeb5b31e5ad483d1425bb8cd9a38aa583740b/packages/jest-cli/src/watch.js#L196-L199. It contains `fs.Stats, but I'm not sure if it's possible for us to knwo that's the only thing that changed.

A possible workaround for you is to use https://www.npmjs.com/package/jest-runner-flowtype, not sure if it' feasible or not 馃檪

I've seen apps deal with this kind of thing by comparing access/modified time stamps when getting the change event.

A possible workaround for you is to use https://www.npmjs.com/package/jest-runner-flowtype

Thanks! I didn't know about it. I'll try it.

@SimenB we should be able to know when only the access time changed and do nothing in that case.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jardakotesovec picture jardakotesovec  路  3Comments

hramos picture hramos  路  3Comments

gustavjf picture gustavjf  路  3Comments

kgowru picture kgowru  路  3Comments

StephanBijzitter picture StephanBijzitter  路  3Comments