Skip to content

Commit af3c48e

Browse files
authored
chore: test refactor (#7262)
Makes the install tests do less DI and more network mocking
1 parent 569f391 commit af3c48e

File tree

2 files changed

+231
-294
lines changed

2 files changed

+231
-294
lines changed

test/lib/arborist-cmd.js

+78
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,81 @@ t.test('handle getWorkspaces raising an error', async t => {
138138
{ message: 'oopsie' }
139139
)
140140
})
141+
142+
t.test('location detection and audit', async (t) => {
143+
await t.test('audit false without package.json', async t => {
144+
const { npm } = await loadMockNpm(t, {
145+
command: 'install',
146+
prefixDir: {
147+
// no package.json
148+
'readme.txt': 'just a file',
149+
'other-dir': { a: 'a' },
150+
},
151+
})
152+
t.equal(npm.config.get('location'), 'user')
153+
t.equal(npm.config.get('audit'), false)
154+
})
155+
156+
await t.test('audit true with package.json', async t => {
157+
const { npm } = await loadMockNpm(t, {
158+
command: 'install',
159+
prefixDir: {
160+
'package.json': '{ "name": "testpkg", "version": "1.0.0" }',
161+
'readme.txt': 'just a file',
162+
},
163+
})
164+
t.equal(npm.config.get('location'), 'user')
165+
t.equal(npm.config.get('audit'), true)
166+
})
167+
168+
await t.test('audit true without package.json when set', async t => {
169+
const { npm } = await loadMockNpm(t, {
170+
command: 'install',
171+
prefixDir: {
172+
// no package.json
173+
'readme.txt': 'just a file',
174+
'other-dir': { a: 'a' },
175+
},
176+
config: {
177+
audit: true,
178+
},
179+
})
180+
t.equal(npm.config.get('location'), 'user')
181+
t.equal(npm.config.get('audit'), true)
182+
})
183+
184+
await t.test('audit true in root config without package.json', async t => {
185+
const { npm } = await loadMockNpm(t, {
186+
command: 'install',
187+
prefixDir: {
188+
// no package.json
189+
'readme.txt': 'just a file',
190+
'other-dir': { a: 'a' },
191+
},
192+
// change npmRoot to get it to use a builtin rc file
193+
otherDirs: { npmrc: 'audit=true' },
194+
npm: ({ other }) => ({ npmRoot: other }),
195+
})
196+
t.equal(npm.config.get('location'), 'user')
197+
t.equal(npm.config.get('audit'), true)
198+
})
199+
200+
await t.test('test for warning when --global & --audit', async t => {
201+
const { npm, logs } = await loadMockNpm(t, {
202+
command: 'install',
203+
prefixDir: {
204+
// no package.json
205+
'readme.txt': 'just a file',
206+
'other-dir': { a: 'a' },
207+
},
208+
config: {
209+
audit: true,
210+
global: true,
211+
},
212+
})
213+
t.equal(npm.config.get('location'), 'user')
214+
t.equal(npm.config.get('audit'), true)
215+
t.equal(logs.warn[0][0], 'config')
216+
t.equal(logs.warn[0][1], 'includes both --global and --audit, which is currently unsupported.')
217+
})
218+
})

0 commit comments

Comments
 (0)