1
1
'use strict' ;
2
2
3
3
const common = require ( '../common' ) ;
4
+ common . requireNoPackageJSONAbove ( ) ;
5
+
4
6
const { it, describe } = require ( 'node:test' ) ;
5
7
const assert = require ( 'node:assert' ) ;
6
8
@@ -15,7 +17,6 @@ describe('node --run [command]', () => {
15
17
{ cwd : __dirname } ,
16
18
) ;
17
19
assert . match ( child . stderr , / E x p e r i m e n t a l W a r n i n g : T a s k r u n n e r i s a n e x p e r i m e n t a l f e a t u r e a n d m i g h t c h a n g e a t a n y t i m e / ) ;
18
- assert . match ( child . stderr , / C a n ' t r e a d p a c k a g e \. j s o n / ) ;
19
20
assert . strictEqual ( child . stdout , '' ) ;
20
21
assert . strictEqual ( child . code , 1 ) ;
21
22
} ) ;
@@ -26,7 +27,9 @@ describe('node --run [command]', () => {
26
27
[ '--no-warnings' , '--run' , 'test' ] ,
27
28
{ cwd : __dirname } ,
28
29
) ;
29
- assert . match ( child . stderr , / C a n ' t r e a d p a c k a g e \. j s o n / ) ;
30
+ assert . match ( child . stderr , / C a n ' t f i n d p a c k a g e \. j s o n [ \s \S ] * / ) ;
31
+ // Ensure we show the path that starting path for the search
32
+ assert ( child . stderr . includes ( __dirname ) ) ;
30
33
assert . strictEqual ( child . stdout , '' ) ;
31
34
assert . strictEqual ( child . code , 1 ) ;
32
35
} ) ;
@@ -53,6 +56,101 @@ describe('node --run [command]', () => {
53
56
assert . strictEqual ( child . code , 0 ) ;
54
57
} ) ;
55
58
59
+ it ( 'chdirs into package directory' , async ( ) => {
60
+ const child = await common . spawnPromisified (
61
+ process . execPath ,
62
+ [ '--no-warnings' , '--run' , `pwd${ envSuffix } ` ] ,
63
+ { cwd : fixtures . path ( 'run-script/sub-directory' ) } ,
64
+ ) ;
65
+ assert . strictEqual ( child . stdout . trim ( ) , fixtures . path ( 'run-script' ) ) ;
66
+ assert . strictEqual ( child . stderr , '' ) ;
67
+ assert . strictEqual ( child . code , 0 ) ;
68
+ } ) ;
69
+
70
+ it ( 'includes actionable info when possible' , async ( ) => {
71
+ {
72
+ const child = await common . spawnPromisified (
73
+ process . execPath ,
74
+ [ '--no-warnings' , '--run' , 'missing' ] ,
75
+ { cwd : fixtures . path ( 'run-script' ) } ,
76
+ ) ;
77
+ assert . strictEqual ( child . stdout , '' ) ;
78
+ assert ( child . stderr . includes ( fixtures . path ( 'run-script/package.json' ) ) ) ;
79
+ assert ( child . stderr . includes ( 'no test specified' ) ) ;
80
+ assert . strictEqual ( child . code , 1 ) ;
81
+ }
82
+ {
83
+ const child = await common . spawnPromisified (
84
+ process . execPath ,
85
+ [ '--no-warnings' , '--run' , 'test' ] ,
86
+ { cwd : fixtures . path ( 'run-script/missing-scripts' ) } ,
87
+ ) ;
88
+ assert . strictEqual ( child . stdout , '' ) ;
89
+ assert ( child . stderr . includes ( fixtures . path ( 'run-script/missing-scripts/package.json' ) ) ) ;
90
+ assert . strictEqual ( child . code , 1 ) ;
91
+ }
92
+ {
93
+ const child = await common . spawnPromisified (
94
+ process . execPath ,
95
+ [ '--no-warnings' , '--run' , 'test' ] ,
96
+ { cwd : fixtures . path ( 'run-script/invalid-json' ) } ,
97
+ ) ;
98
+ assert . strictEqual ( child . stdout , '' ) ;
99
+ assert ( child . stderr . includes ( fixtures . path ( 'run-script/invalid-json/package.json' ) ) ) ;
100
+ assert . strictEqual ( child . code , 1 ) ;
101
+ }
102
+ {
103
+ const child = await common . spawnPromisified (
104
+ process . execPath ,
105
+ [ '--no-warnings' , '--run' , 'array' ] ,
106
+ { cwd : fixtures . path ( 'run-script/invalid-schema' ) } ,
107
+ ) ;
108
+ assert . strictEqual ( child . stdout , '' ) ;
109
+ assert ( child . stderr . includes ( fixtures . path ( 'run-script/invalid-schema/package.json' ) ) ) ;
110
+ assert . strictEqual ( child . code , 1 ) ;
111
+ }
112
+ {
113
+ const child = await common . spawnPromisified (
114
+ process . execPath ,
115
+ [ '--no-warnings' , '--run' , 'boolean' ] ,
116
+ { cwd : fixtures . path ( 'run-script/invalid-schema' ) } ,
117
+ ) ;
118
+ assert . strictEqual ( child . stdout , '' ) ;
119
+ assert ( child . stderr . includes ( fixtures . path ( 'run-script/invalid-schema/package.json' ) ) ) ;
120
+ assert . strictEqual ( child . code , 1 ) ;
121
+ }
122
+ {
123
+ const child = await common . spawnPromisified (
124
+ process . execPath ,
125
+ [ '--no-warnings' , '--run' , 'null' ] ,
126
+ { cwd : fixtures . path ( 'run-script/invalid-schema' ) } ,
127
+ ) ;
128
+ assert . strictEqual ( child . stdout , '' ) ;
129
+ assert ( child . stderr . includes ( fixtures . path ( 'run-script/invalid-schema/package.json' ) ) ) ;
130
+ assert . strictEqual ( child . code , 1 ) ;
131
+ }
132
+ {
133
+ const child = await common . spawnPromisified (
134
+ process . execPath ,
135
+ [ '--no-warnings' , '--run' , 'number' ] ,
136
+ { cwd : fixtures . path ( 'run-script/invalid-schema' ) } ,
137
+ ) ;
138
+ assert . strictEqual ( child . stdout , '' ) ;
139
+ assert ( child . stderr . includes ( fixtures . path ( 'run-script/invalid-schema/package.json' ) ) ) ;
140
+ assert . strictEqual ( child . code , 1 ) ;
141
+ }
142
+ {
143
+ const child = await common . spawnPromisified (
144
+ process . execPath ,
145
+ [ '--no-warnings' , '--run' , 'object' ] ,
146
+ { cwd : fixtures . path ( 'run-script/invalid-schema' ) } ,
147
+ ) ;
148
+ assert . strictEqual ( child . stdout , '' ) ;
149
+ assert ( child . stderr . includes ( fixtures . path ( 'run-script/invalid-schema/package.json' ) ) ) ;
150
+ assert . strictEqual ( child . code , 1 ) ;
151
+ }
152
+ } ) ;
153
+
56
154
it ( 'appends positional arguments' , async ( ) => {
57
155
const child = await common . spawnPromisified (
58
156
process . execPath ,
@@ -120,7 +218,7 @@ describe('node --run [command]', () => {
120
218
[ '--no-warnings' , '--run' , 'test' ] ,
121
219
{ cwd : fixtures . path ( 'run-script/cannot-parse' ) } ,
122
220
) ;
123
- assert . match ( child . stderr , / C a n ' t p a r s e p a c k a g e \. j s o n / ) ;
221
+ assert . match ( child . stderr , / C a n ' t p a r s e / ) ;
124
222
assert . strictEqual ( child . stdout , '' ) ;
125
223
assert . strictEqual ( child . code , 1 ) ;
126
224
} ) ;
@@ -131,7 +229,7 @@ describe('node --run [command]', () => {
131
229
[ '--no-warnings' , '--run' , 'test' ] ,
132
230
{ cwd : fixtures . path ( 'run-script/cannot-find-script' ) } ,
133
231
) ;
134
- assert . match ( child . stderr , / C a n ' t f i n d " s c r i p t s " f i e l d i n p a c k a g e \. j s o n / ) ;
232
+ assert . match ( child . stderr , / C a n ' t f i n d " s c r i p t s " f i e l d i n / ) ;
135
233
assert . strictEqual ( child . stdout , '' ) ;
136
234
assert . strictEqual ( child . code , 1 ) ;
137
235
} ) ;
0 commit comments