File tree 3 files changed +20
-2
lines changed 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -118,10 +118,13 @@ Api.prototype._setupPrecompiler = function (files) {
118
118
var cacheDir = uniqueTempDir ( ) ;
119
119
120
120
if ( isCacheEnabled ) {
121
- cacheDir = findCacheDir ( {
121
+ var foundDir = findCacheDir ( {
122
122
name : 'ava' ,
123
123
files : files
124
124
} ) ;
125
+ if ( foundDir !== null ) {
126
+ cacheDir = foundDir ;
127
+ }
125
128
}
126
129
127
130
this . options . cacheDir = cacheDir ;
Original file line number Diff line number Diff line change @@ -22,7 +22,9 @@ Promise.longStackTraces();
22
22
23
23
exports . run = function ( ) {
24
24
var conf = pkgConf . sync ( 'ava' ) ;
25
- var pkgDir = path . dirname ( pkgConf . filepath ( conf ) ) ;
25
+
26
+ var filepath = pkgConf . filepath ( conf ) ;
27
+ var pkgDir = filepath === null ? process . cwd ( ) : path . dirname ( filepath ) ;
26
28
27
29
var cli = meow ( [
28
30
'Usage' ,
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ var mkdirp = require('mkdirp');
12
12
var touch = require ( 'touch' ) ;
13
13
var proxyquire = require ( 'proxyquire' ) ;
14
14
var sinon = require ( 'sinon' ) ;
15
+ var uniqueTempDir = require ( 'unique-temp-dir' ) ;
16
+ var execa = require ( 'execa' ) ;
15
17
16
18
var cliPath = path . join ( __dirname , '../cli.js' ) ;
17
19
@@ -371,6 +373,17 @@ test('prefers local version of ava', function (t) {
371
373
t . end ( ) ;
372
374
} ) ;
373
375
376
+ test ( 'use current working directory if `package.json` is not found' , function ( ) {
377
+ var cwd = uniqueTempDir ( { create : true } ) ;
378
+ var testFilePath = path . join ( cwd , 'test.js' ) ;
379
+ var cliPath = require . resolve ( '../cli.js' ) ;
380
+ var avaPath = require . resolve ( '../' ) ;
381
+
382
+ fs . writeFileSync ( testFilePath , 'import test from ' + JSON . stringify ( avaPath ) + ';\ntest(t => { t.pass(); });' ) ;
383
+
384
+ return execa ( process . execPath , [ cliPath ] , { cwd : cwd } ) ;
385
+ } ) ;
386
+
374
387
test ( 'workers ensure test files load the same version of ava' , function ( t ) {
375
388
var target = path . join ( __dirname , 'fixture' , 'ava-paths' , 'target' ) ;
376
389
You can’t perform that action at this time.
0 commit comments