Skip to content

Commit 0492d32

Browse files
committed
Fix external assertions tests for Node.js 21
The assertion message is different, which requires more creativity with the snapshots.
1 parent adbfcde commit 0492d32

File tree

3 files changed

+221
-10
lines changed

3 files changed

+221
-10
lines changed

test/external-assertions/snapshots/test.js.md

Lines changed: 191 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The actual snapshot is saved in `test.js.snap`.
44

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

7-
## node assertion
7+
## node assertion (node.js v18)
88

99
> Snapshot 1
1010
@@ -46,7 +46,196 @@ Generated by [AVA](https://avajs.dev).
4646
4747
2 tests failed`
4848

49-
## expect error
49+
## expect error (node.js v18)
50+
51+
> Snapshot 1
52+
53+
`␊
54+
✘ [fail]: test Assertion failed␊
55+
✘ [fail]: test async Assertion failed␊
56+
─␊
57+
58+
test␊
59+
60+
Assertion failed: ␊
61+
62+
expect(received).toBeTruthy()␊
63+
64+
Received: false␊
65+
66+
Error: expect(received).toBeTruthy()␊
67+
68+
Received: false␊
69+
at ---␊
70+
at ---␊
71+
at ---␊
72+
at ---␊
73+
at ---␊
74+
at ---␊
75+
at ---␊
76+
at ---␊
77+
at ---␊
78+
79+
80+
81+
test async␊
82+
83+
Assertion failed: ␊
84+
85+
expect(received).toBeTruthy()␊
86+
87+
Received: false␊
88+
89+
Error: expect(received).toBeTruthy()␊
90+
91+
Received: false␊
92+
at ---␊
93+
at ---␊
94+
95+
─␊
96+
97+
2 tests failed`
98+
99+
## node assertion (node.js v20)
100+
101+
> Snapshot 1
102+
103+
`␊
104+
✘ [fail]: test Assertion failed␊
105+
✘ [fail]: test async Assertion failed␊
106+
─␊
107+
108+
test␊
109+
110+
Assertion failed: ␊
111+
112+
false == true␊
113+
114+
AssertionError [ERR_ASSERTION]: false == true␊
115+
at ---␊
116+
at ---␊
117+
at ---␊
118+
at ---␊
119+
at ---␊
120+
at ---␊
121+
at ---␊
122+
at ---␊
123+
at ---␊
124+
125+
126+
127+
test async␊
128+
129+
Assertion failed: ␊
130+
131+
false == true␊
132+
133+
AssertionError [ERR_ASSERTION]: false == true␊
134+
at ---␊
135+
at ---␊
136+
137+
─␊
138+
139+
2 tests failed`
140+
141+
## expect error (node.js v20)
142+
143+
> Snapshot 1
144+
145+
`␊
146+
✘ [fail]: test Assertion failed␊
147+
✘ [fail]: test async Assertion failed␊
148+
─␊
149+
150+
test␊
151+
152+
Assertion failed: ␊
153+
154+
expect(received).toBeTruthy()␊
155+
156+
Received: false␊
157+
158+
Error: expect(received).toBeTruthy()␊
159+
160+
Received: false␊
161+
at ---␊
162+
at ---␊
163+
at ---␊
164+
at ---␊
165+
at ---␊
166+
at ---␊
167+
at ---␊
168+
at ---␊
169+
at ---␊
170+
171+
172+
173+
test async␊
174+
175+
Assertion failed: ␊
176+
177+
expect(received).toBeTruthy()␊
178+
179+
Received: false␊
180+
181+
Error: expect(received).toBeTruthy()␊
182+
183+
Received: false␊
184+
at ---␊
185+
at ---␊
186+
187+
─␊
188+
189+
2 tests failed`
190+
191+
## node assertion (node.js v21)
192+
193+
> Snapshot 1
194+
195+
`␊
196+
✘ [fail]: test Assertion failed␊
197+
✘ [fail]: test async Assertion failed␊
198+
─␊
199+
200+
test␊
201+
202+
Assertion failed: ␊
203+
204+
The expression evaluated to a falsy value:␊
205+
206+
assert(false)␊
207+
208+
AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:␊
209+
210+
assert(false)␊
211+
212+
at ---␊
213+
at ---␊
214+
at ---␊
215+
at ---␊
216+
at ---␊
217+
at ---␊
218+
at ---␊
219+
at ---␊
220+
at ---␊
221+
222+
223+
224+
test async␊
225+
226+
Assertion failed: ␊
227+
228+
false == true␊
229+
230+
AssertionError [ERR_ASSERTION]: false == true␊
231+
at ---␊
232+
at ---␊
233+
234+
─␊
235+
236+
2 tests failed`
237+
238+
## expect error (node.js v21)
50239

51240
> Snapshot 1
52241
113 Bytes
Binary file not shown.

test/external-assertions/test.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
1+
import process from 'node:process';
2+
13
import test from '@ava/test';
24

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

5-
test('node assertion ', async t => {
6-
const result = await t.throwsAsync(fixture(['assert-failure.js']));
7-
t.snapshot(result.stdout.replaceAll('\r', '').replaceAll(/\/{3}/g, '//').replaceAll(/at.*\n/g, 'at ---\n'));
8-
});
7+
const snapshotStdout = (t, stdout) => {
8+
const normalized = stdout
9+
.replaceAll('\r', '')
10+
.replaceAll(/\/{3}/g, '//')
11+
.replaceAll(/(\b)at.*\n/g, '$1at ---\n');
12+
13+
t.log(process.versions.node.split('.')[0]);
14+
t.snapshot(normalized);
15+
};
16+
17+
const major = process.versions.node.split('.')[0];
18+
19+
for (const version of ['18', '20', '21']) {
20+
// Tests need to be declared for all versions, so that snapshots can be
21+
// updated by running `npx test-ava -u test/external-assertions/test.js` for
22+
// each supported version. However only the tests for the current version
23+
// can run, so skip the others.
24+
const declare = version === major ? test : test.skip;
25+
26+
declare(`node assertion (node.js v${version})`, async t => {
27+
const result = await t.throwsAsync(fixture(['assert-failure.js']));
28+
snapshotStdout(t, result.stdout);
29+
});
930

10-
test('expect error ', async t => {
11-
const result = await t.throwsAsync(fixture(['expect-failure.js']));
12-
t.snapshot(result.stdout.replaceAll('\r', '').replaceAll(/\/{3}/g, '//').replaceAll(/at.*\n/g, 'at ---\n'));
13-
});
31+
declare(`expect error (node.js v${version})`, async t => {
32+
const result = await t.throwsAsync(fixture(['expect-failure.js']));
33+
snapshotStdout(t, result.stdout);
34+
});
35+
}

0 commit comments

Comments
 (0)