Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: test refactor #7262

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading