Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'previous failures' in watch mode always incrementing #3297

Merged
merged 2 commits into from Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/watcher.js
Expand Up @@ -106,7 +106,8 @@
case 'uncaught-exception':
case 'unhandled-rejection':
case 'worker-failed': {
failureCounts.set(evt.testFile, 1 + (failureCounts.get(evt.testFile) ?? 0));
const path = nodePath.relative(projectDir, evt.testFile);
failureCounts.set(path, 1 + (failureCounts.get(path) ?? 0));

Check warning on line 110 in lib/watcher.js

View check run for this annotation

Codecov / codecov/patch

lib/watcher.js#L109-L110

Added lines #L109 - L110 were not covered by tests
break;
}

Expand Down
109 changes: 103 additions & 6 deletions test/external-assertions/snapshots/test.js.md
Expand Up @@ -4,7 +4,7 @@ The actual snapshot is saved in `test.js.snap`.

Generated by [AVA](https://avajs.dev).

## node assertion (node.js v18)
## node assertion (node.js v^18)

> Snapshot 1

Expand Down Expand Up @@ -46,7 +46,7 @@ Generated by [AVA](https://avajs.dev).
2 tests failed`

## expect error (node.js v18)
## expect error (node.js v^18)

> Snapshot 1

Expand Down Expand Up @@ -96,7 +96,7 @@ Generated by [AVA](https://avajs.dev).
2 tests failed`

## node assertion (node.js v20)
## node assertion (node.js v^20 < 20.11)

> Snapshot 1

Expand Down Expand Up @@ -138,7 +138,7 @@ Generated by [AVA](https://avajs.dev).
2 tests failed`

## expect error (node.js v20)
## expect error (node.js v^20 < 20.11)

> Snapshot 1

Expand Down Expand Up @@ -188,7 +188,7 @@ Generated by [AVA](https://avajs.dev).
2 tests failed`

## node assertion (node.js v21)
## node assertion (node.js v^20.11)

> Snapshot 1

Expand Down Expand Up @@ -235,7 +235,104 @@ Generated by [AVA](https://avajs.dev).
2 tests failed`

## expect error (node.js v21)
## expect error (node.js v^20.11)

> Snapshot 1

`␊
✘ [fail]: test Assertion failed␊
✘ [fail]: test async Assertion failed␊
─␊
test␊
Assertion failed: ␊
expect(received).toBeTruthy()␊
Received: false␊
Error: expect(received).toBeTruthy()␊
Received: false␊
at ---␊
at ---␊
at ---␊
at ---␊
at ---␊
at ---␊
at ---␊
at ---␊
at ---␊
test async␊
Assertion failed: ␊
expect(received).toBeTruthy()␊
Received: false␊
Error: expect(received).toBeTruthy()␊
Received: false␊
at ---␊
at ---␊
─␊
2 tests failed`

## node assertion (node.js v^21)

> Snapshot 1

`␊
✘ [fail]: test Assertion failed␊
✘ [fail]: test async Assertion failed␊
─␊
test␊
Assertion failed: ␊
The expression evaluated to a falsy value:␊
assert(false)␊
AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:␊
assert(false)␊
at ---␊
at ---␊
at ---␊
at ---␊
at ---␊
at ---␊
at ---␊
at ---␊
at ---␊
test async␊
Assertion failed: ␊
false == true␊
AssertionError [ERR_ASSERTION]: false == true␊
at ---␊
at ---␊
─␊
2 tests failed`

## expect error (node.js v^21)

> Snapshot 1

Expand Down
Binary file modified test/external-assertions/snapshots/test.js.snap
Binary file not shown.
15 changes: 9 additions & 6 deletions test/external-assertions/test.js
Expand Up @@ -13,21 +13,24 @@ const snapshotStdout = (t, stdout) => {
t.snapshot(normalized);
};

const major = process.versions.node.split('.')[0];

for (const version of ['18', '20', '21']) {
for (const [label, selector] of Object.entries({
'^18': /^18\./,
'^20 < 20.11': /^20\.(\d\.|10\.)/,
'^20.11': /^20\.(1[1-9]\.|[2-9]\d\.)/,
'^21': /^21\./,
})) {
// Tests need to be declared for all versions, so that snapshots can be
// updated by running `npx test-ava -u test/external-assertions/test.js` for
// each supported version. However only the tests for the current version
// can run, so skip the others.
const declare = version === major ? test : test.skip;
const declare = selector.test(process.versions.node) ? test : test.skip;

declare(`node assertion (node.js v${version})`, async t => {
declare(`node assertion (node.js v${label})`, async t => {
const result = await t.throwsAsync(fixture(['assert-failure.js']));
snapshotStdout(t, result.stdout);
});

declare(`expect error (node.js v${version})`, async t => {
declare(`expect error (node.js v${label})`, async t => {
const result = await t.throwsAsync(fixture(['expect-failure.js']));
snapshotStdout(t, result.stdout);
});
Expand Down