Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornlf <quitlahok@gmail.com>2020-12-14 22:11:59 +0300
committernlf <quitlahok@gmail.com>2020-12-15 22:16:37 +0300
commitb4f686e4b3d3dfa443df8e33c8d2d2ca4ee91360 (patch)
tree456cbdf24b5bf51d5aed79f54fa5b9265b8f8904 /test
parent3a6dd511c944c5f2699825a99bba1dde333a45ef (diff)
refactor editor dependency out of lib/config
Diffstat (limited to 'test')
-rw-r--r--test/lib/config.js44
1 files changed, 22 insertions, 22 deletions
diff --git a/test/lib/config.js b/test/lib/config.js
index 8a11a40c8..74cd530c6 100644
--- a/test/lib/config.js
+++ b/test/lib/config.js
@@ -1,5 +1,6 @@
const t = require('tap')
const requireInject = require('require-inject')
+const { EventEmitter } = require('events')
const redactCwd = (path) => {
const normalizePath = p => p
@@ -437,10 +438,16 @@ sign-git-commit=true`
cb()
},
},
- editor: (file, { editor }, cb) => {
- t.equal(file, '~/.npmrc', 'should match user source data')
- t.equal(editor, 'vi', 'should use default editor')
- cb()
+ child_process: {
+ spawn: (bin, args) => {
+ t.equal(bin, 'vi', 'should use default editor')
+ t.strictSame(args, ['~/.npmrc'], 'should match user source data')
+ const ee = new EventEmitter()
+ process.nextTick(() => {
+ ee.emit('exit', 0)
+ })
+ return ee
+ },
},
}
const config = requireInject('../../lib/config.js', editMocks)
@@ -487,15 +494,21 @@ t.test('config edit --global', t => {
cb()
},
},
- editor: (file, { editor }, cb) => {
- t.equal(file, '/etc/npmrc', 'should match global source data')
- t.equal(editor, 'vi', 'should use default editor')
- cb()
+ child_process: {
+ spawn: (bin, args, cb) => {
+ t.equal(bin, 'vi', 'should use default editor')
+ t.strictSame(args, ['/etc/npmrc'], 'should match global source data')
+ const ee = new EventEmitter()
+ process.nextTick(() => {
+ ee.emit('exit', 137)
+ })
+ return ee
+ },
},
}
const config = requireInject('../../lib/config.js', editMocks)
config(['edit'], (err) => {
- t.ifError(err, 'npm config edit --global')
+ t.match(err, /exited with code: 137/, 'propagated exit code from editor')
})
t.teardown(() => {
@@ -505,19 +518,6 @@ t.test('config edit --global', t => {
})
})
-t.test('config edit no editor set', t => {
- flatOptions.editor = undefined
- config(['edit'], (err) => {
- t.match(
- err,
- /No `editor` config or EDITOR environment variable set/,
- 'should throw no available editor error'
- )
- flatOptions.editor = 'vi'
- t.end()
- })
-})
-
t.test('completion', t => {
const { completion } = config