Skip to content

Commit f062849

Browse files
committed
Properly resolve test files in non-watch mode.
1 parent ead0bab commit f062849

File tree

8 files changed

+66
-1
lines changed

8 files changed

+66
-1
lines changed

api.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function Api(options) {
2525

2626
this.options = objectAssign({}, options);
2727
this.options.cwd = this.options.cwd || process.cwd();
28+
this.options.resolveTestsFrom = this.options.resolveTestsFrom || this.options.cwd;
2829
this.options.match = this.options.match || [];
2930
this.options.require = (this.options.require || []).map(function (moduleId) {
3031
var ret = resolveCwd(moduleId);
@@ -74,7 +75,7 @@ Api.prototype._onTimeout = function (runStatus) {
7475
Api.prototype.run = function (files, options) {
7576
var self = this;
7677

77-
return new AvaFiles({files: files})
78+
return new AvaFiles({files: files, cwd: this.options.resolveTestsFrom})
7879
.findTestFiles()
7980
.then(function (files) {
8081
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
});

test/cli.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,39 @@ test('pkg-conf: cli takes precedence', function (t) {
176176
});
177177
});
178178

179+
test('pkg-conf(resolve-dir): works as expected when run from the package.json directory', function (t) {
180+
execCli(['--verbose'], {dirname: 'fixture/pkg-conf/resolve-dir'}, function (err, stdout, stderr) {
181+
t.ifError(err);
182+
t.match(stderr, /dir-a-base-1/);
183+
t.match(stderr, /dir-a-base-2/);
184+
t.notMatch(stderr, /dir-a-wrapper/);
185+
t.notMatch(stdout, /dir-a-wrapper/);
186+
t.end();
187+
});
188+
});
189+
190+
test('pkg-conf(resolve-dir): resolves tests from the package.json dir if none are specified on cli', function (t) {
191+
execCli(['--verbose'], {dirname: 'fixture/pkg-conf/resolve-dir/dir-a-wrapper'}, function (err, stdout, stderr) {
192+
t.ifError(err);
193+
t.match(stderr, /dir-a-base-1/);
194+
t.match(stderr, /dir-a-base-2/);
195+
t.notMatch(stderr, /dir-a-wrapper/);
196+
t.notMatch(stdout, /dir-a-wrapper/);
197+
t.end();
198+
});
199+
});
200+
201+
test('pkg-conf(resolve-dir): resolves tests process.cwd() if globs are passed on the command line', function (t) {
202+
execCli(['--verbose', 'dir-a/*.js'], {dirname: 'fixture/pkg-conf/resolve-dir/dir-a-wrapper'}, function (err, stdout, stderr) {
203+
t.ifError(err);
204+
t.match(stderr, /dir-a-wrapper-3/);
205+
t.match(stderr, /dir-a-wrapper-4/);
206+
t.notMatch(stderr, /dir-a-base/);
207+
t.notMatch(stdout, /dir-a-base/);
208+
t.end();
209+
});
210+
});
211+
179212
test('watcher reruns test files when they changed', function (t) {
180213
var killed = false;
181214

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import test from '../../../../../../';
2+
3+
test(t => {
4+
t.pass();
5+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import test from '../../../../../../';
2+
3+
test(t => {
4+
t.pass();
5+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import test from '../../../../../';
2+
3+
test(t => {
4+
t.pass();
5+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import test from '../../../../../';
2+
3+
test(t => {
4+
t.pass();
5+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "application-name",
3+
"version": "0.0.1",
4+
"ava": {
5+
"files": "dir-a/*.js"
6+
}
7+
}

0 commit comments

Comments
 (0)