Skip to content

Commit bdc57f4

Browse files
authored
extract ava-files to it's own module (#925)
* ava-files should honor a `cwd` option. * Properly resolve test files in non-watch mode. * update test/watcher.js to reflect new AvaFiles Api * extract ava-files to it's own thing
1 parent 9efcee0 commit bdc57f4

File tree

27 files changed

+81
-431
lines changed

27 files changed

+81
-431
lines changed

api.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ var uniqueTempDir = require('unique-temp-dir');
1010
var findCacheDir = require('find-cache-dir');
1111
var debounce = require('lodash.debounce');
1212
var ms = require('ms');
13+
var AvaFiles = require('ava-files');
1314
var AvaError = require('./lib/ava-error');
1415
var fork = require('./lib/fork');
1516
var CachingPrecompiler = require('./lib/caching-precompiler');
16-
var AvaFiles = require('./lib/ava-files');
1717
var RunStatus = require('./lib/run-status');
1818

1919
function Api(options) {
@@ -23,7 +23,9 @@ function Api(options) {
2323

2424
EventEmitter.call(this);
2525

26-
this.options = options || {};
26+
this.options = objectAssign({}, options);
27+
this.options.cwd = this.options.cwd || process.cwd();
28+
this.options.resolveTestsFrom = this.options.resolveTestsFrom || this.options.cwd;
2729
this.options.match = this.options.match || [];
2830
this.options.require = (this.options.require || []).map(function (moduleId) {
2931
var ret = resolveCwd(moduleId);
@@ -73,7 +75,7 @@ Api.prototype._onTimeout = function (runStatus) {
7375
Api.prototype.run = function (files, options) {
7476
var self = this;
7577

76-
return new AvaFiles(files)
78+
return new AvaFiles({files: files, cwd: this.options.resolveTestsFrom})
7779
.findTestFiles()
7880
.then(function (files) {
7981
return self._run(files, options);

cli.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22
'use strict';
33

4+
var path = require('path');
45
var debug = require('debug')('ava');
56

67
// Prefer the local installation of AVA.
@@ -43,6 +44,8 @@ var conf = pkgConf.sync('ava', {
4344
}
4445
});
4546

47+
var pkgDir = path.dirname(pkgConf.filepath(conf));
48+
4649
// check for valid babel config shortcuts (can be either "default" or "inherit")
4750
var isValidShortcut = ['default', 'inherit'].indexOf(conf.babel) !== -1;
4851

@@ -136,6 +139,7 @@ var api = new Api({
136139
explicitTitles: cli.flags.watch,
137140
match: arrify(cli.flags.match),
138141
babelConfig: conf.babel,
142+
resolveTestsFrom: cli.input.length === 0 ? pkgDir : process.cwd(),
139143
timeout: cli.flags.timeout,
140144
concurrency: cli.flags.concurrency ? parseInt(cli.flags.concurrency, 10) : 0
141145
});

lib/ava-files.js

Lines changed: 0 additions & 262 deletions
This file was deleted.

lib/watcher.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var chokidar = require('chokidar');
66
var flatten = require('arr-flatten');
77
var union = require('array-union');
88
var uniq = require('array-uniq');
9-
var AvaFiles = require('./ava-files');
9+
var AvaFiles = require('ava-files');
1010

1111
function rethrowAsync(err) {
1212
// Don't swallow exceptions. Note that any expected error should already have
@@ -18,7 +18,10 @@ function rethrowAsync(err) {
1818

1919
function Watcher(logger, api, files, sources) {
2020
this.debouncer = new Debouncer(this);
21-
this.avaFiles = new AvaFiles(files, sources);
21+
this.avaFiles = new AvaFiles({
22+
files: files,
23+
sources: sources
24+
});
2225

2326
this.isTest = this.avaFiles.makeTestMatcher();
2427

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"array-union": "^1.0.1",
8282
"array-uniq": "^1.0.2",
8383
"arrify": "^1.0.0",
84+
"ava-files": "^0.1.1",
8485
"ava-init": "^0.1.0",
8586
"babel-code-frame": "^6.7.5",
8687
"babel-core": "^6.3.21",

0 commit comments

Comments
 (0)