From 03a6723a11ce8da49df6fa5f6f06244885c097f0 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Mon, 23 Oct 2023 13:56:52 +0200 Subject: [PATCH] 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 https://github.com/nodejs/node/issues/50138 for background. Change tests to compare the decompressed data instead. --- .github/workflows/ci.yml | 2 +- lib/snapshot-manager.js | 8 ++++- package.json | 4 +-- test-tap/integration/snapshots.js | 6 ++-- ...ases.v16.log => default.edgecases.v21.log} | 0 ...lfast.v16.log => default.failfast.v21.log} | 0 ...ast2.v16.log => default.failfast2.v21.log} | 0 ...ault.only.v16.log => default.only.v21.log} | 0 ...egular.v16.log => default.regular.v21.log} | 0 ...log => default.timeoutcontextlogs.v21.log} | 0 ...=> default.timeoutinmultiplefiles.v21.log} | 0 ...og => default.timeoutinsinglefile.v21.log} | 0 ...6.log => default.timeoutwithmatch.v21.log} | 0 ...lt.watch.v16.log => default.watch.v21.log} | 0 ...dgecases.v16.log => tap.edgecases.v21.log} | 0 ....failfast.v16.log => tap.failfast.v21.log} | 0 ...ailfast2.v16.log => tap.failfast2.v21.log} | 0 .../{tap.only.v16.log => tap.only.v21.log} | 0 ...ap.regular.v16.log => tap.regular.v21.log} | 0 .../fixtures/randomness/test.js.snap | Bin 297 -> 293 bytes test/snapshot-order/randomness.js | 5 ++- .../snapshot-order/snapshots/randomness.js.md | 32 ++++++++++++------ .../snapshots/randomness.js.snap | Bin 593 -> 452 bytes test/snapshot-workflow/helpers/macros.js | 9 +++-- 24 files changed, 47 insertions(+), 19 deletions(-) rename test-tap/reporters/{default.edgecases.v16.log => default.edgecases.v21.log} (100%) rename test-tap/reporters/{default.failfast.v16.log => default.failfast.v21.log} (100%) rename test-tap/reporters/{default.failfast2.v16.log => default.failfast2.v21.log} (100%) rename test-tap/reporters/{default.only.v16.log => default.only.v21.log} (100%) rename test-tap/reporters/{default.regular.v16.log => default.regular.v21.log} (100%) rename test-tap/reporters/{default.timeoutcontextlogs.v16.log => default.timeoutcontextlogs.v21.log} (100%) rename test-tap/reporters/{default.timeoutinmultiplefiles.v16.log => default.timeoutinmultiplefiles.v21.log} (100%) rename test-tap/reporters/{default.timeoutinsinglefile.v16.log => default.timeoutinsinglefile.v21.log} (100%) rename test-tap/reporters/{default.timeoutwithmatch.v16.log => default.timeoutwithmatch.v21.log} (100%) rename test-tap/reporters/{default.watch.v16.log => default.watch.v21.log} (100%) rename test-tap/reporters/{tap.edgecases.v16.log => tap.edgecases.v21.log} (100%) rename test-tap/reporters/{tap.failfast.v16.log => tap.failfast.v21.log} (100%) rename test-tap/reporters/{tap.failfast2.v16.log => tap.failfast2.v21.log} (100%) rename test-tap/reporters/{tap.only.v16.log => tap.only.v21.log} (100%) rename test-tap/reporters/{tap.regular.v16.log => tap.regular.v21.log} (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 038498ea6..f8b693016 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [^16.18, ^18.16, ^20.3] + node-version: [^18.18, ^20.8, ^21] os: [ubuntu-latest, windows-latest, macos-latest] steps: - uses: actions/checkout@v3 diff --git a/lib/snapshot-manager.js b/lib/snapshot-manager.js index 0a52cd76a..9a9abaa92 100644 --- a/lib/snapshot-manager.js +++ b/lib/snapshot-manager.js @@ -198,7 +198,7 @@ async function encodeSnapshots(snapshotData) { ], READABLE_PREFIX.byteLength + VERSION_HEADER.byteLength + SHA_256_HASH_LENGTH + compressed.byteLength); } -function decodeSnapshots(buffer, snapPath) { +export function extractCompressedSnapshot(buffer, snapPath) { if (isLegacySnapshot(buffer)) { throw new LegacyError(snapPath); } @@ -220,6 +220,12 @@ function decodeSnapshots(buffer, snapPath) { const compressedOffset = sha256sumOffset + SHA_256_HASH_LENGTH; const compressed = buffer.slice(compressedOffset); + return {version, compressed, sha256sumOffset, compressedOffset}; +} + +function decodeSnapshots(buffer, snapPath) { + const {compressed, sha256sumOffset, compressedOffset} = extractCompressedSnapshot(buffer, snapPath); + const sha256sum = crypto.createHash('sha256').update(compressed).digest(); const expectedSum = buffer.slice(sha256sumOffset, compressedOffset); if (!sha256sum.equals(expectedSum)) { diff --git a/package.json b/package.json index 5f124ff64..c564a4e62 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ }, "type": "module", "engines": { - "node": "^16.18 || ^18.16 || ^20.3" + "node": "^18.18 || ^20.8 || ^21" }, "scripts": { "test": "./scripts/test.sh" @@ -151,6 +151,6 @@ } }, "volta": { - "node": "20.3.1" + "node": "20.8.1" } } diff --git a/test-tap/integration/snapshots.js b/test-tap/integration/snapshots.js index 73e311db0..36461129b 100644 --- a/test-tap/integration/snapshots.js +++ b/test-tap/integration/snapshots.js @@ -2,11 +2,13 @@ import {Buffer} from 'node:buffer'; import fs from 'node:fs'; import path from 'node:path'; import {fileURLToPath} from 'node:url'; +import {gunzipSync} from 'node:zlib'; import {execa} from 'execa'; import {test} from 'tap'; import {temporaryDirectory} from 'tempy'; +import {extractCompressedSnapshot} from '../../lib/snapshot-manager.js'; import {execCli} from '../helper/cli.js'; const __dirname = fileURLToPath(new URL('.', import.meta.url)); @@ -265,9 +267,9 @@ test('snapshots are identical on different platforms', t => { t.ok(fs.existsSync(snapPath)); const reportContents = fs.readFileSync(reportPath); - const snapContents = fs.readFileSync(snapPath); + const snapContents = gunzipSync(extractCompressedSnapshot(fs.readFileSync(snapPath)).compressed); const expectedReportContents = fs.readFileSync(expectedReportPath); - const expectedSnapContents = fs.readFileSync(expectedSnapPath); + const expectedSnapContents = gunzipSync(extractCompressedSnapshot(fs.readFileSync(expectedSnapPath)).compressed); t.ok(reportContents.equals(expectedReportContents), 'report file contents matches snapshot'); t.ok(snapContents.equals(expectedSnapContents), 'snap file contents matches snapshot'); diff --git a/test-tap/reporters/default.edgecases.v16.log b/test-tap/reporters/default.edgecases.v21.log similarity index 100% rename from test-tap/reporters/default.edgecases.v16.log rename to test-tap/reporters/default.edgecases.v21.log diff --git a/test-tap/reporters/default.failfast.v16.log b/test-tap/reporters/default.failfast.v21.log similarity index 100% rename from test-tap/reporters/default.failfast.v16.log rename to test-tap/reporters/default.failfast.v21.log diff --git a/test-tap/reporters/default.failfast2.v16.log b/test-tap/reporters/default.failfast2.v21.log similarity index 100% rename from test-tap/reporters/default.failfast2.v16.log rename to test-tap/reporters/default.failfast2.v21.log diff --git a/test-tap/reporters/default.only.v16.log b/test-tap/reporters/default.only.v21.log similarity index 100% rename from test-tap/reporters/default.only.v16.log rename to test-tap/reporters/default.only.v21.log diff --git a/test-tap/reporters/default.regular.v16.log b/test-tap/reporters/default.regular.v21.log similarity index 100% rename from test-tap/reporters/default.regular.v16.log rename to test-tap/reporters/default.regular.v21.log diff --git a/test-tap/reporters/default.timeoutcontextlogs.v16.log b/test-tap/reporters/default.timeoutcontextlogs.v21.log similarity index 100% rename from test-tap/reporters/default.timeoutcontextlogs.v16.log rename to test-tap/reporters/default.timeoutcontextlogs.v21.log diff --git a/test-tap/reporters/default.timeoutinmultiplefiles.v16.log b/test-tap/reporters/default.timeoutinmultiplefiles.v21.log similarity index 100% rename from test-tap/reporters/default.timeoutinmultiplefiles.v16.log rename to test-tap/reporters/default.timeoutinmultiplefiles.v21.log diff --git a/test-tap/reporters/default.timeoutinsinglefile.v16.log b/test-tap/reporters/default.timeoutinsinglefile.v21.log similarity index 100% rename from test-tap/reporters/default.timeoutinsinglefile.v16.log rename to test-tap/reporters/default.timeoutinsinglefile.v21.log diff --git a/test-tap/reporters/default.timeoutwithmatch.v16.log b/test-tap/reporters/default.timeoutwithmatch.v21.log similarity index 100% rename from test-tap/reporters/default.timeoutwithmatch.v16.log rename to test-tap/reporters/default.timeoutwithmatch.v21.log diff --git a/test-tap/reporters/default.watch.v16.log b/test-tap/reporters/default.watch.v21.log similarity index 100% rename from test-tap/reporters/default.watch.v16.log rename to test-tap/reporters/default.watch.v21.log diff --git a/test-tap/reporters/tap.edgecases.v16.log b/test-tap/reporters/tap.edgecases.v21.log similarity index 100% rename from test-tap/reporters/tap.edgecases.v16.log rename to test-tap/reporters/tap.edgecases.v21.log diff --git a/test-tap/reporters/tap.failfast.v16.log b/test-tap/reporters/tap.failfast.v21.log similarity index 100% rename from test-tap/reporters/tap.failfast.v16.log rename to test-tap/reporters/tap.failfast.v21.log diff --git a/test-tap/reporters/tap.failfast2.v16.log b/test-tap/reporters/tap.failfast2.v21.log similarity index 100% rename from test-tap/reporters/tap.failfast2.v16.log rename to test-tap/reporters/tap.failfast2.v21.log diff --git a/test-tap/reporters/tap.only.v16.log b/test-tap/reporters/tap.only.v21.log similarity index 100% rename from test-tap/reporters/tap.only.v16.log rename to test-tap/reporters/tap.only.v21.log diff --git a/test-tap/reporters/tap.regular.v16.log b/test-tap/reporters/tap.regular.v21.log similarity index 100% rename from test-tap/reporters/tap.regular.v16.log rename to test-tap/reporters/tap.regular.v21.log diff --git a/test/snapshot-order/fixtures/randomness/test.js.snap b/test/snapshot-order/fixtures/randomness/test.js.snap index 17aeedced8a515ea99db267b5118e202c087fa5a..9a7c578f3ed3fbf643a073bef0d67df9f807ddfd 100644 GIT binary patch literal 293 zcmV+=0owjSRzV6Xdl3BBR(ez0SI~3Zi8?qtQzj$m zQN;&YpS0+zXzd1b3gr8~{7BOA$hdgM+Z_cR3@xfXsDYx`peJCL5U|A`p1Q#L+-*{& zFyNpVJw*E|l%h)EQCmfePpI#NVS@~g$Rtx_KuCxgCnOn~nZcuB2iLA6@l*FNapL^H z*eeOUead_8=UxD`1%%+2FRvHJknrC!d~)+ZUJ||^h1yzK_>l=`heW^$YI`RC-ji#N r(W`sN*V3NOE&1?DSU$b9o=fDvpqBfMbt;86#cAso*6HyzxB>tGjHQhg literal 297 zcmV+^0oMLORzVtGc94H| diff --git a/test/snapshot-order/randomness.js b/test/snapshot-order/randomness.js index 297f09be1..a2666109c 100644 --- a/test/snapshot-order/randomness.js +++ b/test/snapshot-order/randomness.js @@ -1,8 +1,10 @@ import fs from 'node:fs'; import path from 'node:path'; +import {gunzipSync} from 'node:zlib'; import test from '@ava/test'; +import {extractCompressedSnapshot} from '../../lib/snapshot-manager.js'; import {cwd, fixture} from '../helpers/exec.js'; import getSnapshotIds from './helpers/get-snapshot-ids.js'; @@ -23,8 +25,9 @@ test('deterministic and sorted over a large, random test case', async t => { // Assert snapshot is unchanged const snapshot = fs.readFileSync(snapshotPath); + const {compressed} = extractCompressedSnapshot(snapshot, snapshotPath); - t.snapshot(snapshot, 'resulting snapshot in binary encoding'); + t.snapshot(gunzipSync(compressed), 'resulting snapshot in binary encoding'); // Assert report is sorted const report = fs.readFileSync(reportPath); diff --git a/test/snapshot-order/snapshots/randomness.js.md b/test/snapshot-order/snapshots/randomness.js.md index 3d401bdf1..4b84d1723 100644 --- a/test/snapshot-order/snapshots/randomness.js.md +++ b/test/snapshot-order/snapshots/randomness.js.md @@ -9,14 +9,26 @@ Generated by [AVA](https://avajs.dev). > resulting snapshot in binary encoding Buffer @Uint8Array [ - 41564120 536e6170 73686f74 2076330a 03008ba7 6ff7a1a2 251e5fa1 afbf3fa8 - fdf7ca69 3e5b2af2 b0734c95 46791417 ae201f8b 08000000 00000003 5b989694 - 939f9c5d dcba28b5 24b32427 b542ca49 41572125 353927b1 2855a138 3f1748e4 - 25161467 e4971467 c259cd0b 5352124b 12c39819 d8194080 91954190 9123332f - 25b5c24a c160111e 49c3d49c c4a4d49c dc8cc462 854485dc d4e2e2c4 f4547c1a - 8c201a8a 12738af3 15507541 5d2cef88 eee2dcfc 22acce6e c4e76c13 9879aace - 38434021 330f687f 4951a586 265260e0 73be29c4 f9a9f9a5 25a945f8 149a4115 - 66e6e5e1 57680e51 980d3651 21313d31 330fee72 5790cb33 8b93138b 52887179 - 133e7b2c 305d1e8e a2901316 a506385d 54e40274 10aed868 5a88cf50 23bcb2c6 - 00d6e9f1 35b80200 00 + a166626c 6f636b73 85a26574 69746c65 781a4220 2d206465 636c6172 6520736f + 6d652073 6e617073 686f7473 69736e61 7073686f 747383a1 64646174 61560300 + 07000000 00000105 00110108 696e6465 783a2030 a2646461 74615603 00070000 + 00000001 05001101 08696e64 65783a20 31656c61 62656c6d 68617320 61206d65 + 73736167 65a26464 61746156 03000700 00000000 01050011 0108696e 6465783a + 2032656c 6162656c 72616c73 6f206861 73206120 6d657373 616765a2 65746974 + 6c65781f 41202d20 6465636c 61726520 736f6d65 206d6f72 6520736e 61707368 + 6f747369 736e6170 73686f74 7381a164 64617461 56030007 00000000 00010500 + 11010869 6e646578 3a2034a2 65746974 6c657825 43202d20 6465636c 61726520 + 736f6d65 20736e61 7073686f 74732069 6e206120 74727928 2969736e 61707368 + 6f747383 a2646461 74615603 00070000 00000001 05001101 08696e64 65783a20 + 35656c61 62656c65 6f757465 72a26464 61746156 03000700 00000000 01050011 + 0108696e 6465783a 2036656c 6162656c 65696e6e 6572a264 64617461 56030007 + 00000000 00010500 11010869 6e646578 3a203765 6c616265 6c6b6f75 74657220 + 61676169 6ea26574 69746c65 78254520 2d206469 73636172 6420736f 6d652073 + 6e617073 686f7473 20696e20 61207472 79282969 736e6170 73686f74 7382a264 + 64617461 56030007 00000000 00010500 11010869 6e646578 3a203865 6c616265 + 6c656f75 746572a2 64646174 61570300 07000000 00000105 00110109 696e6465 + 783a2031 30656c61 62656c6b 6f757465 72206167 61696ea2 65746974 6c657244 + 202d206d 6f726520 736e6170 73686f74 7369736e 61707368 6f747382 a1646461 + 74615703 00070000 00000001 05001101 09696e64 65783a20 3132a164 64617461 + 57030007 00000000 00010500 11010969 6e646578 3a203133 ] diff --git a/test/snapshot-order/snapshots/randomness.js.snap b/test/snapshot-order/snapshots/randomness.js.snap index efe9b14ee22331c5e7b50abe8106d0d2a177872c..d5ee319b3bb8282a9819c70c263f7f9d52c9cdf0 100644 GIT binary patch literal 452 zcmV;#0XzOdRzV1gq$8mFY`{&BVV>=;oI@hOUj5x3X z%vJubWgm+O00000000Axl1)znF%X8^UB!>YAnM73^g^PECWs2e8>lz0YCLwg!_u(Z znzk4?g7JqezrtVU$%Ex%QB)c?>29*~&b&`&CT#_=3_E%-0>e!Vy&3}pD&c}_!$U#^ zBU&m0jL2tDgp!!52#$%e5t$GJ+K`ZH;9Afp-Im6dVvHL4=ofvohQ<#*z<$+!-#vsr z?AgV+0?swNtrjSZ3wZO63sY|>Mf>^fJi=Zj5x5d6(*#9hEy-fmjJVkNNt{Ua zC-%UFeV)}TT`lbZ;llbG)jvG?)(jW^#S|Z8*ACnztj>g72)D2{6?P^S35_ThbMl)p zIoBao>_6l~mrwmS`NM*6BO7UXDUrIiK+C2vOkG7Q&gdD!TL@!>^LEd@J?z`KUGboA u;1)z=+LK=^cEP7?y^;dmjSUyk9A(^+fD5Yn1VkvAjeP=Z22}c~0{{TBaMNM{ literal 593 zcmV-X0P=ei!h(SG+Hje2w_p z_^hs*(;tfn00000000A9n3j~2pPXIXxG1$Gvm__A!aOClB(*3vGcU8aBr{ndF)u}- zIKQYQHANx6EVW1>Q6VR>C_Pn2p$I6GpQ})kT3n)#oLHQiS)7+xP@Iup0yHWmC9xzi zl5qkv13LoA9n*r%`Mh1plAQon16J%s_DosmEEn;L8WaJ9X%qy{QEGkN@bsZ zuTzlk<^bErz#Khe+LX!j=fvLGrLk3Ivx@pwr&FGe;fkuJmg*ZdLKj-ti+em#6%$E+ zGF>G7P~=(e;24TpdvxcI(wcL5N1o>h&!}8=&cfM2(U?D@ z-ZOA%n_5u9gW`RfM}DsSxm0zf>kpAxj-qMLo<0oE;0v6=YZj=19fg&`cGWrtv2uNjCJ2iyWwVG4dBRj8u