Skip to content

Commit a530215

Browse files
committed
chore(smoke-tests): always return stdout and stderr from npm spawn
1 parent c4741fe commit a530215

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

smoke-tests/test/fixtures/setup.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ const testdirHelper = (obj) => {
4444
return obj
4545
}
4646

47-
const getNpmRoot = (helpText) => {
48-
return helpText
47+
const getNpmRoot = (r) => {
48+
return r.stdout
4949
.split('\n')
5050
.slice(-1)[0]
5151
.match(/^npm@.*?\s(.*)$/)
@@ -152,7 +152,6 @@ module.exports = async (t, { testdir = {}, debug, mockRegistry = true, useProxy
152152
const baseSpawn = async (spawnCmd, spawnArgs, {
153153
cwd = paths.project,
154154
env,
155-
stderr: _stderr,
156155
...opts } = {}
157156
) => {
158157
log(`CWD: ${cwd}`)
@@ -175,7 +174,7 @@ module.exports = async (t, { testdir = {}, debug, mockRegistry = true, useProxy
175174
log(stdout)
176175
log('='.repeat(40))
177176

178-
return _stderr ? { stderr, stdout } : stdout
177+
return { stderr, stdout }
179178
}
180179

181180
const baseNpm = async (...a) => {
@@ -255,7 +254,10 @@ module.exports = async (t, { testdir = {}, debug, mockRegistry = true, useProxy
255254
paths,
256255
registry,
257256
npmLocalTarball: async () => SMOKE_PUBLISH_TARBALL ??
258-
npmLocal('pack', `--pack-destination=${root}`).then(r => join(root, r)),
257+
npmLocal('pack', `--pack-destination=${root}`).then(r => {
258+
const output = r.stdout.trim().split('\n')
259+
return join(root, output[output.length - 1])
260+
}),
259261
}
260262
}
261263

smoke-tests/test/index.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ t.test('basic', async t => {
3737
await t.test('npm init', async t => {
3838
const cmdRes = await npm('init', '-y')
3939

40-
t.matchSnapshot(cmdRes, 'should have successful npm init result')
40+
t.matchSnapshot(cmdRes.stdout, 'should have successful npm init result')
4141
const pkg = await readFile('package.json')
4242
t.equal(pkg.name, 'project', 'should have expected generated name')
4343
t.equal(pkg.version, '1.0.0', 'should have expected generated version')
@@ -66,12 +66,12 @@ t.test('basic', async t => {
6666
})
6767

6868
await t.test('npm --version', async t => {
69-
const v = await npm('--version')
69+
const v = await npm('--version').then(r => r.stdout.trim())
7070

7171
if (setup.SMOKE_PUBLISH) {
72-
t.match(v.trim(), /-[0-9a-f]{40}\.\d$/, 'must have a git version')
72+
t.match(v, /-[0-9a-f]{40}\.\d$/, 'must have a git version')
7373
} else {
74-
t.match(v.trim(), /^\d+\.\d+\.\d+/, 'has a version')
74+
t.match(v, /^\d+\.\d+\.\d+/, 'has a version')
7575
}
7676
})
7777

@@ -92,7 +92,7 @@ t.test('basic', async t => {
9292

9393
const cmdRes = await npm('install', '[email protected]')
9494

95-
t.matchSnapshot(cmdRes, 'should have expected install reify output')
95+
t.matchSnapshot(cmdRes.stdout, 'should have expected install reify output')
9696
t.resolveMatchSnapshot(readFile('package.json'), 'should have expected package.json result')
9797
t.resolveMatchSnapshot(readFile('package-lock.json'), 'should have expected lockfile result')
9898
})
@@ -109,7 +109,7 @@ t.test('basic', async t => {
109109

110110
const cmdRes = await npm('install', 'promise-all-reject-late', '-D')
111111

112-
t.matchSnapshot(cmdRes, 'should have expected dev dep added reify output')
112+
t.matchSnapshot(cmdRes.stdout, 'should have expected dev dep added reify output')
113113
t.resolveMatchSnapshot(
114114
readFile('package.json'),
115115
'should have expected dev dep added package.json result'
@@ -123,19 +123,19 @@ t.test('basic', async t => {
123123
await t.test('npm ls', async t => {
124124
const cmdRes = await npm('ls')
125125

126-
t.matchSnapshot(cmdRes, 'should have expected ls output')
126+
t.matchSnapshot(cmdRes.stdout, 'should have expected ls output')
127127
})
128128

129129
await t.test('npm fund', async t => {
130130
const cmdRes = await npm('fund')
131131

132-
t.matchSnapshot(cmdRes, 'should have expected fund output')
132+
t.matchSnapshot(cmdRes.stdout, 'should have expected fund output')
133133
})
134134

135135
await t.test('npm explain', async t => {
136136
const cmdRes = await npm('explain', 'abbrev')
137137

138-
t.matchSnapshot(cmdRes, 'should have expected explain output')
138+
t.matchSnapshot(cmdRes.stdout, 'should have expected explain output')
139139
})
140140

141141
await t.test('npm diff', async t => {
@@ -151,7 +151,7 @@ t.test('basic', async t => {
151151

152152
const cmdRes = await npm('diff', '[email protected]', '[email protected]')
153153

154-
t.matchSnapshot(cmdRes, 'should have expected diff output')
154+
t.matchSnapshot(cmdRes.stdout, 'should have expected diff output')
155155
})
156156

157157
await t.test('npm outdated', async t => {
@@ -175,7 +175,7 @@ t.test('basic', async t => {
175175
await t.test('npm pkg set scripts', async t => {
176176
const cmdRes = await npm('pkg', 'set', 'scripts.hello=echo Hello')
177177

178-
t.matchSnapshot(cmdRes, 'should have expected set-script output')
178+
t.matchSnapshot(cmdRes.stdout, 'should have expected set-script output')
179179
t.resolveMatchSnapshot(
180180
readFile('package.json'),
181181
'should have expected script added package.json result'
@@ -185,13 +185,13 @@ t.test('basic', async t => {
185185
await t.test('npm run-script', async t => {
186186
const cmdRes = await npm('run', 'hello')
187187

188-
t.matchSnapshot(cmdRes, 'should have expected run-script output')
188+
t.matchSnapshot(cmdRes.stdout, 'should have expected run-script output')
189189
})
190190

191191
await t.test('npm prefix', async t => {
192192
const cmdRes = await npm('prefix')
193193

194-
t.matchSnapshot(cmdRes, 'should have expected prefix output')
194+
t.matchSnapshot(cmdRes.stdout, 'should have expected prefix output')
195195
})
196196

197197
await t.test('npm view', async t => {
@@ -200,7 +200,7 @@ t.test('basic', async t => {
200200
})
201201
const cmdRes = await npm('view', '[email protected]')
202202

203-
t.matchSnapshot(cmdRes, 'should have expected view output')
203+
t.matchSnapshot(cmdRes.stdout, 'should have expected view output')
204204
})
205205

206206
await t.test('npm update dep', async t => {
@@ -214,7 +214,7 @@ t.test('basic', async t => {
214214

215215
const cmdRes = await npm('update', 'abbrev')
216216

217-
t.matchSnapshot(cmdRes, 'should have expected update reify output')
217+
t.matchSnapshot(cmdRes.stdout, 'should have expected update reify output')
218218
t.resolveMatchSnapshot(readFile('package.json'),
219219
'should have expected update package.json result')
220220
t.resolveMatchSnapshot(readFile('package-lock.json'),
@@ -224,7 +224,7 @@ t.test('basic', async t => {
224224
await t.test('npm uninstall', async t => {
225225
const cmdRes = await npm('uninstall', 'promise-all-reject-late')
226226

227-
t.matchSnapshot(cmdRes, 'should have expected uninstall reify output')
227+
t.matchSnapshot(cmdRes.stdout, 'should have expected uninstall reify output')
228228
t.resolveMatchSnapshot(readFile('package.json'),
229229
'should have expected uninstall package.json result')
230230
t.resolveMatchSnapshot(readFile('package-lock.json'),
@@ -233,21 +233,21 @@ t.test('basic', async t => {
233233

234234
await t.test('npm pkg', async t => {
235235
let cmdRes = await npm('pkg', 'get', 'license')
236-
t.matchSnapshot(cmdRes, 'should have expected pkg get output')
236+
t.matchSnapshot(cmdRes.stdout, 'should have expected pkg get output')
237237

238238
cmdRes = await npm('pkg', 'set', 'tap[test-env][0]=LC_ALL=sk')
239-
t.matchSnapshot(cmdRes, 'should have expected pkg set output')
239+
t.matchSnapshot(cmdRes.stdout, 'should have expected pkg set output')
240240

241241
t.resolveMatchSnapshot(
242242
readFile('package.json'),
243243
'should have expected npm pkg set modified package.json result'
244244
)
245245

246246
cmdRes = await npm('pkg', 'get')
247-
t.matchSnapshot(cmdRes, 'should print package.json contents')
247+
t.matchSnapshot(cmdRes.stdout, 'should print package.json contents')
248248

249249
cmdRes = await npm('pkg', 'delete', 'tap')
250-
t.matchSnapshot(cmdRes, 'should have expected pkg delete output')
250+
t.matchSnapshot(cmdRes.stdout, 'should have expected pkg delete output')
251251

252252
t.resolveMatchSnapshot(
253253
readFile('package.json'),
@@ -385,7 +385,7 @@ t.test('basic', async t => {
385385
})
386386

387387
const o = await npm('exec', 'exec-test')
388-
t.match(o.trim(), '1.0.0')
388+
t.match(o.stdout.trim(), '1.0.0')
389389
}
390390
// Second run finds newer version
391391
{
@@ -401,7 +401,7 @@ t.test('basic', async t => {
401401
},
402402
})
403403
const o = await npm('exec', 'exec-test')
404-
t.match(o.trim(), '1.0.1')
404+
t.match(o.stdout.trim(), '1.0.1')
405405
}
406406
})
407407
})

0 commit comments

Comments
 (0)