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 17aeedced..9a7c578f3 100644 Binary files a/test/snapshot-order/fixtures/randomness/test.js.snap and b/test/snapshot-order/fixtures/randomness/test.js.snap differ 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 efe9b14ee..d5ee319b3 100644 Binary files a/test/snapshot-order/snapshots/randomness.js.snap and b/test/snapshot-order/snapshots/randomness.js.snap differ diff --git a/test/snapshot-workflow/helpers/macros.js b/test/snapshot-workflow/helpers/macros.js index 835316231..00deecf53 100644 --- a/test/snapshot-workflow/helpers/macros.js +++ b/test/snapshot-workflow/helpers/macros.js @@ -1,9 +1,11 @@ import {promises as fs} from 'node:fs'; import path from 'node:path'; +import {gunzipSync} from 'node:zlib'; import concordance from 'concordance'; +import {extractCompressedSnapshot} from '../../../lib/snapshot-manager.js'; import {fixture} from '../../helpers/exec.js'; import {withTemporaryFixture} from '../../helpers/with-temporary-fixture.js'; @@ -63,9 +65,12 @@ export async function beforeAndAfter(t, { } async function readSnapshots(cwd) { + const snapPath = path.join(cwd, 'test.js.snap'); const [snapshot, report] = await Promise.all([ - fs.readFile(path.join(cwd, 'test.js.snap')), + fs.readFile(snapPath), fs.readFile(path.join(cwd, 'test.js.md'), 'utf8'), ]); - return {snapshot, report}; + + const {version, compressed} = extractCompressedSnapshot(snapshot, snapPath); + return {snapshot: {version, decompressed: gunzipSync(compressed)}, report}; }