Skip to content

Commit

Permalink
chore: test refactor (#7262)
Browse files Browse the repository at this point in the history
Makes the install tests do less DI and more network mocking
  • Loading branch information
wraithgar committed Mar 5, 2024
1 parent 569f391 commit af3c48e
Show file tree
Hide file tree
Showing 2 changed files with 231 additions and 294 deletions.
78 changes: 78 additions & 0 deletions test/lib/arborist-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,81 @@ t.test('handle getWorkspaces raising an error', async t => {
{ message: 'oopsie' }
)
})

t.test('location detection and audit', async (t) => {
await t.test('audit false without package.json', async t => {
const { npm } = await loadMockNpm(t, {
command: 'install',
prefixDir: {
// no package.json
'readme.txt': 'just a file',
'other-dir': { a: 'a' },
},
})
t.equal(npm.config.get('location'), 'user')
t.equal(npm.config.get('audit'), false)
})

await t.test('audit true with package.json', async t => {
const { npm } = await loadMockNpm(t, {
command: 'install',
prefixDir: {
'package.json': '{ "name": "testpkg", "version": "1.0.0" }',
'readme.txt': 'just a file',
},
})
t.equal(npm.config.get('location'), 'user')
t.equal(npm.config.get('audit'), true)
})

await t.test('audit true without package.json when set', async t => {
const { npm } = await loadMockNpm(t, {
command: 'install',
prefixDir: {
// no package.json
'readme.txt': 'just a file',
'other-dir': { a: 'a' },
},
config: {
audit: true,
},
})
t.equal(npm.config.get('location'), 'user')
t.equal(npm.config.get('audit'), true)
})

await t.test('audit true in root config without package.json', async t => {
const { npm } = await loadMockNpm(t, {
command: 'install',
prefixDir: {
// no package.json
'readme.txt': 'just a file',
'other-dir': { a: 'a' },
},
// change npmRoot to get it to use a builtin rc file
otherDirs: { npmrc: 'audit=true' },
npm: ({ other }) => ({ npmRoot: other }),
})
t.equal(npm.config.get('location'), 'user')
t.equal(npm.config.get('audit'), true)
})

await t.test('test for warning when --global & --audit', async t => {
const { npm, logs } = await loadMockNpm(t, {
command: 'install',
prefixDir: {
// no package.json
'readme.txt': 'just a file',
'other-dir': { a: 'a' },
},
config: {
audit: true,
global: true,
},
})
t.equal(npm.config.get('location'), 'user')
t.equal(npm.config.get('audit'), true)
t.equal(logs.warn[0][0], 'config')
t.equal(logs.warn[0][1], 'includes both --global and --audit, which is currently unsupported.')
})
})
Loading

0 comments on commit af3c48e

Please sign in to comment.