-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-interrupt.js
58 lines (46 loc) · 1.4 KB
/
init-interrupt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* eslint-disable standard/no-callback-literal */
// if 'npm init' is interrupted with ^C, don't report
// 'init written successfully'
var test = require('tap').test
var path = require('path')
var osenv = require('osenv')
var rimraf = require('rimraf')
var npmlog = require('npmlog')
var requireInject = require('require-inject')
var npm = require('../../lib/npm.js')
var PKG_DIR = path.resolve(__dirname, 'init-interrupt')
test('setup', function (t) {
cleanup()
t.end()
})
test('issue #6684 remove confusing message', function (t) {
var initJsonMock = function (dir, input, config, cb) {
process.nextTick(function () {
cb({ message: 'canceled' })
})
}
initJsonMock.yes = function () { return true }
npm.load({ loglevel: 'silent' }, function () {
var log = ''
var init = requireInject('../../lib/init', {
'init-package-json': initJsonMock
})
// capture log messages
npmlog.on('log', function (chunk) { log += chunk.message + '\n' })
init([], function (err, code) {
t.ifError(err, 'init ran successfully')
t.notOk(code, 'exited without issue')
t.notSimilar(log, /written successfully/, 'no success message written')
t.similar(log, /canceled/, 'alerted that init was canceled')
t.end()
})
})
})
test('cleanup', function (t) {
cleanup()
t.end()
})
function cleanup () {
process.chdir(osenv.tmpdir())
rimraf.sync(PKG_DIR)
}