-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix external assertions tests for Node.js 21
The assertion message is different, which requires more creativity with the snapshots.
- Loading branch information
1 parent
adbfcde
commit 0492d32
Showing
3 changed files
with
221 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} |