Skip to content

Commit 2d0eb9d

Browse files
committed
run-script snapshot tests
1 parent 85c6fbb commit 2d0eb9d

File tree

3 files changed

+290
-205
lines changed

3 files changed

+290
-205
lines changed

lib/commands/run-script.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,30 @@ class RunScript extends BaseCommand {
157157
}
158158

159159
const [cmds, runScripts] = scriptEntries.reduce((acc, s) => {
160-
acc[cmdList.includes(s) ? 0 : 1].push(s)
160+
acc[cmdList.includes(s[0]) ? 0 : 1].push(s)
161161
return acc
162162
}, [[], []])
163163

164164
const { reset, bold, green, dim, blue } = this.npm.chalk
165-
let pkgId = ` in ${green(_id || name)}`
165+
const inPkg = `in ${green(_id || name)}`
166166
const title = (t) => reset(bold(t))
167167

168168
if (cmds.length) {
169-
output.standard(`${title('Lifecycle scripts')} included${pkgId}:`)
169+
output.standard(`${title('Lifecycle scripts')} included ${inPkg}:`)
170170
for (const [k, v] of cmds) {
171171
output.standard(` ${k}`)
172172
output.standard(` ${dim(v)}`)
173173
}
174-
pkgId = ''
175174
}
176175

177176
if (runScripts.length) {
178-
output.standard(`${title('Scripts')} available${pkgId} via \`${blue('npm run-script')}\`:`)
177+
const via = `via \`${blue('npm run-script')}\`:`
178+
if (!cmds.length) {
179+
output.standard(`${title('Scripts')} available ${inPkg} ${via}`)
180+
} else {
181+
output.standard('')
182+
output.standard(`available ${via}`)
183+
}
179184
for (const [k, v] of runScripts) {
180185
output.standard(` ${k}`)
181186
output.standard(` ${dim(v)}`)
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
/* IMPORTANT
2+
* This snapshot file is auto-generated, but designed for humans.
3+
* It should be checked into source control and tracked carefully.
4+
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
5+
* Make sure to inspect the output below. Do not ignore changes!
6+
*/
7+
'use strict'
8+
exports[`test/lib/commands/run-script.js TAP list scripts no args > basic report 1`] = `
9+
Lifecycle scripts included in [email protected]:
10+
test
11+
exit 2
12+
start
13+
node server.js
14+
stop
15+
node kill-server.js
16+
17+
available via \`npm run-script\`:
18+
preenv
19+
echo before the env
20+
postenv
21+
echo after the env
22+
`
23+
24+
exports[`test/lib/commands/run-script.js TAP list scripts parseable > must match snapshot 1`] = `
25+
test:exit 2
26+
start:node server.js
27+
stop:node kill-server.js
28+
preenv:echo before the env
29+
postenv:echo after the env
30+
`
31+
32+
exports[`test/lib/commands/run-script.js TAP list scripts warn json > json report 1`] = `
33+
{
34+
test: 'exit 2',
35+
start: 'node server.js',
36+
stop: 'node kill-server.js',
37+
preenv: 'echo before the env',
38+
postenv: 'echo after the env'
39+
}
40+
`
41+
42+
exports[`test/lib/commands/run-script.js TAP list scripts, only commands > must match snapshot 1`] = `
43+
Lifecycle scripts included in [email protected]:
44+
preversion
45+
echo doing the version dance
46+
`
47+
48+
exports[`test/lib/commands/run-script.js TAP list scripts, only non-commands > must match snapshot 1`] = `
49+
Scripts available in [email protected] via \`npm run-script\`:
50+
glorp
51+
echo doing the glerp glop
52+
`
53+
54+
exports[`test/lib/commands/run-script.js TAP workspaces failed workspace run with succeeded runs > should log error msgs for each workspace script 1`] = `
55+
Lifecycle script \`glorp\` failed with error:
56+
Error: ERR
57+
in workspace: [email protected]
58+
at location: {CWD}/prefix/packages/a
59+
`
60+
61+
exports[`test/lib/commands/run-script.js TAP workspaces list all scripts --json > must match snapshot 1`] = `
62+
{ a: { glorp: 'echo a doing the glerp glop' } }
63+
{ b: { glorp: 'echo b doing the glerp glop' } }
64+
{
65+
c: { test: 'exit 0', posttest: 'echo posttest', lorem: 'echo c lorem' }
66+
}
67+
{ d: { test: 'exit 0', posttest: 'echo posttest' } }
68+
{ e: { test: 'exit 0', start: 'echo start something' } }
69+
{ noscripts: {} }
70+
`
71+
72+
exports[`test/lib/commands/run-script.js TAP workspaces list all scripts --parseable > must match snapshot 1`] = `
73+
a:glorp:echo a doing the glerp glop
74+
b:glorp:echo b doing the glerp glop
75+
c:test:exit 0
76+
c:posttest:echo posttest
77+
c:lorem:echo c lorem
78+
d:test:exit 0
79+
d:posttest:echo posttest
80+
e:test:exit 0
81+
e:start:echo start something
82+
`
83+
84+
exports[`test/lib/commands/run-script.js TAP workspaces list all scripts > must match snapshot 1`] = `
85+
Scripts available in [email protected] via \`npm run-script\`:
86+
glorp
87+
echo a doing the glerp glop
88+
89+
Scripts available in [email protected] via \`npm run-script\`:
90+
glorp
91+
echo b doing the glerp glop
92+
93+
Lifecycle scripts included in [email protected]:
94+
test
95+
exit 0
96+
posttest
97+
echo posttest
98+
99+
available via \`npm run-script\`:
100+
lorem
101+
echo c lorem
102+
103+
Lifecycle scripts included in [email protected]:
104+
test
105+
exit 0
106+
posttest
107+
echo posttest
108+
109+
Lifecycle scripts included in e:
110+
test
111+
exit 0
112+
start
113+
echo start something
114+
`
115+
116+
exports[`test/lib/commands/run-script.js TAP workspaces list all scripts with colors > must match snapshot 1`] = `
117+
Scripts available in [[email protected] via \`npm run-script\`:
118+
glorp
119+
echo a doing the glerp glop
120+
121+
Scripts available in [[email protected] via \`npm run-script\`:
122+
glorp
123+
echo b doing the glerp glop
124+
125+
Lifecycle scripts included in [[email protected]:
126+
test
127+
exit 0
128+
posttest
129+
echo posttest
130+
131+
available via \`npm run-script\`:
132+
lorem
133+
echo c lorem
134+
135+
Lifecycle scripts included in [[email protected]:
136+
test
137+
exit 0
138+
posttest
139+
echo posttest
140+
141+
Lifecycle scripts included in e:
142+
test
143+
exit 0
144+
start
145+
echo start something
146+
`
147+
148+
exports[`test/lib/commands/run-script.js TAP workspaces list regular scripts, filtered by name > must match snapshot 1`] = `
149+
Scripts available in [email protected] via \`npm run-script\`:
150+
glorp
151+
echo a doing the glerp glop
152+
153+
Scripts available in [email protected] via \`npm run-script\`:
154+
glorp
155+
echo b doing the glerp glop
156+
`
157+
158+
exports[`test/lib/commands/run-script.js TAP workspaces list regular scripts, filtered by parent folder > must match snapshot 1`] = `
159+
Scripts available in [email protected] via \`npm run-script\`:
160+
glorp
161+
echo a doing the glerp glop
162+
163+
Scripts available in [email protected] via \`npm run-script\`:
164+
glorp
165+
echo b doing the glerp glop
166+
167+
Lifecycle scripts included in [email protected]:
168+
test
169+
exit 0
170+
posttest
171+
echo posttest
172+
173+
available via \`npm run-script\`:
174+
lorem
175+
echo c lorem
176+
177+
Lifecycle scripts included in [email protected]:
178+
test
179+
exit 0
180+
posttest
181+
echo posttest
182+
183+
Lifecycle scripts included in e:
184+
test
185+
exit 0
186+
start
187+
echo start something
188+
`
189+
190+
exports[`test/lib/commands/run-script.js TAP workspaces list regular scripts, filtered by path > must match snapshot 1`] = `
191+
Scripts available in [email protected] via \`npm run-script\`:
192+
glorp
193+
echo a doing the glerp glop
194+
`
195+
196+
exports[`test/lib/commands/run-script.js TAP workspaces missing scripts in all workspaces > should log error msgs for each workspace script 1`] = `
197+
Lifecycle script \`missing-script\` failed with error:
198+
Error: Missing script: "missing-script"
199+
200+
To see a list of scripts, run:
201+
npm run
202+
in workspace: [email protected]
203+
at location: {CWD}/prefix/packages/a
204+
Lifecycle script \`missing-script\` failed with error:
205+
Error: Missing script: "missing-script"
206+
207+
To see a list of scripts, run:
208+
npm run
209+
in workspace: [email protected]
210+
at location: {CWD}/prefix/packages/b
211+
Lifecycle script \`missing-script\` failed with error:
212+
Error: Missing script: "missing-script"
213+
214+
To see a list of scripts, run:
215+
npm run
216+
in workspace: [email protected]
217+
at location: {CWD}/prefix/packages/c
218+
Lifecycle script \`missing-script\` failed with error:
219+
Error: Missing script: "missing-script"
220+
221+
To see a list of scripts, run:
222+
npm run
223+
in workspace: [email protected]
224+
at location: {CWD}/prefix/packages/d
225+
Lifecycle script \`missing-script\` failed with error:
226+
Error: Missing script: "missing-script"
227+
228+
To see a list of scripts, run:
229+
npm run
230+
in workspace: e
231+
at location: {CWD}/prefix/packages/e
232+
Lifecycle script \`missing-script\` failed with error:
233+
Error: Missing script: "missing-script"
234+
235+
To see a list of scripts, run:
236+
npm run
237+
in workspace: [email protected]
238+
at location: {CWD}/prefix/packages/noscripts
239+
`
240+
241+
exports[`test/lib/commands/run-script.js TAP workspaces missing scripts in some workspaces > should log error msgs for each workspace script 1`] = `
242+
Lifecycle script \`test\` failed with error:
243+
Error: Missing script: "test"
244+
245+
To see a list of scripts, run:
246+
npm run
247+
in workspace: [email protected]
248+
at location: {CWD}/prefix/packages/a
249+
Lifecycle script \`test\` failed with error:
250+
Error: Missing script: "test"
251+
252+
To see a list of scripts, run:
253+
npm run
254+
in workspace: [email protected]
255+
at location: {CWD}/prefix/packages/b
256+
`
257+
258+
exports[`test/lib/commands/run-script.js TAP workspaces single failed workspace run > should log error msgs for each workspace script 1`] = `
259+
Lifecycle script \`test\` failed with error:
260+
Error: err
261+
in workspace: [email protected]
262+
at location: {CWD}/prefix/packages/c
263+
`

0 commit comments

Comments
 (0)