node/deps/npm/test/lib/commands/prune.js
npm CLI robot 36bcfa7913
deps: upgrade npm to 11.17.0
PR-URL: https://github.com/nodejs/node/pull/63857
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
2026-06-13 19:08:33 +00:00

48 lines
1.3 KiB
JavaScript

const t = require('tap')
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
t.test('should prune using Arborist', async (t) => {
t.plan(4)
const { npm } = await loadMockNpm(t, {
mocks: {
'@npmcli/arborist': function (args) {
t.ok(args, 'gets options object')
t.ok(args.path, 'gets path option')
this.prune = () => {
t.ok(true, 'prune is called')
}
},
'{LIB}/utils/reify-finish.js': (arb) => {
t.ok(arb, 'gets arborist tree')
},
},
})
await npm.exec('prune', [])
})
t.test('prune threads allowScripts policy through to arborist', async t => {
let capturedOpts
const FakeArborist = function (opts) {
capturedOpts = opts
this.options = opts
this.actualTree = { inventory: new Map() }
}
FakeArborist.prototype.prune = async () => {}
const { npm } = await loadMockNpm(t, {
prefixDir: {
'package.json': JSON.stringify({
name: 'host',
version: '1.0.0',
allowScripts: { canvas: true },
}),
},
mocks: {
'@npmcli/arborist': FakeArborist,
'{LIB}/utils/reify-finish.js': async () => {},
},
})
await npm.exec('prune', [])
t.strictSame(capturedOpts.allowScripts, { canvas: true },
'opts.allowScripts populated from package.json')
})