From 5642e75a7b6bf066d49e09805878342a5b1164de Mon Sep 17 00:00:00 2001 From: Gar Date: Thu, 30 Nov 2023 13:57:41 -0800 Subject: [PATCH] chore: fix tests for zlib differences between node versions --- .../test/lib/commands/pack.js.test.cjs | 28 ++++++------- .../test/lib/commands/publish.js.test.cjs | 40 +++++++++---------- test/fixtures/clean-snapshot.js | 16 ++++++-- test/lib/commands/pack.js | 11 +++++ test/lib/commands/publish.js | 8 +--- 5 files changed, 60 insertions(+), 43 deletions(-) diff --git a/tap-snapshots/test/lib/commands/pack.js.test.cjs b/tap-snapshots/test/lib/commands/pack.js.test.cjs index fdb64f990e9b8..49ce8807ffa21 100644 --- a/tap-snapshots/test/lib/commands/pack.js.test.cjs +++ b/tap-snapshots/test/lib/commands/pack.js.test.cjs @@ -16,10 +16,10 @@ Array [ name: test-package version: 1.0.0 filename: test-package-1.0.0.tgz - package size: 136 B + package size: {size}, unpacked size: 41 B - shasum: a92a0679a70a450f14f98a468756948a679e4107 - integrity: sha512-Gka9ZV/Bryxky[...]LgMJ+0F+FhXMA== + shasum: {sha} + integrity: {sha} total files: 1 ), "", @@ -41,14 +41,14 @@ Array [ Object { "mode": 420, "path": "package.json", - "size": 41, + "size": {size}, }, ], "id": "test-package@1.0.0", - "integrity": "sha512-Gka9ZV/BryxkypfvMpTvLfaJE1AUi7PK1EAbYqnVzqtucf6QvUK4CFsLVzagY1GwZVx2T1jwWLgMJ+0F+FhXMA==", + "integrity": "{sha}", "name": "test-package", - "shasum": "a92a0679a70a450f14f98a468756948a679e4107", - "size": 136, + "shasum": "{sha}", + "size": {size}, "unpackedSize": 41, "version": "1.0.0", }, @@ -71,14 +71,14 @@ Array [ Object { "mode": 420, "path": "package.json", - "size": 50, + "size": {size}, }, ], "id": "@myscope/test-package@1.0.0", - "integrity": "sha512-bUu8iTm2E5DZMrwKeyx963K6ViEmaFocXh75EujgI+FHSaJeqvObcdk1KFwdx8CbOgsfNHEvWNQw/bONAJsoNw==", + "integrity": "{sha}", "name": "@myscope/test-package", - "shasum": "7e6eb2e1ca46bed6b8fa8e144e0fcd1b22fe2d98", - "size": 145, + "shasum": "{sha}", + "size": {size}, "unpackedSize": 50, "version": "1.0.0", }, @@ -97,10 +97,10 @@ Array [ name: test-package version: 1.0.0 filename: test-package-1.0.0.tgz - package size: 136 B + package size: {size}, unpacked size: 41 B - shasum: a92a0679a70a450f14f98a468756948a679e4107 - integrity: sha512-Gka9ZV/Bryxky[...]LgMJ+0F+FhXMA== + shasum: {sha} + integrity: {sha} total files: 1 ), "", diff --git a/tap-snapshots/test/lib/commands/publish.js.test.cjs b/tap-snapshots/test/lib/commands/publish.js.test.cjs index 95778f6f86748..0b139b2f00580 100644 --- a/tap-snapshots/test/lib/commands/publish.js.test.cjs +++ b/tap-snapshots/test/lib/commands/publish.js.test.cjs @@ -38,10 +38,10 @@ Array [ name: test-package version: 1.0.0 filename: test-package-1.0.0.tgz - package size: 160 B + package size: {size}, unpacked size: 87 B - shasum:{sha} - integrity:{sha} + shasum: {sha} + integrity: {sha} total files: 1 ), ], @@ -82,7 +82,7 @@ exports[`test/lib/commands/publish.js TAP json > new package json 1`] = ` "id": "test-package@1.0.0", "name": "test-package", "version": "1.0.0", - "size": 160, + "size": {size}, "unpackedSize": 87, "shasum": "{sha}", "integrity": "{sha}", @@ -90,7 +90,7 @@ exports[`test/lib/commands/publish.js TAP json > new package json 1`] = ` "files": [ { "path": "package.json", - "size": 87, + "size": {size}, "mode": 420 } ], @@ -289,10 +289,10 @@ Array [ name: @npm/test-package version: 1.0.0 filename: npm-test-package-1.0.0.tgz - package size: 147 B + package size: {size}, unpacked size: 55 B - shasum:{sha} - integrity:{sha} + shasum: {sha} + integrity: {sha} total files: 1 ), ], @@ -344,10 +344,10 @@ Array [ name: @npm/test-package version: 1.0.0 filename: npm-test-package-1.0.0.tgz - package size: 147 B + package size: {size}, unpacked size: 55 B - shasum:{sha} - integrity:{sha} + shasum: {sha} + integrity: {sha} total files: 1 ), ], @@ -398,10 +398,10 @@ Array [ name: test-tar-package version: 1.0.0 filename: test-tar-package-1.0.0.tgz - package size: 218 B + package size: {size}, unpacked size: 124 B - shasum:{sha} - integrity:{sha} + shasum: {sha} + integrity: {sha} total files: 2 ), ], @@ -550,7 +550,7 @@ exports[`test/lib/commands/publish.js TAP workspaces json > all workspaces in js "id": "workspace-a@1.2.3-a", "name": "workspace-a", "version": "1.2.3-a", - "size": 162, + "size": {size}, "unpackedSize": 82, "shasum": "{sha}", "integrity": "{sha}", @@ -558,7 +558,7 @@ exports[`test/lib/commands/publish.js TAP workspaces json > all workspaces in js "files": [ { "path": "package.json", - "size": 82, + "size": {size}, "mode": 420 } ], @@ -569,7 +569,7 @@ exports[`test/lib/commands/publish.js TAP workspaces json > all workspaces in js "id": "workspace-b@1.2.3-n", "name": "workspace-b", "version": "1.2.3-n", - "size": 171, + "size": {size}, "unpackedSize": 92, "shasum": "{sha}", "integrity": "{sha}", @@ -577,7 +577,7 @@ exports[`test/lib/commands/publish.js TAP workspaces json > all workspaces in js "files": [ { "path": "package.json", - "size": 92, + "size": {size}, "mode": 420 } ], @@ -588,7 +588,7 @@ exports[`test/lib/commands/publish.js TAP workspaces json > all workspaces in js "id": "workspace-n@1.2.3-n", "name": "workspace-n", "version": "1.2.3-n", - "size": 140, + "size": {size}, "unpackedSize": 42, "shasum": "{sha}", "integrity": "{sha}", @@ -596,7 +596,7 @@ exports[`test/lib/commands/publish.js TAP workspaces json > all workspaces in js "files": [ { "path": "package.json", - "size": 42, + "size": {size}, "mode": 420 } ], diff --git a/test/fixtures/clean-snapshot.js b/test/fixtures/clean-snapshot.js index 83ddc00f4b787..53362ead0242c 100644 --- a/test/fixtures/clean-snapshot.js +++ b/test/fixtures/clean-snapshot.js @@ -33,11 +33,21 @@ const cleanDate = (str) => const cleanTime = str => str.replace(/in [0-9]+m?s\s*$/gm, 'in {TIME}') +const cleanZlib = str => str + .replace(/shasum:( *).*/g, 'shasum:$1{sha}') + .replace(/integrity:( *).*/g, 'integrity:$1{sha}') + .replace(/package size:( *).*/g, 'package size:$1{size},') + + .replace(/"shasum": ".*",/g, '"shasum": "{sha}",') + .replace(/"integrity": ".*",/g, '"integrity": "{sha}",') + .replace(/"size": [0-9]*,/g, '"size": {size},') + module.exports = { - normalizePath, - pathRegex, cleanCwd, cleanDate, - cleanTime, cleanNewlines, + cleanTime, + cleanZlib, + normalizePath, + pathRegex, } diff --git a/test/lib/commands/pack.js b/test/lib/commands/pack.js index 61296cc93a53a..7ed6569c46a76 100644 --- a/test/lib/commands/pack.js +++ b/test/lib/commands/pack.js @@ -3,6 +3,17 @@ const { load: loadMockNpm } = require('../../fixtures/mock-npm') const path = require('path') const fs = require('fs') +t.cleanSnapshot = data => { + return data + .replace(/shasum:( *).*/g, 'shasum:$1{sha}') + .replace(/integrity:( *).*/g, 'integrity:$1{sha}') + .replace(/package size:( *).*/g, 'package size:$1{size},') + + .replace(/"shasum": ".*",/g, '"shasum": "{sha}",') + .replace(/"integrity": ".*",/g, '"integrity": "{sha}",') + .replace(/"size": [0-9]*,/g, '"size": {size},') +} + t.test('should pack current directory with no arguments', async t => { const { npm, outputs, logs } = await loadMockNpm(t, { prefixDir: { diff --git a/test/lib/commands/publish.js b/test/lib/commands/publish.js index c10b380ca95e8..a5644ce224d67 100644 --- a/test/lib/commands/publish.js +++ b/test/lib/commands/publish.js @@ -1,5 +1,6 @@ const t = require('tap') const { load: loadMockNpm } = require('../../fixtures/mock-npm') +const { cleanZlib } = require('../../fixtures/clean-snapshot') const MockRegistry = require('@npmcli/mock-registry') const pacote = require('pacote') const Arborist = require('@npmcli/arborist') @@ -19,12 +20,7 @@ const pkgJson = { version: '1.0.0', } -t.cleanSnapshot = data => { - return data.replace(/shasum:.*/g, 'shasum:{sha}') - .replace(/integrity:.*/g, 'integrity:{sha}') - .replace(/"shasum": ".*",/g, '"shasum": "{sha}",') - .replace(/"integrity": ".*",/g, '"integrity": "{sha}",') -} +t.cleanSnapshot = data => cleanZlib(data) t.test('respects publishConfig.registry, runs appropriate scripts', async t => { const { npm, joinedOutput, prefix } = await loadMockNpm(t, {