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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 2 deletions
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');

0 commit comments

Comments
 (0)