question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

watch mode does not honor shouldRunTestSuite when there are changes

See original GitHub issue

🐛 Bug Report

jest@23.6.0 ts-jest@23.10.1

When there are changes, even though jest-watch-suspend returns false in shouldRunTestSuite() callback, tests are still executed.

To Reproduce

Use this branch: https://github.com/unional/issues/tree/jest-watch-git

After you clone and npm install, run npm run watch. You will see no test is executed (expected result):

Determining test suites to run...
Test is suspended on start.
No tests found related to files changed since last commit.
Press `a` to run all tests, or run Jest with `--watchAll`.

Watch Usage
 › Press a to run all tests.
 › Press f to run only failed tests.
 › 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 s to suspend watch mode.
 › Press Enter to trigger a test run.

Now, do the following:

  1. edit src/index.ts to add a function, e.g.:
export function foo(x) { return x }

export function boo(y) { return y }
  1. create a copy of src/r2/index.spec.ts as src/r2/index2.spec.ts

Now if you run npm run watch, you will see the test in src/r2/index.spec.ts is executed while Test is suspended on start. is printed:

Determining test suites to run...
Test is suspended on start.
 PASS  src/r2/index.spec.ts
  √ test demo (7ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        3.706s
Ran all test suites related to changed files.

Watch Usage
 › Press a to run all tests.
 › Press f to run only failed tests.
 › 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 s to suspend watch mode.
 › Press Enter to trigger a test run.

The code that prints the “Test is suspended on start.” is here:

https://github.com/unional/jest-watch-suspend/blob/0670a39eb93abc160060475208e26f2b3493aa3d/src/WatchSuspendPlugin.ts#L19-L20

You can see that it is returning false. But in the example above, the test is still being executed.

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: Windows 10
    CPU: x64 Intel(R) Xeon(R) CPU E5-4650 v4 @ 2.20GHz
  Binaries:
    Yarn: 1.9.4 - C:\Program Files\nodejs\yarn.CMD
    npm: 5.6.0 - C:\Program Files\nodejs\npm.CMD

reference: https://github.com/unional/jest-watch-suspend/issues/4

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rogeliogcommented, Sep 25, 2018

Thanks for reporting, I’ll take a look tomorrow morning

0reactions
github-actions[bot]commented, May 12, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No coverage when running in watch mode #7331 - GitHub
The tests for those files won't be run because they haven't been changed since the last commit. Your coverage report will therefore be...
Read more >
Watching Files for Changes - Node Tap
In this mode, tap will watch your project for changes to test files and the program files that they cover, and open a...
Read more >
Run New and Failing Tests on File Change with Pytest
See how to pair Pytest and pytest-watch to run failing unit tests and new tests automatically on file changes without running the whole...
Read more >
Jest CLI Options
This mode will send all other test output and user messages to stderr. --lastCommit ​. Run all tests affected by file changes in...
Read more >
A Practical Guide To Testing React Applications With Jest
Jest has a nice feature called watch mode, which watches for file changes and runs tests accordingly. To run Jest in watch mode,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found