forked from npm/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-script.js
More file actions
140 lines (121 loc) · 2.9 KB
/
run-script.js
File metadata and controls
140 lines (121 loc) · 2.9 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const t = require('tap')
const baseOpts = {
args: [],
call: '',
color: false,
flatOptions: {},
path: '',
runPath: '',
shell: process.platform === 'win32'
? process.env.ComSpec || 'cmd'
: process.env.SHELL || 'sh',
}
t.test('disable, enable log progress', t => {
t.plan(3)
const path = t.testdir({
'package.json': JSON.stringify({
name: 'pkg',
}),
})
const runScript = t.mock('../lib/run-script.js', {
'ci-info': { isCI: false },
'@npmcli/run-script': async () => {
t.ok('should call run-script')
},
'../lib/no-tty.js': () => false,
npmlog: {
disableProgress () {
t.ok('should disable progress')
},
enableProgress () {
t.ok('should enable progress')
},
},
})
runScript({
...baseOpts,
path,
})
})
t.test('no package.json', t => {
t.plan(1)
const runScript = t.mock('../lib/run-script.js', {
'ci-info': { isCI: false },
'@npmcli/run-script': async () => {
t.ok('should call run-script')
},
'../lib/no-tty.js': () => false,
})
runScript(baseOpts)
})
t.test('colorized interactive mode msg', async t => {
t.plan(2)
const runScript = t.mock('../lib/run-script.js', {
'ci-info': { isCI: false },
'@npmcli/run-script': async () => {
t.ok('should call run-script')
},
'../lib/no-tty.js': () => false,
})
const OUTPUT = []
await runScript({
...baseOpts,
output: msg => {
OUTPUT.push(msg)
},
runPath: '/foo/',
flatOptions: { color: true },
})
t.matchSnapshot(OUTPUT.join('\n'), 'should print colorized output')
})
t.test('no color interactive mode msg', async t => {
t.plan(2)
const runScript = t.mock('../lib/run-script.js', {
'ci-info': { isCI: false },
'@npmcli/run-script': async () => {
t.ok('should call run-script')
},
'../lib/no-tty.js': () => false,
})
const OUTPUT = []
await runScript({
...baseOpts,
output: msg => {
OUTPUT.push(msg)
},
runPath: '/foo/',
})
t.matchSnapshot(OUTPUT.join('\n'), 'should print non-colorized output')
})
t.test('no tty', t => {
t.plan(1)
const runScript = t.mock('../lib/run-script.js', {
'ci-info': { isCI: false },
'@npmcli/run-script': async () => {
t.ok('should call run-script')
},
'../lib/no-tty.js': () => true,
})
runScript(baseOpts)
})
t.test('ci env', t => {
t.plan(2)
const runScript = t.mock('../lib/run-script.js', {
'ci-info': { isCI: true },
'@npmcli/run-script': async () => {
throw new Error('should not call run-script')
},
'../lib/no-tty.js': () => false,
'proc-log': {
warn (title, msg) {
t.equal(title, 'exec', 'should have expected title')
t.equal(
msg,
'Interactive mode disabled in CI environment',
'should have expected ci environment message'
)
},
},
})
runScript({ ...baseOpts })
})