Ava: Issues with .only - tests double run and tests do not recover

Created on 8 Aug 2019  Â·  8Comments  Â·  Source: avajs/ava

Description

I've been experiencing 2 issues with .only since 2.0.0 (or maybe earlier, I can't remember for sure). I believe the issues persisted in 2.1.0 and 2.2.0.

My typical workflow is:

  1. Run tests in a specific file, e.g. ava test/test-tiny-atom.js -vw
  2. Pick one test and add .only
  3. Once I'm done with that test, remove .only

Expected behaviour:

  1. All tests run in the file
  2. Only the one tests with .only runs
  3. All tests run in the file OR I can hit r+enter to rerun all.

Actual behaviour:

  1. All tests run in the file
  2. Only the one tests with .only runs the first time, and then that test starts running twice on each rerun.
  3. No tests are run after removing .only, r+enter doesn't do anything.

Test Source

Reproducable tests in the following repo: https://github.com/KidkArolis/tiny-atom. But I've been experiencing this issue with all of my repos using ava.

Error Message & Stack Trace

  • See how does not mutate the state object test runs twice
  • See how r+enter doesn't do anything

image

Config

Copy the relevant section from package.json:

  "ava": {
    "files": [
      "test/test-*.js"
    ],
    "require": [
      "@babel/register",
      "./test/helpers/setup.js"
    ]
  },

Command-Line Arguments

ava test/test-tiny-atom.js -vw

Environment

os darwin 18.7.0
node 10.15.3
ava 2.1.0
npm 6.10.0
bug watch-mode

All 8 comments

@KidkArolis can you reproduce this with master?

I'm still seeing one bug though:

I think somehow the a.test.js file gets flagged as having exclusive tests, which isn't true. And then the watcher gets stuck until you re-run all tests.

Tried master (with npm i avajs/ava).. but ava -w is just hanging with the spinner stuck â ™, not sure why.

I had some trouble myself. There's some changes in Node.js 12.7.0 which may be impacting us. Maybe give it a go when once I get the next release out.

I think somehow the a.test.js file gets flagged as having exclusive tests, which isn't true. And then the watcher gets stuck until you re-run all tests.

I think the problem is in this line https://github.com/avajs/ava/blob/master/lib/watcher.js#L232:

this.updateExclusivity(evt.testFile, fileStats.declaredTests > fileStats.selectedTests);

On step 4, when you save a.test.js, it has no tests selected to run, so declaredTests=2 and selectedTests=0 and it gets marked has exclusive. I think it should have an additional check for fileStats.selectedTests > 0 to make sure it did have a subset of tests to run (i.e. .only)

I think it should have an additional check for fileStats.selectedTests > 0 to make sure it did have a subset of tests to run (i.e. .only)

That sounds like it'll do the trick.

@vmlf01 that solved it for me, see https://github.com/avajs/ava/pull/2216.

@KidkArolis 2.3.0 is out with watcher fixes. Please file a new issue if you're still having trouble after upgrading.

Oh! This is great! Thanks for quick action.

Seems to be working well for the most part - adding .only runs the one test, removing .only runs all tests - just as you'd expect.

However, I still noticed the issue where ava was running the same .only test twice:
image

But can't reproduce anymore. I'll open a new issue if I can isolate how that happens.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

avaly picture avaly  Â·  4Comments

fleg picture fleg  Â·  3Comments

ehmicky picture ehmicky  Â·  3Comments

carpasse picture carpasse  Â·  3Comments

sindresorhus picture sindresorhus  Â·  5Comments