File tree 2 files changed +35
-2
lines changed
2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
const path = require ( 'path' ) ;
3
+ const fs = require ( 'fs' ) ;
3
4
const del = require ( 'del' ) ;
4
5
const updateNotifier = require ( 'update-notifier' ) ;
5
6
const figures = require ( 'figures' ) ;
@@ -213,6 +214,24 @@ exports.run = async () => { // eslint-disable-line complexity
213
214
214
215
const match = arrify ( conf . match ) ;
215
216
const resolveTestsFrom = cli . input . length === 0 ? projectDir : process . cwd ( ) ;
217
+
218
+ const files = cli . input . map ( file => path . relative ( resolveTestsFrom , path . resolve ( process . cwd ( ) , file ) ) ) ;
219
+
220
+ for ( const file of cli . input ) {
221
+ try {
222
+ const stats = fs . statSync ( file ) ;
223
+ if ( ! stats . isFile ( ) ) {
224
+ exit ( `${ file } is not a test file.` ) ;
225
+ }
226
+ } catch ( error ) {
227
+ if ( error . code === 'ENOENT' ) {
228
+ exit ( `${ file } does not exist.` ) ;
229
+ } else {
230
+ exit ( `Error accessing ${ file } \n\n${ chalk . gray ( ( error && error . stack ) || error ) } ` ) ;
231
+ }
232
+ }
233
+ }
234
+
216
235
const api = new Api ( {
217
236
babelConfig,
218
237
cacheEnabled : conf . cache !== false ,
@@ -268,8 +287,6 @@ exports.run = async () => { // eslint-disable-line complexity
268
287
} ) ;
269
288
} ) ;
270
289
271
- const files = cli . input . map ( file => path . relative ( resolveTestsFrom , path . resolve ( process . cwd ( ) , file ) ) ) ;
272
-
273
290
if ( conf . watch ) {
274
291
const watcher = new Watcher ( {
275
292
api,
Original file line number Diff line number Diff line change @@ -27,6 +27,22 @@ test('timeout', t => {
27
27
// }, 2000);
28
28
// });
29
29
30
+ test ( 'Should throw error if passed file does not exist' , t => {
31
+ execCli ( 'no-such-file.js' , ( err , e , stdout ) => {
32
+ t . ok ( err ) ;
33
+ t . match ( stdout , / n o - s u c h - f i l e \. j s d o e s n o t e x i s t \. / ) ;
34
+ t . end ( ) ;
35
+ } ) ;
36
+ } ) ;
37
+
38
+ test ( 'Should throw error if passed file is a directory' , t => {
39
+ execCli ( 'ava-paths' , ( err , e , stdout ) => {
40
+ t . ok ( err ) ;
41
+ t . match ( stdout , / a v a - p a t h s i s n o t a t e s t f i l e \. / ) ;
42
+ t . end ( ) ;
43
+ } ) ;
44
+ } ) ;
45
+
30
46
test ( 'include anonymous functions in error reports' , t => {
31
47
execCli ( 'error-in-anonymous-function.js' , ( err , stdout ) => {
32
48
t . ok ( err ) ;
You can’t perform that action at this time.
0 commit comments