You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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: #3329
Credit: @wraithgarClose: #3329
Reviewed-by: @ruyadorno
Copy file name to clipboardExpand all lines: test/lib/exec.js
+10-12Lines changed: 10 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,6 @@
1
1
constt=require('tap')
2
2
constmockNpm=require('../fixtures/mock-npm')
3
3
const{ resolve, delimiter }=require('path')
4
-
constOUTPUT=[]
5
-
constoutput=(...msg)=>OUTPUT.push(msg)
6
4
7
5
constARB_CTOR=[]
8
6
constARB_ACTUAL_TREE={}
@@ -36,6 +34,7 @@ const config = {
36
34
package: [],
37
35
'script-shell': 'shell-cmd',
38
36
}
37
+
39
38
constnpm=mockNpm({
40
39
flatOptions,
41
40
config,
@@ -53,7 +52,6 @@ const npm = mockNpm({
53
52
LOG_WARN.push(args)
54
53
},
55
54
},
56
-
output,
57
55
})
58
56
59
57
constRUN_SCRIPTS=[]
@@ -225,7 +223,7 @@ t.test('npm exec <noargs>, run interactive shell', t => {
225
223
ARB_CTOR.length=0
226
224
MKDIRPS.length=0
227
225
ARB_REIFY.length=0
228
-
OUTPUT.length=0
226
+
npm._mockOutputs.length=0
229
227
exec.exec([],er=>{
230
228
if(er)
231
229
thrower
@@ -256,7 +254,7 @@ t.test('npm exec <noargs>, run interactive shell', t => {
256
254
process.stdin.isTTY=true
257
255
run(t,true,()=>{
258
256
t.strictSame(LOG_WARN,[])
259
-
t.strictSame(OUTPUT,[
257
+
t.strictSame(npm._mockOutputs,[
260
258
[`\nEntering npm script environment at location:\n${process.cwd()}\nType 'exit' or ^D when finished\n`],
261
259
],'printed message about interactive shell')
262
260
t.end()
@@ -270,7 +268,7 @@ t.test('npm exec <noargs>, run interactive shell', t => {
270
268
271
269
run(t,true,()=>{
272
270
t.strictSame(LOG_WARN,[])
273
-
t.strictSame(OUTPUT,[
271
+
t.strictSame(npm._mockOutputs,[
274
272
[`\u001b[0m\u001b[0m\n\u001b[0mEntering npm script environment\u001b[0m\u001b[0m at location:\u001b[0m\n\u001b[0m\u001b[2m${process.cwd()}\u001b[22m\u001b[0m\u001b[1m\u001b[22m\n\u001b[1mType 'exit' or ^D when finished\u001b[22m\n\u001b[1m\u001b[22m`],
275
273
],'printed message about interactive shell')
276
274
t.end()
@@ -282,7 +280,7 @@ t.test('npm exec <noargs>, run interactive shell', t => {
282
280
process.stdin.isTTY=false
283
281
run(t,true,()=>{
284
282
t.strictSame(LOG_WARN,[])
285
-
t.strictSame(OUTPUT,[],'no message about interactive shell')
283
+
t.strictSame(npm._mockOutputs,[],'no message about interactive shell')
286
284
t.end()
287
285
})
288
286
})
@@ -294,7 +292,7 @@ t.test('npm exec <noargs>, run interactive shell', t => {
294
292
t.strictSame(LOG_WARN,[
295
293
['exec','Interactive mode disabled in CI environment'],
296
294
])
297
-
t.strictSame(OUTPUT,[],'no message about interactive shell')
295
+
t.strictSame(npm._mockOutputs,[],'no message about interactive shell')
298
296
t.end()
299
297
})
300
298
})
@@ -316,7 +314,7 @@ t.test('npm exec <noargs>, run interactive shell', t => {
316
314
ARB_CTOR.length=0
317
315
MKDIRPS.length=0
318
316
ARB_REIFY.length=0
319
-
OUTPUT.length=0
317
+
npm._mockOutputs.length=0
320
318
RUN_SCRIPTS.length=0
321
319
t.end()
322
320
})
@@ -1195,22 +1193,22 @@ t.test('workspaces', t => {
1195
1193
returnrej(er)
1196
1194
1197
1195
t.strictSame(LOG_WARN,[])
1198
-
t.strictSame(OUTPUT,[
1196
+
t.strictSame(npm._mockOutputs,[
1199
1197
[`\nEntering npm script environment in workspace a@1.0.0 at location:\n${resolve(npm.localPrefix,'packages/a')}\nType 'exit' or ^D when finished\n`],
1200
1198
],'printed message about interactive shell')
1201
1199
res()
1202
1200
})
1203
1201
})
1204
1202
1205
1203
config.color=true
1206
-
OUTPUT.length=0
1204
+
npm._mockOutputs.length=0
1207
1205
awaitnewPromise((res,rej)=>{
1208
1206
exec.execWorkspaces([],['a'],er=>{
1209
1207
if(er)
1210
1208
returnrej(er)
1211
1209
1212
1210
t.strictSame(LOG_WARN,[])
1213
-
t.strictSame(OUTPUT,[
1211
+
t.strictSame(npm._mockOutputs,[
1214
1212
[`\u001b[0m\u001b[0m\n\u001b[0mEntering npm script environment\u001b[0m\u001b[0m in workspace \u001b[32ma@1.0.0\u001b[39m at location:\u001b[0m\n\u001b[0m\u001b[2m${resolve(npm.localPrefix,'packages/a')}\u001b[22m\u001b[0m\u001b[1m\u001b[22m\n\u001b[1mType 'exit' or ^D when finished\u001b[22m\n\u001b[1m\u001b[22m`],
0 commit comments