Browse Source

Use current working directory if no `package.json` (#1044)

replace-snapshot
Juan Soto 8 years ago
committed by Mark Wubben
parent
commit
59254b74e4
  1. 5
      api.js
  2. 4
      lib/cli.js
  3. 13
      test/cli.js

5
api.js

@ -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;

4
lib/cli.js

@ -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',

13
test/cli.js

@ -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');
@ -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');

Loading…
Cancel
Save