@@ -40,6 +40,23 @@ try { runner.run('./test/data/.scriptrc', 'bogus.data'); }
40
40
catch ( err ) { thrown = true ; }
41
41
if ( ! thrown ) { throw new Error ( 'typhonjs-npm-scripts-runner test error: bad entries did not throw exception' ) ; }
42
42
43
+ // Verify that runner throws exception with bad file array.
44
+ thrown = false ;
45
+ try { runner . run ( [ false , './test/data/.scriptrc' ] , 'test.data.scripts' ) ; }
46
+ catch ( err ) { thrown = true ; }
47
+ if ( ! thrown ) { throw new Error ( 'typhonjs-npm-scripts-runner test error: bad file array did not throw exception' ) ; }
48
+
49
+ // Verify that runner throws exception with bad file array paths.
50
+ thrown = false ;
51
+ try { runner . run ( [ './test/data/.badfile1' , './test/data/.badfile2' ] , 'test.data.scripts' ) ; }
52
+ catch ( err ) { thrown = true ; }
53
+ if ( ! thrown ) { throw new Error ( 'typhonjs-npm-scripts-runner test error: bad file array did not throw exception' ) ; }
54
+
55
+ // ------------------------------------------------------------------------------------------------------------------
56
+
57
+ // Bare script treated as JSON.
58
+ console . log ( 'Testing bare script treated as JSON:' ) ;
59
+
43
60
// Actually run the test of copying files.
44
61
runner . run ( './test/data/.scriptrc' , 'test.data.scripts' ) ;
45
62
@@ -63,7 +80,190 @@ catch (err)
63
80
throw new Error ( 'typhonjs-npm-scripts-runner test error: ' + err ) ;
64
81
}
65
82
83
+ // -------------------------
84
+
85
+ // Test the message prepend
86
+ console . log ( '\nTesting bare script message prepend:' ) ;
87
+
88
+ runner . run ( './test/data/.scriptrc' , 'test.data.scripts' , 'A custom message -' ) ;
89
+
90
+ fs . emptyDirSync ( './test/fixture' ) ;
91
+
92
+ // -------------------------
93
+
94
+ // Run again with file array with bad first entry
95
+ console . log ( '\nTesting bad file array first entry:' ) ;
96
+
97
+ // Actually run the test of copying files.
98
+ runner . run ( [ './test/data/.badfile1' , './test/data/.scriptrc' , './test/data/.badfile2' ] , 'test.data.scripts' ) ;
99
+
100
+ // Verify that two files were copied.
101
+ try
102
+ {
103
+ // Verify that `./test/fixture/empty2.json` exists.
104
+ if ( ! fs . statSync ( './test/fixture/empty2.js' ) . isFile ( ) )
105
+ {
106
+ throw new Error ( '`./test/fixture/empty2.js` is not a file.' ) ;
107
+ }
108
+
109
+ // Verify that `./test/fixture/empty3.json` exists.
110
+ if ( ! fs . statSync ( './test/fixture/empty2.js' ) . isFile ( ) )
111
+ {
112
+ throw new Error ( '`./test/fixture/empty2.js` is not a file.' ) ;
113
+ }
114
+ }
115
+ catch ( err )
116
+ {
117
+ throw new Error ( 'typhonjs-npm-scripts-runner test error: ' + err ) ;
118
+ }
119
+
120
+ // -------------------------
121
+
66
122
// Test the message prepend
123
+ console . log ( '\nTesting message prepend:' ) ;
124
+
67
125
runner . run ( './test/data/.scriptrc' , 'test.data.scripts' , 'A custom message -' ) ;
68
126
69
- fs . emptyDirSync ( './test/fixture' ) ;
127
+ fs . emptyDirSync ( './test/fixture' ) ;
128
+
129
+ // ------------------------------------------------------------------------------------------------------------------
130
+
131
+ // CJS JS script required.
132
+ console . log ( '\nTesting CJS scriptrc.js require:' ) ;
133
+
134
+ // Actually run the test of copying files.
135
+ runner . run ( './test/data/.scriptrc.js' , 'test.data.scripts' ) ;
136
+
137
+ // Verify that two files were copied.
138
+ try
139
+ {
140
+ // Verify that `./test/fixture/empty2.json` exists.
141
+ if ( ! fs . statSync ( './test/fixture/empty2.js' ) . isFile ( ) )
142
+ {
143
+ throw new Error ( '`./test/fixture/empty2.js` is not a file.' ) ;
144
+ }
145
+
146
+ // Verify that `./test/fixture/empty3.json` exists.
147
+ if ( ! fs . statSync ( './test/fixture/empty2.js' ) . isFile ( ) )
148
+ {
149
+ throw new Error ( '`./test/fixture/empty2.js` is not a file.' ) ;
150
+ }
151
+ }
152
+ catch ( err )
153
+ {
154
+ throw new Error ( 'typhonjs-npm-scripts-runner test error: ' + err ) ;
155
+ }
156
+
157
+ // -------------------------
158
+
159
+ // Test the message prepend
160
+ console . log ( '\nTesting CJS scriptrc.js require - message prepend:' ) ;
161
+
162
+ runner . run ( './test/data/.scriptrc.js' , 'test.data.scripts' , 'A custom message -' ) ;
163
+
164
+ fs . emptyDirSync ( './test/fixture' ) ;
165
+
166
+ // -------------------------
167
+
168
+ // Run again with file array with bad first entry
169
+ console . log ( '\nTesting CJS bad first entry for file array:' ) ;
170
+
171
+ // Actually run the test of copying files.
172
+ runner . run ( [ './test/data/.badfile1.js' , './test/data/.scriptrc.js' , './test/data/.badfile2.js' ] , 'test.data.scripts' ) ;
173
+
174
+ // Verify that two files were copied.
175
+ try
176
+ {
177
+ // Verify that `./test/fixture/empty2.json` exists.
178
+ if ( ! fs . statSync ( './test/fixture/empty2.js' ) . isFile ( ) )
179
+ {
180
+ throw new Error ( '`./test/fixture/empty2.js` is not a file.' ) ;
181
+ }
182
+
183
+ // Verify that `./test/fixture/empty3.json` exists.
184
+ if ( ! fs . statSync ( './test/fixture/empty2.js' ) . isFile ( ) )
185
+ {
186
+ throw new Error ( '`./test/fixture/empty2.js` is not a file.' ) ;
187
+ }
188
+ }
189
+ catch ( err )
190
+ {
191
+ throw new Error ( 'typhonjs-npm-scripts-runner test error: ' + err ) ;
192
+ }
193
+
194
+ // -------------------------
195
+
196
+ // Test the message prepend
197
+ console . log ( '\nTesting CJS prepend message:' ) ;
198
+
199
+ runner . run ( './test/data/.scriptrc.js' , 'test.data.scripts' , 'A custom message -' ) ;
200
+
201
+ fs . emptyDirSync ( './test/fixture' ) ;
202
+
203
+ // -------------------------
204
+
205
+ // Test that multiple file array only executes first matching file.
206
+ console . log ( '\nTesting JSON file array only executes first matching script:' ) ;
207
+
208
+ // Actually run the test of copying files.
209
+ runner . run ( [ './test/data/.scriptrc' , './test/data/.scriptrc2' ] , 'test.data.scripts' ) ;
210
+
211
+ // Verify that two files were copied and that 'scriptrc2' is not executed.
212
+ try
213
+ {
214
+ // Verify that `./test/fixture/empty2.json` exists.
215
+ if ( ! fs . statSync ( './test/fixture/empty2.js' ) . isFile ( ) )
216
+ {
217
+ throw new Error ( '`./test/fixture/empty2.js` is not a file.' ) ;
218
+ }
219
+
220
+ // Verify that `./test/fixture/empty3.json` exists.
221
+ if ( ! fs . statSync ( './test/fixture/empty2.js' ) . isFile ( ) )
222
+ {
223
+ throw new Error ( '`./test/fixture/empty2.js` is not a file.' ) ;
224
+ }
225
+
226
+ // Verify that `./test/fixture/empty3.json` exists.
227
+ if ( fs . existsSync ( './test/fixture/SHOULD_NOT_EXIST.js' ) )
228
+ {
229
+ throw new Error ( '`./test/fixture/SHOULD_NOT_EXIST.js` is was copied / scriptrc2 was incorrectly executed.' ) ;
230
+ }
231
+ }
232
+ catch ( err )
233
+ {
234
+ throw new Error ( 'typhonjs-npm-scripts-runner test error: ' + err ) ;
235
+ }
236
+
237
+ // -------------------------
238
+
239
+ // Test that multiple file array only executes first matching file.
240
+ console . log ( '\nTesting CJS file array only executes first matching script:' ) ;
241
+
242
+ // Actually run the test of copying files.
243
+ runner . run ( [ './test/data/.scriptrc.js' , './test/data/.scriptrc2' ] , 'test.data.scripts' ) ;
244
+
245
+ // Verify that two files were copied and that 'scriptrc2' is not executed.
246
+ try
247
+ {
248
+ // Verify that `./test/fixture/empty2.json` exists.
249
+ if ( ! fs . statSync ( './test/fixture/empty2.js' ) . isFile ( ) )
250
+ {
251
+ throw new Error ( '`./test/fixture/empty2.js` is not a file.' ) ;
252
+ }
253
+
254
+ // Verify that `./test/fixture/empty3.json` exists.
255
+ if ( ! fs . statSync ( './test/fixture/empty2.js' ) . isFile ( ) )
256
+ {
257
+ throw new Error ( '`./test/fixture/empty2.js` is not a file.' ) ;
258
+ }
259
+
260
+ // Verify that `./test/fixture/empty3.json` exists.
261
+ if ( fs . existsSync ( './test/fixture/SHOULD_NOT_EXIST.js' ) )
262
+ {
263
+ throw new Error ( '`./test/fixture/SHOULD_NOT_EXIST.js` is was copied / scriptrc2 was incorrectly executed.' ) ;
264
+ }
265
+ }
266
+ catch ( err )
267
+ {
268
+ throw new Error ( 'typhonjs-npm-scripts-runner test error: ' + err ) ;
269
+ }
0 commit comments