Skip to content

Commit

Permalink
fixup! lib/init.js test shenanigans
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed May 28, 2021
1 parent 996248c commit 6a96cf1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ class Init extends BaseCommand {
log,
globalBin,
} = this.npm
// this function is definitely called. But because of coverage map stuff
// it ends up both uncovered, and the coverage report doesn't even mention.
// the tests do assert that some output happens, so we know this line is
// being hit.
/* istanbul ignore next */
const output = (...outputArgs) => this.npm.output(...outputArgs)
const locationMsg = await getLocationMsg({ color, path })
const runPath = path
Expand Down
17 changes: 16 additions & 1 deletion tap-snapshots/test/lib/init.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@
*/
'use strict'
exports[`test/lib/init.js TAP workspaces no args > should print helper info 1`] = `
Array []
Array [
Array [
String(
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See \`npm help init\` for definitive documentation on these fields
and exactly what they do.
Use \`npm install <pkg>\` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
),
],
]
`

exports[`test/lib/init.js TAP workspaces no args, existing folder > should print helper info 1`] = `
Expand Down
10 changes: 9 additions & 1 deletion test/lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ t.afterEach(() => {
config.package = undefined
npm.log = npmLog
process.chdir(_cwd)
npm._mockOutputs.length = 0
console.log = _consolelog
})

Expand Down Expand Up @@ -318,6 +317,9 @@ t.test('npm init error', t => {

t.test('workspaces', t => {
t.test('no args', t => {
t.teardown(() => {
npm._mockOutputs.length = 0
})
npm.localPrefix = t.testdir({
'package.json': JSON.stringify({
name: 'top-level',
Expand All @@ -342,6 +344,9 @@ t.test('workspaces', t => {
})

t.test('no args, existing folder', t => {
t.teardown(() => {
npm._mockOutputs.length = 0
})
// init-package-json prints directly to console.log
// this avoids poluting test output with those logs
console.log = noop
Expand Down Expand Up @@ -371,6 +376,9 @@ t.test('workspaces', t => {
})

t.test('with arg but missing workspace folder', t => {
t.teardown(() => {
npm._mockOutputs.length = 0
})
// init-package-json prints directly to console.log
// this avoids poluting test output with those logs
console.log = noop
Expand Down

0 comments on commit 6a96cf1

Please sign in to comment.