diff options
author | Gar <gar+gh@danger.computer> | 2021-05-28 19:23:49 +0300 |
---|---|---|
committer | Ruy Adorno <ruyadorno@hotmail.com> | 2021-06-01 01:21:04 +0300 |
commit | 598a17a2671c9e3bc204dddd6488169c9a72c6a1 (patch) | |
tree | 8784ad00c789fb0d8741b9e8317c8a0ee4b5fbcc /test/lib/init.js | |
parent | c4fc03e9eb3a6386e8feacb67c19f0a1578dfe38 (diff) |
fix(libnpmexec): don't detach output from npm
The npm output function refers to this.log. libnpmexec has that passed
in, which decoupled the function from the npm object. This fixes it,
and sets the tests up in a way where if the output function ever becomes
detached from this.npm in the same way, tests will fail.
PR-URL: https://github.com/npm/cli/pull/3329
Credit: @wraithgar
Close: #3329
Reviewed-by: @ruyadorno
Diffstat (limited to 'test/lib/init.js')
-rw-r--r-- | test/lib/init.js | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/test/lib/init.js b/test/lib/init.js index 0964bb5ce..268b170cb 100644 --- a/test/lib/init.js +++ b/test/lib/init.js @@ -3,7 +3,6 @@ const { resolve } = require('path') const t = require('tap') const mockNpm = require('../fixtures/mock-npm') -let result = '' const npmLog = { disableProgress: () => null, enableProgress: () => null, @@ -19,9 +18,6 @@ const config = { const npm = mockNpm({ config, log: npmLog, - output: (...msg) => { - result += msg.join('\n') - }, }) const mocks = { '../../lib/utils/usage.js': () => 'usage instructions', @@ -33,7 +29,6 @@ const _consolelog = console.log const noop = () => {} t.afterEach(() => { - result = '' config.yes = true config.package = undefined npm.log = npmLog @@ -322,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', @@ -340,12 +338,15 @@ t.test('workspaces', t => { if (err) throw err - t.matchSnapshot(result, 'should print helper info') + t.matchSnapshot(npm._mockOutputs, 'should print helper info') t.end() }) }) 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 @@ -369,12 +370,15 @@ t.test('workspaces', t => { if (err) throw err - t.matchSnapshot(result, 'should print helper info') + t.matchSnapshot(npm._mockOutputs, 'should print helper info') t.end() }) }) 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 @@ -401,7 +405,7 @@ t.test('workspaces', t => { if (err) throw err - t.matchSnapshot(result, 'should print helper info') + t.matchSnapshot(npm._mockOutputs, 'should print helper info') t.end() }) }) |