Skip to content

Commit 9be5388

Browse files
committed
wip! Refactor glob handling
* Require globs to match files, not directories * Only accept files via the CLI, not globs or directories * Upgrade globby * At this stage, only test files starting with _ are treated as helpers. Helper globs should be made configurable. * It's no longer possible to override an exclusion pattern. We may reintroduce this at a later stage
1 parent 569b066 commit 9be5388

File tree

48 files changed

+867
-942
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+867
-942
lines changed

docs/05-command-line.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/do
66
$ npx ava --help
77

88
Usage
9-
ava [<file|directory|glob> ...]
9+
ava [<file> ...]
1010

1111
Options
1212
--watch, -w Re-run tests when tests and source files change
@@ -28,12 +28,15 @@ $ npx ava --help
2828
ava test-*.js
2929
ava test
3030

31-
Default patterns when no arguments:
32-
test.js test-*.js test/**/*.js **/__tests__/**/*.js **/*.test.js
31+
The above relies on your shell expanding the glob patterns.
32+
Without arguments, AVA uses the following patterns:
33+
test.js test-*.js test/**/*.js **/__tests__/**/*.js **/*.test.js
3334
```
3435

3536
*Note that the CLI will use your local install of AVA when available, even when run globally.*
3637

38+
**FIXME**
39+
3740
Directories are recursed, with all `*.js` files being treated as test files. Directories named `fixtures`, `helpers` and `node_modules` are *always* ignored. So are files starting with `_` which allows you to place helpers in the same directory as your test files.
3841

3942
When using `npm test`, you can pass positional arguments directly `npm test test2.js`, but flags needs to be passed like `npm test -- --verbose`.

docs/06-configuration.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ To ignore a file or directory, prefix the pattern with an `!` (exclamation mark)
1313
"ava": {
1414
"files": [
1515
"my-test-directory/**/*.js",
16-
"!my-test-directory/exclude-this-directory/**/*.js",
16+
"!my-test-directory/exclude-this-directory",
1717
"!**/exclude-this-file.js"
1818
],
1919
"sources": [
2020
"**/*.{js,jsx}",
21-
"!dist/**/*"
21+
"!dist"
2222
],
2323
"match": [
2424
"*oo",
@@ -48,7 +48,7 @@ Arguments passed to the CLI will always take precedence over the CLI options con
4848

4949
## Options
5050

51-
- `files`: file & directory paths and glob patterns that select which files AVA will run tests from. Files with an underscore prefix are ignored. All matched files in selected directories are run. By default only selects files with `js` extensions, even if the glob pattern matches other files. Specify `extensions` and `babel.extensions` to allow other file extensions
51+
- `files`: **FIXME** file & directory paths and glob patterns that select which files AVA will run tests from. Files with an underscore prefix are ignored. All matched files in selected directories are run. By default only selects files with `js` extensions, even if the glob pattern matches other files. Specify `extensions` and `babel.extensions` to allow other file extensions
5252
- `sources`: files that, when changed, cause tests to be re-run in watch mode. See the [watch mode recipe for details](https://github.com/avajs/ava/blob/master/docs/recipes/watch-mode.md#source-files-and-test-files)
5353
- `match`: not typically useful in the `package.json` configuration, but equivalent to [specifying `--match` on the CLI](./05-command-line.md#running-tests-with-matching-titles)
5454
- `cache`: cache compiled test and helper files under `node_modules/.cache/ava`. If `false`, files are cached in a temporary directory instead
@@ -64,7 +64,7 @@ Arguments passed to the CLI will always take precedence over the CLI options con
6464
- `babel.extensions`: extensions of test files that will be precompiled using AVA's Babel presets. Setting this overrides the default `"js"` value, so make sure to include that extension in the list
6565
- `timeout`: Timeouts in AVA behave differently than in other test frameworks. AVA resets a timer after each test, forcing tests to quit if no new test results were received within the specified timeout. This can be used to handle stalled tests. See our [timeout documentation](./07-test-timeouts.md) for more options.
6666

67-
Note that providing files on the CLI overrides the `files` option. If you've configured a glob pattern, for instance `test/**/*.test.js`, you may want to repeat it when using the CLI: `ava 'test/integration/*.test.js'`.
67+
**FIXME** Note that providing files on the CLI overrides the `files` option. If you've configured a glob pattern, for instance `test/**/*.test.js`, you may want to repeat it when using the CLI: `ava 'test/integration/*.test.js'`.
6868

6969
## Using `ava.config.js`
7070

docs/08-common-pitfalls.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ test('one is one', t => {
8585

8686
### Helpers are not compiled when using a non-default test folder
8787

88+
**FIXME**
89+
8890
This is a [known issue](https://github.com/avajs/ava/issues/1319). You should put your tests in a folder called `test` or `__tests__`.
8991

9092
---

docs/recipes/watch-mode.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ AVA uses [`chokidar`] as the file watcher. Note that even if you see warnings ab
6565

6666
## Source files and test files
6767

68+
**FIXME**
69+
6870
In AVA there's a distinction between *source files* and *test files*. As you can imagine the *test files* contain your tests. *Source files* are all other files that are needed for the tests to run, be it your source code or test fixtures.
6971

7072
By default AVA watches for changes to the test files, snapshot files, `package.json`, and any other `.js` files. It'll ignore files in [certain directories](https://github.com/novemberborn/ignore-by-default/blob/master/index.js) as provided by the [`ignore-by-default`] package.

lib/api.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const ms = require('ms');
1616
const chunkd = require('chunkd');
1717
const Emittery = require('emittery');
1818
const babelPipeline = require('./babel-pipeline');
19+
const globs = require('./globs');
1920
const RunStatus = require('./run-status');
20-
const AvaFiles = require('./ava-files');
2121
const fork = require('./fork');
2222
const serializeError = require('./serialize-error');
2323

@@ -50,7 +50,7 @@ class Api extends Emittery {
5050
}
5151
}
5252

53-
async run(files, runtimeOptions = {}) {
53+
async run(files = [], runtimeOptions = {}) {
5454
const apiOptions = this.options;
5555

5656
// Each run will have its own status. It can only be created when test files
@@ -105,8 +105,17 @@ class Api extends Emittery {
105105
};
106106

107107
try {
108-
// Find all test files.
109-
files = await new AvaFiles({cwd: apiOptions.resolveTestsFrom, files, extensions: this._allExtensions}).findTestFiles();
108+
const precompiler = await this._setupPrecompiler();
109+
let helpers = [];
110+
if (files.length === 0 || precompiler.enabled) {
111+
const found = await globs.findHelpersAndTests({cwd: this.options.resolveTestsFrom, ...apiOptions.globs});
112+
if (files.length === 0) {
113+
({tests: files} = found);
114+
}
115+
116+
({helpers} = found);
117+
}
118+
110119
if (this.options.parallelRuns) {
111120
const {currentIndex, totalRuns} = this.options.parallelRuns;
112121
const fileCount = files.length;
@@ -157,22 +166,21 @@ class Api extends Emittery {
157166
}
158167
});
159168

160-
let precompilation = await this._setupPrecompiler();
161-
if (precompilation.enabled) {
169+
let precompilation = null;
170+
if (precompiler.enabled) {
162171
// Compile all test and helper files. Assumes the tests only load
163172
// helpers from within the `resolveTestsFrom` directory. Without
164173
// arguments this is the `projectDir`, else it's `process.cwd()`
165174
// which may be nested too deeply.
166-
const helpers = await new AvaFiles({cwd: this.options.resolveTestsFrom, extensions: this._allExtensions}).findTestHelpers();
167175
precompilation = {
168-
cacheDir: precompilation.cacheDir,
176+
cacheDir: precompiler.cacheDir,
169177
map: [...files, ...helpers].reduce((acc, file) => {
170178
try {
171179
const realpath = fs.realpathSync(file);
172180
const filename = path.basename(realpath);
173181
const cachePath = this._regexpFullExtensions.test(filename) ?
174-
precompilation.precompileFull(realpath) :
175-
precompilation.precompileEnhancementsOnly(realpath);
182+
precompiler.precompileFull(realpath) :
183+
precompiler.precompileEnhancementsOnly(realpath);
176184
if (cachePath) {
177185
acc[realpath] = cachePath;
178186
}
@@ -183,8 +191,6 @@ class Api extends Emittery {
183191
return acc;
184192
}, {})
185193
};
186-
} else {
187-
precompilation = null;
188194
}
189195

190196
// Resolve the correct concurrency value.

0 commit comments

Comments
 (0)