Skip to content

Commit b21e11f

Browse files
committed
chore: fix init test to not mock package-json lib
1 parent ca78c74 commit b21e11f

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

test/lib/commands/init.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ const { cleanTime } = require('../../fixtures/clean-snapshot')
66

77
t.cleanSnapshot = cleanTime
88

9-
const mockNpm = async (t, { noLog, libnpmexec, initPackageJson, packageJson, ...opts } = {}) => {
9+
const mockNpm = async (t, { noLog, libnpmexec, initPackageJson, ...opts } = {}) => {
1010
const res = await _mockNpm(t, {
1111
...opts,
1212
mocks: {
1313
...(libnpmexec ? { libnpmexec } : {}),
1414
...(initPackageJson ? { 'init-package-json': initPackageJson } : {}),
15-
...(packageJson ? { '@npmcli/package-json': packageJson } : {}),
1615
},
1716
globals: {
1817
// init-package-json prints directly to console.log
@@ -313,23 +312,15 @@ t.test('workspaces', async t => {
313312
await t.test('fail parsing top-level package.json to set workspace', async t => {
314313
const { npm } = await mockNpm(t, {
315314
prefixDir: {
316-
'package.json': JSON.stringify({
317-
name: 'top-level',
318-
}),
319-
},
320-
packageJson: {
321-
async load () {
322-
throw new Error('ERR')
323-
},
315+
'package.json': 'not json['
324316
},
325317
config: { workspace: 'a', yes: true },
326318
noLog: true,
327319
})
328320

329321
await t.rejects(
330322
npm.exec('init', []),
331-
/ERR/,
332-
'should exit with error'
323+
{ code: 'EJSONPARSE' }
333324
)
334325
})
335326

0 commit comments

Comments
 (0)