11cb0ef41Sopenharmony_ciconst t = require('tap') 21cb0ef41Sopenharmony_ciconst { load: loadMockNpm } = require('../../fixtures/mock-npm') 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_cit.test('exec commands', async t => { 51cb0ef41Sopenharmony_ci await t.test('with args, dev=true', async t => { 61cb0ef41Sopenharmony_ci const SCRIPTS = [] 71cb0ef41Sopenharmony_ci let ARB_ARGS = null 81cb0ef41Sopenharmony_ci let REIFY_CALLED = false 91cb0ef41Sopenharmony_ci let ARB_OBJ = null 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t, { 121cb0ef41Sopenharmony_ci mocks: { 131cb0ef41Sopenharmony_ci '@npmcli/run-script': ({ event }) => { 141cb0ef41Sopenharmony_ci SCRIPTS.push(event) 151cb0ef41Sopenharmony_ci }, 161cb0ef41Sopenharmony_ci '@npmcli/arborist': function (args) { 171cb0ef41Sopenharmony_ci ARB_ARGS = args 181cb0ef41Sopenharmony_ci ARB_OBJ = this 191cb0ef41Sopenharmony_ci this.reify = () => { 201cb0ef41Sopenharmony_ci REIFY_CALLED = true 211cb0ef41Sopenharmony_ci } 221cb0ef41Sopenharmony_ci }, 231cb0ef41Sopenharmony_ci '{LIB}/utils/reify-finish.js': (_, arb) => { 241cb0ef41Sopenharmony_ci if (arb !== ARB_OBJ) { 251cb0ef41Sopenharmony_ci throw new Error('got wrong object passed to reify-finish') 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci }, 281cb0ef41Sopenharmony_ci }, 291cb0ef41Sopenharmony_ci config: { 301cb0ef41Sopenharmony_ci // This is here because CI calls tests with `--ignore-scripts`, which config 311cb0ef41Sopenharmony_ci // picks up from argv 321cb0ef41Sopenharmony_ci 'ignore-scripts': false, 331cb0ef41Sopenharmony_ci 'audit-level': 'low', 341cb0ef41Sopenharmony_ci dev: true, 351cb0ef41Sopenharmony_ci }, 361cb0ef41Sopenharmony_ci }) 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci await npm.exec('install', ['fizzbuzz']) 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci t.match( 411cb0ef41Sopenharmony_ci ARB_ARGS, 421cb0ef41Sopenharmony_ci { global: false, path: npm.prefix, auditLevel: null }, 431cb0ef41Sopenharmony_ci 'Arborist gets correct args and ignores auditLevel' 441cb0ef41Sopenharmony_ci ) 451cb0ef41Sopenharmony_ci t.equal(REIFY_CALLED, true, 'called reify') 461cb0ef41Sopenharmony_ci t.strictSame(SCRIPTS, [], 'no scripts when adding dep') 471cb0ef41Sopenharmony_ci }) 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci await t.test('without args', async t => { 501cb0ef41Sopenharmony_ci const SCRIPTS = [] 511cb0ef41Sopenharmony_ci let ARB_ARGS = null 521cb0ef41Sopenharmony_ci let REIFY_CALLED = false 531cb0ef41Sopenharmony_ci let ARB_OBJ = null 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t, { 561cb0ef41Sopenharmony_ci mocks: { 571cb0ef41Sopenharmony_ci '@npmcli/run-script': ({ event }) => { 581cb0ef41Sopenharmony_ci SCRIPTS.push(event) 591cb0ef41Sopenharmony_ci }, 601cb0ef41Sopenharmony_ci '@npmcli/arborist': function (args) { 611cb0ef41Sopenharmony_ci ARB_ARGS = args 621cb0ef41Sopenharmony_ci ARB_OBJ = this 631cb0ef41Sopenharmony_ci this.reify = () => { 641cb0ef41Sopenharmony_ci REIFY_CALLED = true 651cb0ef41Sopenharmony_ci } 661cb0ef41Sopenharmony_ci }, 671cb0ef41Sopenharmony_ci '{LIB}/utils/reify-finish.js': (_, arb) => { 681cb0ef41Sopenharmony_ci if (arb !== ARB_OBJ) { 691cb0ef41Sopenharmony_ci throw new Error('got wrong object passed to reify-finish') 701cb0ef41Sopenharmony_ci } 711cb0ef41Sopenharmony_ci }, 721cb0ef41Sopenharmony_ci }, 731cb0ef41Sopenharmony_ci config: { 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci }, 761cb0ef41Sopenharmony_ci }) 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci await npm.exec('install', []) 791cb0ef41Sopenharmony_ci t.match(ARB_ARGS, { global: false, path: npm.prefix }) 801cb0ef41Sopenharmony_ci t.equal(REIFY_CALLED, true, 'called reify') 811cb0ef41Sopenharmony_ci t.strictSame(SCRIPTS, [ 821cb0ef41Sopenharmony_ci 'preinstall', 831cb0ef41Sopenharmony_ci 'install', 841cb0ef41Sopenharmony_ci 'postinstall', 851cb0ef41Sopenharmony_ci 'prepublish', 861cb0ef41Sopenharmony_ci 'preprepare', 871cb0ef41Sopenharmony_ci 'prepare', 881cb0ef41Sopenharmony_ci 'postprepare', 891cb0ef41Sopenharmony_ci ], 'exec scripts when doing local build') 901cb0ef41Sopenharmony_ci }) 911cb0ef41Sopenharmony_ci 921cb0ef41Sopenharmony_ci await t.test('should ignore scripts with --ignore-scripts', async t => { 931cb0ef41Sopenharmony_ci const SCRIPTS = [] 941cb0ef41Sopenharmony_ci let REIFY_CALLED = false 951cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t, { 961cb0ef41Sopenharmony_ci mocks: { 971cb0ef41Sopenharmony_ci '{LIB}/utils/reify-finish.js': async () => {}, 981cb0ef41Sopenharmony_ci '@npmcli/run-script': ({ event }) => { 991cb0ef41Sopenharmony_ci SCRIPTS.push(event) 1001cb0ef41Sopenharmony_ci }, 1011cb0ef41Sopenharmony_ci '@npmcli/arborist': function () { 1021cb0ef41Sopenharmony_ci this.reify = () => { 1031cb0ef41Sopenharmony_ci REIFY_CALLED = true 1041cb0ef41Sopenharmony_ci } 1051cb0ef41Sopenharmony_ci }, 1061cb0ef41Sopenharmony_ci }, 1071cb0ef41Sopenharmony_ci config: { 1081cb0ef41Sopenharmony_ci 'ignore-scripts': true, 1091cb0ef41Sopenharmony_ci }, 1101cb0ef41Sopenharmony_ci }) 1111cb0ef41Sopenharmony_ci 1121cb0ef41Sopenharmony_ci await npm.exec('install', []) 1131cb0ef41Sopenharmony_ci t.equal(REIFY_CALLED, true, 'called reify') 1141cb0ef41Sopenharmony_ci t.strictSame(SCRIPTS, [], 'no scripts when adding dep') 1151cb0ef41Sopenharmony_ci }) 1161cb0ef41Sopenharmony_ci 1171cb0ef41Sopenharmony_ci await t.test('should install globally using Arborist', async t => { 1181cb0ef41Sopenharmony_ci const SCRIPTS = [] 1191cb0ef41Sopenharmony_ci let ARB_ARGS = null 1201cb0ef41Sopenharmony_ci let REIFY_CALLED 1211cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t, { 1221cb0ef41Sopenharmony_ci mocks: { 1231cb0ef41Sopenharmony_ci '@npmcli/run-script': ({ event }) => { 1241cb0ef41Sopenharmony_ci SCRIPTS.push(event) 1251cb0ef41Sopenharmony_ci }, 1261cb0ef41Sopenharmony_ci '{LIB}/utils/reify-finish.js': async () => {}, 1271cb0ef41Sopenharmony_ci '@npmcli/arborist': function (args) { 1281cb0ef41Sopenharmony_ci ARB_ARGS = args 1291cb0ef41Sopenharmony_ci this.reify = () => { 1301cb0ef41Sopenharmony_ci REIFY_CALLED = true 1311cb0ef41Sopenharmony_ci } 1321cb0ef41Sopenharmony_ci }, 1331cb0ef41Sopenharmony_ci }, 1341cb0ef41Sopenharmony_ci config: { 1351cb0ef41Sopenharmony_ci global: true, 1361cb0ef41Sopenharmony_ci }, 1371cb0ef41Sopenharmony_ci }) 1381cb0ef41Sopenharmony_ci await npm.exec('install', []) 1391cb0ef41Sopenharmony_ci t.match( 1401cb0ef41Sopenharmony_ci ARB_ARGS, 1411cb0ef41Sopenharmony_ci { global: true, path: npm.globalPrefix } 1421cb0ef41Sopenharmony_ci ) 1431cb0ef41Sopenharmony_ci t.equal(REIFY_CALLED, true, 'called reify') 1441cb0ef41Sopenharmony_ci t.strictSame(SCRIPTS, [], 'no scripts when installing globally') 1451cb0ef41Sopenharmony_ci t.notOk(npm.config.get('audit', 'cli')) 1461cb0ef41Sopenharmony_ci }) 1471cb0ef41Sopenharmony_ci 1481cb0ef41Sopenharmony_ci await t.test('should not install invalid global package name', async t => { 1491cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t, { 1501cb0ef41Sopenharmony_ci mocks: { 1511cb0ef41Sopenharmony_ci '@npmcli/run-script': () => {}, 1521cb0ef41Sopenharmony_ci '{LIB}/utils/reify-finish.js': async () => {}, 1531cb0ef41Sopenharmony_ci '@npmcli/arborist': function (args) { 1541cb0ef41Sopenharmony_ci throw new Error('should not reify') 1551cb0ef41Sopenharmony_ci }, 1561cb0ef41Sopenharmony_ci }, 1571cb0ef41Sopenharmony_ci config: { 1581cb0ef41Sopenharmony_ci global: true, 1591cb0ef41Sopenharmony_ci }, 1601cb0ef41Sopenharmony_ci }) 1611cb0ef41Sopenharmony_ci await t.rejects( 1621cb0ef41Sopenharmony_ci npm.exec('install', ['']), 1631cb0ef41Sopenharmony_ci /Usage:/, 1641cb0ef41Sopenharmony_ci 'should not install invalid package name' 1651cb0ef41Sopenharmony_ci ) 1661cb0ef41Sopenharmony_ci }) 1671cb0ef41Sopenharmony_ci 1681cb0ef41Sopenharmony_ci await t.test('npm i -g npm engines check success', async t => { 1691cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t, { 1701cb0ef41Sopenharmony_ci mocks: { 1711cb0ef41Sopenharmony_ci '{LIB}/utils/reify-finish.js': async () => {}, 1721cb0ef41Sopenharmony_ci '@npmcli/arborist': function () { 1731cb0ef41Sopenharmony_ci this.reify = () => {} 1741cb0ef41Sopenharmony_ci }, 1751cb0ef41Sopenharmony_ci pacote: { 1761cb0ef41Sopenharmony_ci manifest: () => { 1771cb0ef41Sopenharmony_ci return { 1781cb0ef41Sopenharmony_ci version: '100.100.100', 1791cb0ef41Sopenharmony_ci engines: { 1801cb0ef41Sopenharmony_ci node: '>1', 1811cb0ef41Sopenharmony_ci }, 1821cb0ef41Sopenharmony_ci } 1831cb0ef41Sopenharmony_ci }, 1841cb0ef41Sopenharmony_ci }, 1851cb0ef41Sopenharmony_ci }, 1861cb0ef41Sopenharmony_ci config: { 1871cb0ef41Sopenharmony_ci global: true, 1881cb0ef41Sopenharmony_ci }, 1891cb0ef41Sopenharmony_ci }) 1901cb0ef41Sopenharmony_ci await npm.exec('install', ['npm']) 1911cb0ef41Sopenharmony_ci t.ok('No exceptions happen') 1921cb0ef41Sopenharmony_ci }) 1931cb0ef41Sopenharmony_ci 1941cb0ef41Sopenharmony_ci await t.test('npm i -g npm engines check failure', async t => { 1951cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t, { 1961cb0ef41Sopenharmony_ci mocks: { 1971cb0ef41Sopenharmony_ci pacote: { 1981cb0ef41Sopenharmony_ci manifest: () => { 1991cb0ef41Sopenharmony_ci return { 2001cb0ef41Sopenharmony_ci _id: 'npm@1.2.3', 2011cb0ef41Sopenharmony_ci version: '100.100.100', 2021cb0ef41Sopenharmony_ci engines: { 2031cb0ef41Sopenharmony_ci node: '>1000', 2041cb0ef41Sopenharmony_ci }, 2051cb0ef41Sopenharmony_ci } 2061cb0ef41Sopenharmony_ci }, 2071cb0ef41Sopenharmony_ci }, 2081cb0ef41Sopenharmony_ci }, 2091cb0ef41Sopenharmony_ci config: { 2101cb0ef41Sopenharmony_ci global: true, 2111cb0ef41Sopenharmony_ci }, 2121cb0ef41Sopenharmony_ci }) 2131cb0ef41Sopenharmony_ci await t.rejects( 2141cb0ef41Sopenharmony_ci npm.exec('install', ['npm']), 2151cb0ef41Sopenharmony_ci { 2161cb0ef41Sopenharmony_ci message: 'Unsupported engine', 2171cb0ef41Sopenharmony_ci pkgid: 'npm@1.2.3', 2181cb0ef41Sopenharmony_ci current: { 2191cb0ef41Sopenharmony_ci node: process.version, 2201cb0ef41Sopenharmony_ci npm: '100.100.100', 2211cb0ef41Sopenharmony_ci }, 2221cb0ef41Sopenharmony_ci required: { 2231cb0ef41Sopenharmony_ci node: '>1000', 2241cb0ef41Sopenharmony_ci }, 2251cb0ef41Sopenharmony_ci code: 'EBADENGINE', 2261cb0ef41Sopenharmony_ci } 2271cb0ef41Sopenharmony_ci ) 2281cb0ef41Sopenharmony_ci }) 2291cb0ef41Sopenharmony_ci 2301cb0ef41Sopenharmony_ci await t.test('npm i -g npm engines check failure forced override', async t => { 2311cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t, { 2321cb0ef41Sopenharmony_ci mocks: { 2331cb0ef41Sopenharmony_ci '{LIB}/utils/reify-finish.js': async () => {}, 2341cb0ef41Sopenharmony_ci '@npmcli/arborist': function () { 2351cb0ef41Sopenharmony_ci this.reify = () => {} 2361cb0ef41Sopenharmony_ci }, 2371cb0ef41Sopenharmony_ci pacote: { 2381cb0ef41Sopenharmony_ci manifest: () => { 2391cb0ef41Sopenharmony_ci return { 2401cb0ef41Sopenharmony_ci _id: 'npm@1.2.3', 2411cb0ef41Sopenharmony_ci version: '100.100.100', 2421cb0ef41Sopenharmony_ci engines: { 2431cb0ef41Sopenharmony_ci node: '>1000', 2441cb0ef41Sopenharmony_ci }, 2451cb0ef41Sopenharmony_ci } 2461cb0ef41Sopenharmony_ci }, 2471cb0ef41Sopenharmony_ci }, 2481cb0ef41Sopenharmony_ci }, 2491cb0ef41Sopenharmony_ci config: { 2501cb0ef41Sopenharmony_ci global: true, 2511cb0ef41Sopenharmony_ci force: true, 2521cb0ef41Sopenharmony_ci }, 2531cb0ef41Sopenharmony_ci }) 2541cb0ef41Sopenharmony_ci await npm.exec('install', ['npm']) 2551cb0ef41Sopenharmony_ci t.ok('Does not throw') 2561cb0ef41Sopenharmony_ci }) 2571cb0ef41Sopenharmony_ci 2581cb0ef41Sopenharmony_ci await t.test('npm i -g npm@version engines check failure', async t => { 2591cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t, { 2601cb0ef41Sopenharmony_ci mocks: { 2611cb0ef41Sopenharmony_ci '{LIB}/utils/reify-finish.js': async () => {}, 2621cb0ef41Sopenharmony_ci '@npmcli/arborist': function () { 2631cb0ef41Sopenharmony_ci this.reify = () => {} 2641cb0ef41Sopenharmony_ci }, 2651cb0ef41Sopenharmony_ci pacote: { 2661cb0ef41Sopenharmony_ci manifest: () => { 2671cb0ef41Sopenharmony_ci return { 2681cb0ef41Sopenharmony_ci _id: 'npm@1.2.3', 2691cb0ef41Sopenharmony_ci version: '100.100.100', 2701cb0ef41Sopenharmony_ci engines: { 2711cb0ef41Sopenharmony_ci node: '>1000', 2721cb0ef41Sopenharmony_ci }, 2731cb0ef41Sopenharmony_ci } 2741cb0ef41Sopenharmony_ci }, 2751cb0ef41Sopenharmony_ci }, 2761cb0ef41Sopenharmony_ci }, 2771cb0ef41Sopenharmony_ci config: { 2781cb0ef41Sopenharmony_ci global: true, 2791cb0ef41Sopenharmony_ci }, 2801cb0ef41Sopenharmony_ci }) 2811cb0ef41Sopenharmony_ci await t.rejects( 2821cb0ef41Sopenharmony_ci npm.exec('install', ['npm@100']), 2831cb0ef41Sopenharmony_ci { 2841cb0ef41Sopenharmony_ci message: 'Unsupported engine', 2851cb0ef41Sopenharmony_ci pkgid: 'npm@1.2.3', 2861cb0ef41Sopenharmony_ci current: { 2871cb0ef41Sopenharmony_ci node: process.version, 2881cb0ef41Sopenharmony_ci npm: '100.100.100', 2891cb0ef41Sopenharmony_ci }, 2901cb0ef41Sopenharmony_ci required: { 2911cb0ef41Sopenharmony_ci node: '>1000', 2921cb0ef41Sopenharmony_ci }, 2931cb0ef41Sopenharmony_ci code: 'EBADENGINE', 2941cb0ef41Sopenharmony_ci } 2951cb0ef41Sopenharmony_ci ) 2961cb0ef41Sopenharmony_ci }) 2971cb0ef41Sopenharmony_ci}) 2981cb0ef41Sopenharmony_ci 2991cb0ef41Sopenharmony_cit.test('completion', async t => { 3001cb0ef41Sopenharmony_ci const mockComp = async (t, { noChdir } = {}) => loadMockNpm(t, { 3011cb0ef41Sopenharmony_ci command: 'install', 3021cb0ef41Sopenharmony_ci prefixDir: { 3031cb0ef41Sopenharmony_ci arborist: { 3041cb0ef41Sopenharmony_ci 'package.json': '{}', 3051cb0ef41Sopenharmony_ci }, 3061cb0ef41Sopenharmony_ci 'arborist.txt': 'just a file', 3071cb0ef41Sopenharmony_ci 'other-dir': { a: 'a' }, 3081cb0ef41Sopenharmony_ci }, 3091cb0ef41Sopenharmony_ci ...(noChdir ? { chdir: false } : {}), 3101cb0ef41Sopenharmony_ci }) 3111cb0ef41Sopenharmony_ci 3121cb0ef41Sopenharmony_ci await t.test('completion to folder - has a match', async t => { 3131cb0ef41Sopenharmony_ci const { install } = await mockComp(t) 3141cb0ef41Sopenharmony_ci const res = await install.completion({ partialWord: './ar' }) 3151cb0ef41Sopenharmony_ci t.strictSame(res, ['arborist'], 'package dir match') 3161cb0ef41Sopenharmony_ci }) 3171cb0ef41Sopenharmony_ci 3181cb0ef41Sopenharmony_ci await t.test('completion to folder - invalid dir', async t => { 3191cb0ef41Sopenharmony_ci const { install } = await mockComp(t, { noChdir: true }) 3201cb0ef41Sopenharmony_ci const res = await install.completion({ partialWord: '/does/not/exist' }) 3211cb0ef41Sopenharmony_ci t.strictSame(res, [], 'invalid dir: no matching') 3221cb0ef41Sopenharmony_ci }) 3231cb0ef41Sopenharmony_ci 3241cb0ef41Sopenharmony_ci await t.test('completion to folder - no matches', async t => { 3251cb0ef41Sopenharmony_ci const { install } = await mockComp(t) 3261cb0ef41Sopenharmony_ci const res = await install.completion({ partialWord: './pa' }) 3271cb0ef41Sopenharmony_ci t.strictSame(res, [], 'no name match') 3281cb0ef41Sopenharmony_ci }) 3291cb0ef41Sopenharmony_ci 3301cb0ef41Sopenharmony_ci await t.test('completion to folder - match is not a package', async t => { 3311cb0ef41Sopenharmony_ci const { install } = await mockComp(t) 3321cb0ef41Sopenharmony_ci const res = await install.completion({ partialWord: './othe' }) 3331cb0ef41Sopenharmony_ci t.strictSame(res, [], 'no name match') 3341cb0ef41Sopenharmony_ci }) 3351cb0ef41Sopenharmony_ci 3361cb0ef41Sopenharmony_ci await t.test('completion to url', async t => { 3371cb0ef41Sopenharmony_ci const { install } = await mockComp(t) 3381cb0ef41Sopenharmony_ci const res = await install.completion({ partialWord: 'http://path/to/url' }) 3391cb0ef41Sopenharmony_ci t.strictSame(res, []) 3401cb0ef41Sopenharmony_ci }) 3411cb0ef41Sopenharmony_ci 3421cb0ef41Sopenharmony_ci await t.test('no /', async t => { 3431cb0ef41Sopenharmony_ci const { install } = await mockComp(t) 3441cb0ef41Sopenharmony_ci const res = await install.completion({ partialWord: 'toto' }) 3451cb0ef41Sopenharmony_ci t.notOk(res) 3461cb0ef41Sopenharmony_ci }) 3471cb0ef41Sopenharmony_ci 3481cb0ef41Sopenharmony_ci await t.test('only /', async t => { 3491cb0ef41Sopenharmony_ci const { install } = await mockComp(t) 3501cb0ef41Sopenharmony_ci const res = await install.completion({ partialWord: '/' }) 3511cb0ef41Sopenharmony_ci t.strictSame(res, []) 3521cb0ef41Sopenharmony_ci }) 3531cb0ef41Sopenharmony_ci}) 3541cb0ef41Sopenharmony_ci 3551cb0ef41Sopenharmony_cit.test('location detection and audit', async (t) => { 3561cb0ef41Sopenharmony_ci await t.test('audit false without package.json', async t => { 3571cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t, { 3581cb0ef41Sopenharmony_ci command: 'install', 3591cb0ef41Sopenharmony_ci prefixDir: { 3601cb0ef41Sopenharmony_ci // no package.json 3611cb0ef41Sopenharmony_ci 'readme.txt': 'just a file', 3621cb0ef41Sopenharmony_ci 'other-dir': { a: 'a' }, 3631cb0ef41Sopenharmony_ci }, 3641cb0ef41Sopenharmony_ci }) 3651cb0ef41Sopenharmony_ci t.equal(npm.config.get('location'), 'user') 3661cb0ef41Sopenharmony_ci t.equal(npm.config.get('audit'), false) 3671cb0ef41Sopenharmony_ci }) 3681cb0ef41Sopenharmony_ci 3691cb0ef41Sopenharmony_ci await t.test('audit true with package.json', async t => { 3701cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t, { 3711cb0ef41Sopenharmony_ci command: 'install', 3721cb0ef41Sopenharmony_ci prefixDir: { 3731cb0ef41Sopenharmony_ci 'package.json': '{ "name": "testpkg", "version": "1.0.0" }', 3741cb0ef41Sopenharmony_ci 'readme.txt': 'just a file', 3751cb0ef41Sopenharmony_ci }, 3761cb0ef41Sopenharmony_ci }) 3771cb0ef41Sopenharmony_ci t.equal(npm.config.get('location'), 'user') 3781cb0ef41Sopenharmony_ci t.equal(npm.config.get('audit'), true) 3791cb0ef41Sopenharmony_ci }) 3801cb0ef41Sopenharmony_ci 3811cb0ef41Sopenharmony_ci await t.test('audit true without package.json when set', async t => { 3821cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t, { 3831cb0ef41Sopenharmony_ci command: 'install', 3841cb0ef41Sopenharmony_ci prefixDir: { 3851cb0ef41Sopenharmony_ci // no package.json 3861cb0ef41Sopenharmony_ci 'readme.txt': 'just a file', 3871cb0ef41Sopenharmony_ci 'other-dir': { a: 'a' }, 3881cb0ef41Sopenharmony_ci }, 3891cb0ef41Sopenharmony_ci config: { 3901cb0ef41Sopenharmony_ci audit: true, 3911cb0ef41Sopenharmony_ci }, 3921cb0ef41Sopenharmony_ci }) 3931cb0ef41Sopenharmony_ci t.equal(npm.config.get('location'), 'user') 3941cb0ef41Sopenharmony_ci t.equal(npm.config.get('audit'), true) 3951cb0ef41Sopenharmony_ci }) 3961cb0ef41Sopenharmony_ci 3971cb0ef41Sopenharmony_ci await t.test('audit true in root config without package.json', async t => { 3981cb0ef41Sopenharmony_ci const { npm } = await loadMockNpm(t, { 3991cb0ef41Sopenharmony_ci command: 'install', 4001cb0ef41Sopenharmony_ci prefixDir: { 4011cb0ef41Sopenharmony_ci // no package.json 4021cb0ef41Sopenharmony_ci 'readme.txt': 'just a file', 4031cb0ef41Sopenharmony_ci 'other-dir': { a: 'a' }, 4041cb0ef41Sopenharmony_ci }, 4051cb0ef41Sopenharmony_ci // change npmRoot to get it to use a builtin rc file 4061cb0ef41Sopenharmony_ci otherDirs: { npmrc: 'audit=true' }, 4071cb0ef41Sopenharmony_ci npm: ({ other }) => ({ npmRoot: other }), 4081cb0ef41Sopenharmony_ci }) 4091cb0ef41Sopenharmony_ci t.equal(npm.config.get('location'), 'user') 4101cb0ef41Sopenharmony_ci t.equal(npm.config.get('audit'), true) 4111cb0ef41Sopenharmony_ci }) 4121cb0ef41Sopenharmony_ci 4131cb0ef41Sopenharmony_ci await t.test('test for warning when --global & --audit', async t => { 4141cb0ef41Sopenharmony_ci const { npm, logs } = await loadMockNpm(t, { 4151cb0ef41Sopenharmony_ci command: 'install', 4161cb0ef41Sopenharmony_ci prefixDir: { 4171cb0ef41Sopenharmony_ci // no package.json 4181cb0ef41Sopenharmony_ci 'readme.txt': 'just a file', 4191cb0ef41Sopenharmony_ci 'other-dir': { a: 'a' }, 4201cb0ef41Sopenharmony_ci }, 4211cb0ef41Sopenharmony_ci config: { 4221cb0ef41Sopenharmony_ci audit: true, 4231cb0ef41Sopenharmony_ci global: true, 4241cb0ef41Sopenharmony_ci }, 4251cb0ef41Sopenharmony_ci }) 4261cb0ef41Sopenharmony_ci t.equal(npm.config.get('location'), 'user') 4271cb0ef41Sopenharmony_ci t.equal(npm.config.get('audit'), true) 4281cb0ef41Sopenharmony_ci t.equal(logs.warn[0][0], 'config') 4291cb0ef41Sopenharmony_ci t.equal(logs.warn[0][1], 'includes both --global and --audit, which is currently unsupported.') 4301cb0ef41Sopenharmony_ci }) 4311cb0ef41Sopenharmony_ci}) 432