Skip to content

Commit

Permalink
chore: fix tests for zlib differences between node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Nov 30, 2023
1 parent 11ec231 commit 5642e75
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 43 deletions.
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: {sha}
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": "{sha}",
"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": "{sha}",
"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: {sha}
total files: 1
),
"",
Expand Down
40 changes: 20 additions & 20 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: {sha}
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}",
"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: {sha}
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: {sha}
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: {sha}
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}",
"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}",
"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}",
"filename": "workspace-n-1.2.3-n.tgz",
"files": [
{
"path": "package.json",
"size": 42,
"size": {size},
"mode": 420
}
],
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:( *).*/g, 'shasum:$1{sha}')

Check failure on line 37 in test/fixtures/clean-snapshot.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 2 spaces but found 4
.replace(/integrity:( *).*/g, 'integrity:$1{sha}')

Check failure on line 38 in test/fixtures/clean-snapshot.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 2 spaces but found 4
.replace(/package size:( *).*/g, 'package size:$1{size},')

Check failure on line 39 in test/fixtures/clean-snapshot.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 2 spaces but found 4

.replace(/"shasum": ".*",/g, '"shasum": "{sha}",')

Check failure on line 41 in test/fixtures/clean-snapshot.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 2 spaces but found 4
.replace(/"integrity": ".*",/g, '"integrity": "{sha}",')

Check failure on line 42 in test/fixtures/clean-snapshot.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 2 spaces but found 4
.replace(/"size": [0-9]*,/g, '"size": {size},')

Check failure on line 43 in test/fixtures/clean-snapshot.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 2 spaces but found 4

module.exports = {
normalizePath,
pathRegex,
cleanCwd,
cleanDate,
cleanTime,
cleanNewlines,
cleanTime,
cleanZlib,
normalizePath,
pathRegex,
}
11 changes: 11 additions & 0 deletions test/lib/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
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

0 comments on commit 5642e75

Please sign in to comment.