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

Don't force-exit after tests have completed #3260

Merged
merged 7 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix external assertions tests for Node.js 21
The assertion message is different, which requires more creativity with the snapshots.
  • Loading branch information
novemberborn committed Dec 3, 2023
commit 4210433bcb1ef8d5ed591d5b3ebbadbc63c042c3
193 changes: 191 additions & 2 deletions test/external-assertions/snapshots/test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The actual snapshot is saved in `test.js.snap`.

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

## node assertion
## node assertion (node.js v18)

> Snapshot 1

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

## expect error
## expect error (node.js v18)

> 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 v20)

> Snapshot 1

`␊
✘ [fail]: test Assertion failed␊
✘ [fail]: test async Assertion failed␊
─␊
test␊
Assertion failed: ␊
false == true␊
AssertionError [ERR_ASSERTION]: false == true␊
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 v20)

> 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 v21)

> 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 v21)

> Snapshot 1

Expand Down
Binary file modified test/external-assertions/snapshots/test.js.snap
Binary file not shown.
38 changes: 30 additions & 8 deletions test/external-assertions/test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
import process from 'node:process';

import test from '@ava/test';

import {fixture} from '../helpers/exec.js';

test('node assertion ', async t => {
const result = await t.throwsAsync(fixture(['assert-failure.js']));
t.snapshot(result.stdout.replaceAll('\r', '').replaceAll(/\/{3}/g, '//').replaceAll(/at.*\n/g, 'at ---\n'));
});
const snapshotStdout = (t, stdout) => {
const normalized = stdout
.replaceAll('\r', '')
.replaceAll(/\/{3}/g, '//')
.replaceAll(/(\b)at.*\n/g, '$1at ---\n');

t.log(process.versions.node.split('.')[0]);
t.snapshot(normalized);
};

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

for (const version of ['18', '20', '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;

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

test('expect error ', async t => {
const result = await t.throwsAsync(fixture(['expect-failure.js']));
t.snapshot(result.stdout.replaceAll('\r', '').replaceAll(/\/{3}/g, '//').replaceAll(/at.*\n/g, 'at ---\n'));
});
declare(`expect error (node.js v${version})`, async t => {
const result = await t.throwsAsync(fixture(['expect-failure.js']));
snapshotStdout(t, result.stdout);
});
}
Loading