Skip to content

Use current working directory if no package.json #1044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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