Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix tests for zlib differences between node versions #7040

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions tap-snapshots/test/lib/commands/pack.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {integrity}
total files: 1
),
"",
Expand All @@ -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": "{integrity}",
"name": "test-package",
"shasum": "a92a0679a70a450f14f98a468756948a679e4107",
"size": 136,
"shasum": "{sha}",
"size": "{size}",
"unpackedSize": 41,
"version": "1.0.0",
},
Expand All @@ -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": "{integrity}",
"name": "@myscope/test-package",
"shasum": "7e6eb2e1ca46bed6b8fa8e144e0fcd1b22fe2d98",
"size": 145,
"shasum": "{sha}",
"size": "{size}",
"unpackedSize": 50,
"version": "1.0.0",
},
Expand All @@ -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: {integrity}
total files: 1
),
"",
Expand Down
48 changes: 24 additions & 24 deletions tap-snapshots/test/lib/commands/publish.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {integrity}
total files: 1
),
],
Expand Down Expand Up @@ -82,15 +82,15 @@ 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}",
"integrity": "{integrity}",
"filename": "test-package-1.0.0.tgz",
"files": [
{
"path": "package.json",
"size": 87,
"size": "{size}",
"mode": 420
}
],
Expand Down Expand Up @@ -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: {integrity}
total files: 1
),
],
Expand Down Expand Up @@ -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: {integrity}
total files: 1
),
],
Expand Down Expand Up @@ -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: {integrity}
total files: 2
),
],
Expand Down Expand Up @@ -550,15 +550,15 @@ 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}",
"integrity": "{integrity}",
"filename": "workspace-a-1.2.3-a.tgz",
"files": [
{
"path": "package.json",
"size": 82,
"size": "{size}",
"mode": 420
}
],
Expand All @@ -569,15 +569,15 @@ 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}",
"integrity": "{integrity}",
"filename": "workspace-b-1.2.3-n.tgz",
"files": [
{
"path": "package.json",
"size": 92,
"size": "{size}",
"mode": 420
}
],
Expand All @@ -588,15 +588,15 @@ 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}",
"integrity": "{integrity}",
"filename": "workspace-n-1.2.3-n.tgz",
"files": [
{
"path": "package.json",
"size": 42,
"size": "{size}",
"mode": 420
}
],
Expand Down
12 changes: 6 additions & 6 deletions tap-snapshots/test/lib/utils/tar.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ bundle-dep
name: my-cool-pkg
version: 1.0.0
filename: my-cool-pkg-1.0.0.tgz
package size: 271 B
package size: {size}
unpacked size: 126 B
shasum: 23e31c8ad422f96301c07730e61ff403b10306f1
integrity: sha512-/Lg5tEGQv5A5y[...]gq8T9D5+Wat1A==
shasum: {sha}
integrity: {integrity}
bundled deps: 1
bundled files: 0
own files: 5
Expand All @@ -53,10 +53,10 @@ bundle-dep
name: @myscope/my-cool-pkg
version: 1.0.0
filename: myscope-my-cool-pkg-1.0.0.tgz
package size: 280 B
package size: {size}
unpacked size: 135 B
shasum: a4f63307f2211e8fde72cd39bc1176b4fe997b71
integrity: sha512-b+RavF8JiErJt[...]YpwkJc8ycaabA==
shasum: {sha}
integrity: {integrity}
bundled deps: 1
bundled files: 0
own files: 5
Expand Down
16 changes: 13 additions & 3 deletions test/fixtures/clean-snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:( *)[0-9a-f]{40}/g, 'shasum:$1{sha}')
.replace(/integrity:( *).*/g, 'integrity:$1{integrity}')
.replace(/package size:( *)[0-9 A-Z]*/g, 'package size:$1{size}')

.replace(/"shasum": "[0-9a-f]{40}",/g, '"shasum": "{sha}",')
.replace(/"integrity": ".*",/g, '"integrity": "{integrity}",')
.replace(/"size": [0-9]*,/g, '"size": "{size}",')

module.exports = {
normalizePath,
pathRegex,
cleanCwd,
cleanDate,
cleanTime,
cleanNewlines,
cleanTime,
cleanZlib,
normalizePath,
pathRegex,
}
3 changes: 3 additions & 0 deletions test/lib/commands/pack.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const t = require('tap')
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
const { cleanZlib } = require('../../fixtures/clean-snapshot')
const path = require('path')
const fs = require('fs')

t.cleanSnapshot = data => cleanZlib(data)

t.test('should pack current directory with no arguments', async t => {
const { npm, outputs, logs } = await loadMockNpm(t, {
prefixDir: {
Expand Down
8 changes: 2 additions & 6 deletions test/lib/commands/publish.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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, {
Expand Down
8 changes: 6 additions & 2 deletions test/lib/utils/tar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ const t = require('tap')
const pack = require('libnpmpack')
const ssri = require('ssri')
const tmock = require('../../fixtures/tmock')
const { cleanZlib } = require('../../fixtures/clean-snapshot')

const { getContents } = require('../../../lib/utils/tar.js')
t.cleanSnapshot = data => cleanZlib(data)

const mockTar = ({ notice }) => tmock(t, '{LIB}/utils/tar.js', {
'proc-log': {
Expand Down Expand Up @@ -121,13 +123,15 @@ t.test('should getContents of a tarball', async (t) => {
algorithms: ['sha1', 'sha512'],
})

// zlib is nondeterministic
t.match(tarballContents.shasum, /^[0-9a-f]{40}$/)
delete tarballContents.shasum
t.strictSame(tarballContents, {
id: 'my-cool-pkg@1.0.0',
name: 'my-cool-pkg',
version: '1.0.0',
size: 146,
size: tarball.length,
unpackedSize: 49,
shasum: 'b8379c5e69693cdda73aec3d81dae1d11c1e75bd',
integrity: ssri.parse(integrity.sha512[0]),
filename: 'my-cool-pkg-1.0.0.tgz',
files: [{ path: 'package.json', size: 49, mode: 420 }],
Expand Down