Skip to content

Commit b707873

Browse files
committed
Add tests and snapshots for optional dep removal from prod
1 parent 235d698 commit b707873

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

workspaces/arborist/tap-snapshots/test/arborist/reify.js.test.cjs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33087,6 +33087,55 @@ exports[`test/arborist/reify.js TAP save proper lockfile with bins when upgradin
3308733087

3308833088
exports[`test/arborist/reify.js TAP save-prod, with optional > must match snapshot 1`] = `
3308933089
{"dependencies":{"abbrev":"^1.1.1"}}
33090+
`
33091+
exports[`test/arborist/reify.js TAP delete from prod, if optional dep is added > must match snapshot 1`] = `
33092+
{
33093+
"name": "tap-testdir-reify-delete-from-prod-if-optional-dep-is-added",
33094+
"lockfileVersion": 3,
33095+
"requires": true,
33096+
"packages": {
33097+
"": {
33098+
"optionalDependencies": {
33099+
"abbrev": "^1.1.1"
33100+
}
33101+
},
33102+
"node_modules/abbrev": {
33103+
"version": "1.1.1",
33104+
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
33105+
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==",
33106+
"license": "ISC",
33107+
"optional": true
33108+
}
33109+
}
33110+
}
33111+
33112+
`
33113+
33114+
exports[`test/arborist/reify.js TAP keep in prod, if optional dep fails install > must match snapshot 1`] = `
33115+
{
33116+
"name": "tap-testdir-reify-keep-in-prod-if-optional-dep-fails-install",
33117+
"lockfileVersion": 3,
33118+
"requires": true,
33119+
"packages": {
33120+
"": {
33121+
"dependencies": {
33122+
"@isaacs/testing-fail-install": "*"
33123+
},
33124+
"optionalDependencies": {
33125+
"@isaacs/testing-fail-install": "^1.0.0"
33126+
}
33127+
},
33128+
"node_modules/@isaacs/testing-fail-install": {
33129+
"version": "1.0.0",
33130+
"resolved": "https://registry.npmjs.org/@isaacs/testing-fail-install/-/testing-fail-install-1.0.0.tgz",
33131+
"integrity": "sha512-MlK05L4wasrk2/fQqgCeR8s+1KE8LEfMI3ZzaGfR5Dyvgi4R8vQY0fvwYcvKh6cqrmMX7wORvGKi5YJn8LZ9bg==",
33132+
"hasInstallScript": true,
33133+
"license": "ISC",
33134+
"optional": true
33135+
}
33136+
}
33137+
}
33138+
3309033139
`
3309133140

3309233141
exports[`test/arborist/reify.js TAP saveBundle > must match snapshot 1`] = `

workspaces/arborist/test/arborist/reify.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,6 +1857,37 @@ t.test('save-prod, with optional', async t => {
18571857
t.matchSnapshot(fs.readFileSync(path + '/package.json', 'utf8'))
18581858
})
18591859

1860+
t.test('delete from prod, if optional dep is added', async t => {
1861+
// add to existing optional dep in lockfile
1862+
const pathNoSaveType = t.testdir({
1863+
'package.json': JSON.stringify({
1864+
optionalDependencies: { abbrev: '*' }
1865+
}),
1866+
})
1867+
const arbNoSaveType = newArb({ path: pathNoSaveType })
1868+
await arbNoSaveType.reify({ add: ['abbrev'] })
1869+
const resultNoSaveType = fs.readFileSync(pathNoSaveType + '/package-lock.json', 'utf8')
1870+
1871+
// add to empty lockfile using optional saveType
1872+
const pathSaveType = t.testdir({ 'package.json': '{}' })
1873+
const arbSaveType = newArb({ path: pathSaveType })
1874+
await arbSaveType.reify({ add: ['abbrev'], saveType: 'optional' })
1875+
const resultSaveType = fs.readFileSync(pathSaveType + '/package-lock.json', 'utf8')
1876+
1877+
// both lockfiles should be the same
1878+
t.same(resultNoSaveType, resultSaveType)
1879+
t.matchSnapshot(resultNoSaveType)
1880+
1881+
})
1882+
1883+
t.test('keep in prod, if optional dep fails install', async t => {
1884+
const path = t.testdir({ 'package.json': '{}' })
1885+
const arb = newArb({ path })
1886+
1887+
await arb.reify({ add: ['@isaacs/testing-fail-install'], saveType: 'optional' })
1888+
t.matchSnapshot(fs.readFileSync(path + '/package-lock.json', 'utf8'))
1889+
})
1890+
18601891
t.test('saveBundle', async t => {
18611892
const path = t.testdir({
18621893
'package.json': JSON.stringify({

0 commit comments

Comments
 (0)