Skip to content

Stale "Tests with previous failures not run" when changing source file  #2821

@IgnusG

Description

@IgnusG

I noticed that changing the source file sometimes leads to ava reporting a "1 previous failure in test files that were not rerun" even though the tests testing that file already passed. This message is a bit confusing since the test actually was rerun and passed.

I saw that the relevant line that "prunes" the failures is

this.pruneFailures(plan.files);

But that line seems to run after the failures have already been passed to the api at

previousFailures: this.sumPreviousFailures(this.runVector),
and it's therefore not up to date anymore (since we overwrite the array in prune - not modify it).

It's either possible to modify the array instead at

this.filesWithFailures = this.filesWithFailures.filter(state => !toPrune.has(state.file));
or to pass it as a function that gets evaluated instead:

watcher.js

runtimeOptions: {
  clearLogOnNextRun,
  previousFailures: () => this.sumPreviousFailures(this.runVector), // This is now a function
  runOnlyExclusive,
  runVector: this.runVector,
  updateSnapshots: updateSnapshots === true
}

and reporters/default.js

if (this.previousFailures() > 0) { // Which we call in the reporter to get the up to date data
  this.lineWriter.writeLine(colors.error(`${this.previousFailures()} previous ${plur('failure', this.previousFailures())} in test files that were not rerun`));
}

The code is taken from the latest commit on ava@next

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions