Skip to content

Commit 03a6723

Browse files
authored
Drop Node.js 16, upgrade minimal 18 and 20, test 21
* Drop support for Node.js 16 * Change expected Node.js 18 to 18.18 * Change expected Node.js 20 to 20.8 * Add Node.js 21 to the test matrix * Change snapshot tests to compare decompressed bitstreams The snapshots are compressed differently in Node.js 21. The compression has been stable for many versions but that is not a guarantee, see nodejs/node#50138 for background. Change tests to compare the decompressed data instead.
1 parent b6fbd58 commit 03a6723

24 files changed

+47
-19
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
node-version: [^16.18, ^18.16, ^20.3]
18+
node-version: [^18.18, ^20.8, ^21]
1919
os: [ubuntu-latest, windows-latest, macos-latest]
2020
steps:
2121
- uses: actions/checkout@v3

lib/snapshot-manager.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ async function encodeSnapshots(snapshotData) {
198198
], READABLE_PREFIX.byteLength + VERSION_HEADER.byteLength + SHA_256_HASH_LENGTH + compressed.byteLength);
199199
}
200200

201-
function decodeSnapshots(buffer, snapPath) {
201+
export function extractCompressedSnapshot(buffer, snapPath) {
202202
if (isLegacySnapshot(buffer)) {
203203
throw new LegacyError(snapPath);
204204
}
@@ -220,6 +220,12 @@ function decodeSnapshots(buffer, snapPath) {
220220
const compressedOffset = sha256sumOffset + SHA_256_HASH_LENGTH;
221221
const compressed = buffer.slice(compressedOffset);
222222

223+
return {version, compressed, sha256sumOffset, compressedOffset};
224+
}
225+
226+
function decodeSnapshots(buffer, snapPath) {
227+
const {compressed, sha256sumOffset, compressedOffset} = extractCompressedSnapshot(buffer, snapPath);
228+
223229
const sha256sum = crypto.createHash('sha256').update(compressed).digest();
224230
const expectedSum = buffer.slice(sha256sumOffset, compressedOffset);
225231
if (!sha256sum.equals(expectedSum)) {

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"type": "module",
3535
"engines": {
36-
"node": "^16.18 || ^18.16 || ^20.3"
36+
"node": "^18.18 || ^20.8 || ^21"
3737
},
3838
"scripts": {
3939
"test": "./scripts/test.sh"
@@ -151,6 +151,6 @@
151151
}
152152
},
153153
"volta": {
154-
"node": "20.3.1"
154+
"node": "20.8.1"
155155
}
156156
}

test-tap/integration/snapshots.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import {Buffer} from 'node:buffer';
22
import fs from 'node:fs';
33
import path from 'node:path';
44
import {fileURLToPath} from 'node:url';
5+
import {gunzipSync} from 'node:zlib';
56

67
import {execa} from 'execa';
78
import {test} from 'tap';
89
import {temporaryDirectory} from 'tempy';
910

11+
import {extractCompressedSnapshot} from '../../lib/snapshot-manager.js';
1012
import {execCli} from '../helper/cli.js';
1113

1214
const __dirname = fileURLToPath(new URL('.', import.meta.url));
@@ -265,9 +267,9 @@ test('snapshots are identical on different platforms', t => {
265267
t.ok(fs.existsSync(snapPath));
266268

267269
const reportContents = fs.readFileSync(reportPath);
268-
const snapContents = fs.readFileSync(snapPath);
270+
const snapContents = gunzipSync(extractCompressedSnapshot(fs.readFileSync(snapPath)).compressed);
269271
const expectedReportContents = fs.readFileSync(expectedReportPath);
270-
const expectedSnapContents = fs.readFileSync(expectedSnapPath);
272+
const expectedSnapContents = gunzipSync(extractCompressedSnapshot(fs.readFileSync(expectedSnapPath)).compressed);
271273

272274
t.ok(reportContents.equals(expectedReportContents), 'report file contents matches snapshot');
273275
t.ok(snapContents.equals(expectedSnapContents), 'snap file contents matches snapshot');
Binary file not shown.

test/snapshot-order/randomness.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
3+
import {gunzipSync} from 'node:zlib';
34

45
import test from '@ava/test';
56

7+
import {extractCompressedSnapshot} from '../../lib/snapshot-manager.js';
68
import {cwd, fixture} from '../helpers/exec.js';
79

810
import getSnapshotIds from './helpers/get-snapshot-ids.js';
@@ -23,8 +25,9 @@ test('deterministic and sorted over a large, random test case', async t => {
2325

2426
// Assert snapshot is unchanged
2527
const snapshot = fs.readFileSync(snapshotPath);
28+
const {compressed} = extractCompressedSnapshot(snapshot, snapshotPath);
2629

27-
t.snapshot(snapshot, 'resulting snapshot in binary encoding');
30+
t.snapshot(gunzipSync(compressed), 'resulting snapshot in binary encoding');
2831

2932
// Assert report is sorted
3033
const report = fs.readFileSync(reportPath);

test/snapshot-order/snapshots/randomness.js.md

+22-10
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,26 @@ Generated by [AVA](https://avajs.dev).
99
> resulting snapshot in binary encoding
1010
1111
Buffer @Uint8Array [
12-
41564120 536e6170 73686f74 2076330a 03008ba7 6ff7a1a2 251e5fa1 afbf3fa8
13-
fdf7ca69 3e5b2af2 b0734c95 46791417 ae201f8b 08000000 00000003 5b989694
14-
939f9c5d dcba28b5 24b32427 b542ca49 41572125 353927b1 2855a138 3f1748e4
15-
25161467 e4971467 c259cd0b 5352124b 12c39819 d8194080 91954190 9123332f
16-
25b5c24a c160111e 49c3d49c c4a4d49c dc8cc462 854485dc d4e2e2c4 f4547c1a
17-
8c201a8a 12738af3 15507541 5d2cef88 eee2dcfc 22acce6e c4e76c13 9879aace
18-
38434021 330f687f 4951a586 265260e0 73be29c4 f9a9f9a5 25a945f8 149a4115
19-
66e6e5e1 57680e51 980d3651 21313d31 330fee72 5790cb33 8b93138b 52887179
20-
133e7b2c 305d1e8e a2901316 a506385d 54e40274 10aed868 5a88cf50 23bcb2c6
21-
00d6e9f1 35b80200 00
12+
a166626c 6f636b73 85a26574 69746c65 781a4220 2d206465 636c6172 6520736f
13+
6d652073 6e617073 686f7473 69736e61 7073686f 747383a1 64646174 61560300
14+
07000000 00000105 00110108 696e6465 783a2030 a2646461 74615603 00070000
15+
00000001 05001101 08696e64 65783a20 31656c61 62656c6d 68617320 61206d65
16+
73736167 65a26464 61746156 03000700 00000000 01050011 0108696e 6465783a
17+
2032656c 6162656c 72616c73 6f206861 73206120 6d657373 616765a2 65746974
18+
6c65781f 41202d20 6465636c 61726520 736f6d65 206d6f72 6520736e 61707368
19+
6f747369 736e6170 73686f74 7381a164 64617461 56030007 00000000 00010500
20+
11010869 6e646578 3a2034a2 65746974 6c657825 43202d20 6465636c 61726520
21+
736f6d65 20736e61 7073686f 74732069 6e206120 74727928 2969736e 61707368
22+
6f747383 a2646461 74615603 00070000 00000001 05001101 08696e64 65783a20
23+
35656c61 62656c65 6f757465 72a26464 61746156 03000700 00000000 01050011
24+
0108696e 6465783a 2036656c 6162656c 65696e6e 6572a264 64617461 56030007
25+
00000000 00010500 11010869 6e646578 3a203765 6c616265 6c6b6f75 74657220
26+
61676169 6ea26574 69746c65 78254520 2d206469 73636172 6420736f 6d652073
27+
6e617073 686f7473 20696e20 61207472 79282969 736e6170 73686f74 7382a264
28+
64617461 56030007 00000000 00010500 11010869 6e646578 3a203865 6c616265
29+
6c656f75 746572a2 64646174 61570300 07000000 00000105 00110109 696e6465
30+
783a2031 30656c61 62656c6b 6f757465 72206167 61696ea2 65746974 6c657244
31+
202d206d 6f726520 736e6170 73686f74 7369736e 61707368 6f747382 a1646461
32+
74615703 00070000 00000001 05001101 09696e64 65783a20 3132a164 64617461
33+
57030007 00000000 00010500 11010969 6e646578 3a203133
2234
]
-141 Bytes
Binary file not shown.

test/snapshot-workflow/helpers/macros.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11

22
import {promises as fs} from 'node:fs';
33
import path from 'node:path';
4+
import {gunzipSync} from 'node:zlib';
45

56
import concordance from 'concordance';
67

8+
import {extractCompressedSnapshot} from '../../../lib/snapshot-manager.js';
79
import {fixture} from '../../helpers/exec.js';
810
import {withTemporaryFixture} from '../../helpers/with-temporary-fixture.js';
911

@@ -63,9 +65,12 @@ export async function beforeAndAfter(t, {
6365
}
6466

6567
async function readSnapshots(cwd) {
68+
const snapPath = path.join(cwd, 'test.js.snap');
6669
const [snapshot, report] = await Promise.all([
67-
fs.readFile(path.join(cwd, 'test.js.snap')),
70+
fs.readFile(snapPath),
6871
fs.readFile(path.join(cwd, 'test.js.md'), 'utf8'),
6972
]);
70-
return {snapshot, report};
73+
74+
const {version, compressed} = extractCompressedSnapshot(snapshot, snapPath);
75+
return {snapshot: {version, decompressed: gunzipSync(compressed)}, report};
7176
}

0 commit comments

Comments
 (0)