Skip to content

Commit

Permalink
Use current working directory if no package.json (#1044)
Browse files Browse the repository at this point in the history
  • Loading branch information
sotojuan authored and novemberborn committed Oct 30, 2016
1 parent 3c3a6d8 commit 59254b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion api.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,13 @@ Api.prototype._setupPrecompiler = function (files) {
var cacheDir = uniqueTempDir();

if (isCacheEnabled) {
cacheDir = findCacheDir({
var foundDir = findCacheDir({
name: 'ava',
files: files
});
if (foundDir !== null) {
cacheDir = foundDir;
}
}

this.options.cacheDir = cacheDir;
Expand Down
4 changes: 3 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ Promise.longStackTraces();

exports.run = function () {
var conf = pkgConf.sync('ava');
var pkgDir = path.dirname(pkgConf.filepath(conf));

var filepath = pkgConf.filepath(conf);
var pkgDir = filepath === null ? process.cwd() : path.dirname(filepath);

var cli = meow([
'Usage',
Expand Down
13 changes: 13 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var mkdirp = require('mkdirp');
var touch = require('touch');
var proxyquire = require('proxyquire');
var sinon = require('sinon');
var uniqueTempDir = require('unique-temp-dir');
var execa = require('execa');

var cliPath = path.join(__dirname, '../cli.js');

Expand Down Expand Up @@ -371,6 +373,17 @@ test('prefers local version of ava', function (t) {
t.end();
});

test('use current working directory if `package.json` is not found', function () {
var cwd = uniqueTempDir({create: true});
var testFilePath = path.join(cwd, 'test.js');
var cliPath = require.resolve('../cli.js');
var avaPath = require.resolve('../');

fs.writeFileSync(testFilePath, 'import test from ' + JSON.stringify(avaPath) + ';\ntest(t => { t.pass(); });');

return execa(process.execPath, [cliPath], {cwd: cwd});
});

test('workers ensure test files load the same version of ava', function (t) {
var target = path.join(__dirname, 'fixture', 'ava-paths', 'target');

Expand Down

0 comments on commit 59254b7

Please sign in to comment.