Skip to content

Commit

Permalink
Add tests and snapshots for optional dep removal from prod
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulio96 committed Sep 8, 2024
1 parent 235d698 commit b707873
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
49 changes: 49 additions & 0 deletions workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -33087,6 +33087,55 @@ exports[`test/arborist/reify.js TAP save proper lockfile with bins when upgradin

exports[`test/arborist/reify.js TAP save-prod, with optional > must match snapshot 1`] = `
{"dependencies":{"abbrev":"^1.1.1"}}
`
exports[`test/arborist/reify.js TAP delete from prod, if optional dep is added > must match snapshot 1`] = `
{
"name": "tap-testdir-reify-delete-from-prod-if-optional-dep-is-added",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"optionalDependencies": {
"abbrev": "^1.1.1"
}
},
"node_modules/abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==",
"license": "ISC",
"optional": true
}
}
}

`

exports[`test/arborist/reify.js TAP keep in prod, if optional dep fails install > must match snapshot 1`] = `
{
"name": "tap-testdir-reify-keep-in-prod-if-optional-dep-fails-install",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"@isaacs/testing-fail-install": "*"
},
"optionalDependencies": {
"@isaacs/testing-fail-install": "^1.0.0"
}
},
"node_modules/@isaacs/testing-fail-install": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@isaacs/testing-fail-install/-/testing-fail-install-1.0.0.tgz",
"integrity": "sha512-MlK05L4wasrk2/fQqgCeR8s+1KE8LEfMI3ZzaGfR5Dyvgi4R8vQY0fvwYcvKh6cqrmMX7wORvGKi5YJn8LZ9bg==",
"hasInstallScript": true,
"license": "ISC",
"optional": true
}
}
}

`

exports[`test/arborist/reify.js TAP saveBundle > must match snapshot 1`] = `
Expand Down
31 changes: 31 additions & 0 deletions workspaces/arborist/test/arborist/reify.js
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,37 @@ t.test('save-prod, with optional', async t => {
t.matchSnapshot(fs.readFileSync(path + '/package.json', 'utf8'))
})

t.test('delete from prod, if optional dep is added', async t => {
// add to existing optional dep in lockfile
const pathNoSaveType = t.testdir({
'package.json': JSON.stringify({
optionalDependencies: { abbrev: '*' }

Check failure on line 1864 in workspaces/arborist/test/arborist/reify.js

View workflow job for this annotation

GitHub Actions / Lint

Missing trailing comma
}),
})
const arbNoSaveType = newArb({ path: pathNoSaveType })
await arbNoSaveType.reify({ add: ['abbrev'] })
const resultNoSaveType = fs.readFileSync(pathNoSaveType + '/package-lock.json', 'utf8')

// add to empty lockfile using optional saveType
const pathSaveType = t.testdir({ 'package.json': '{}' })
const arbSaveType = newArb({ path: pathSaveType })
await arbSaveType.reify({ add: ['abbrev'], saveType: 'optional' })
const resultSaveType = fs.readFileSync(pathSaveType + '/package-lock.json', 'utf8')

// both lockfiles should be the same
t.same(resultNoSaveType, resultSaveType)
t.matchSnapshot(resultNoSaveType)

Check failure on line 1879 in workspaces/arborist/test/arborist/reify.js

View workflow job for this annotation

GitHub Actions / Lint

Block must not be padded by blank lines

})

t.test('keep in prod, if optional dep fails install', async t => {
const path = t.testdir({ 'package.json': '{}' })
const arb = newArb({ path })

await arb.reify({ add: ['@isaacs/testing-fail-install'], saveType: 'optional' })
t.matchSnapshot(fs.readFileSync(path + '/package-lock.json', 'utf8'))
})

t.test('saveBundle', async t => {
const path = t.testdir({
'package.json': JSON.stringify({
Expand Down

0 comments on commit b707873

Please sign in to comment.