Thanks for working on AVA! I'm enjoying it very much so far. I've run into an edge case with globbing patterns, and have put up a repository reproducing the issue: https://github.com/coopy/ava-test-glob-repro
I have a source tree that looks like this (with test files in asrc/modules/deeper/ directory):
βββ lib
βΒ Β βββ dep.js
βΒ Β βββ dep.test.js
βββ modules
βββ deeper
βββ add.js
βββ add.test.js
When I run $ ava with defaults, all is good and tests are found and run.
Issue: When I run AVA with a file globbing pattern specified, only the tests in the shallower directory (lib/) are run .
$ ava src/**/*.test.js
See full repro here:
https://github.com/coopy/ava-test-glob-repro
$ ava src/**/*.test.js --verbose
β should return configuration
1 test passed
$ ava --verbose
β lib βΊ dep βΊ should return configuration
β modules βΊ deeper βΊ add βΊ should add two numbers
2 tests passed
Copy the relevant section from package.json:
{
"name": "ava-test-glob-repro",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "ava src/**/*.test.js --verbose"
},
"author": "",
"license": "MIT",
"description": "",
"devDependencies": {
"ava": "^0.24.0"
},
"dependencies": {
"node-glob": "^1.2.0"
}
}
Copy your npm build scripts or the ava command used:
ava src/**/*.test.js --verbose
https://github.com/coopy/ava-test-glob-repro
Tell us which operating system you are using, as well as which versions of Node.js, npm, and AVA. Run the following to get it quickly:
$ node -e "var os=require('os');console.log('Node.js ' + process.version + '\n' + os.platform() + ' ' + os.release())"
darwin 17.3.0
$ ava --version
0.24.0
$ npm --version
5.6.0
@coopy thanks for the excellent issue report!
Most likely your shell is expanding the pattern, not AVA. Try quoting the patterns instead:
$ ava 'src/**/*.test.js' --verbose
This works for me. (Closing this issue but please let me know if this helps!)
Yep, quoting the pattern solves the issue. π€¦ββοΈ Thanks, @novemberborn! I'll add quoting globs in scripts to my list of best practicesβ¦
There is a curious difference apart from just the file matches, though. When I quote the glob (or just run ava --verbose without a pattern), it lists the full directory structure:
$ ava 'src/**/*.test.js' --verbose
β modules βΊ deeper βΊ add βΊ should add two numbers
β lib βΊ dep βΊ should return configuration
2 tests passed
When I run without the glob quoted, I just get the test description (for the test in the one matched path):
$ ava src/**/*.test.js --verbose
β should return configuration
1 test passed
Either way, my issue is resolved.
@coopy if there's only a single test file the directory structure is not shown.
This was working on 1.x but is now broken for me on 2.0.0
@danielgormly I just faced the same issue with ava 2.x.x, removing the quotes solves the issue though.
@jonathansamines i believe you mentioned wrong user :)
Per the release notes: https://github.com/avajs/ava/releases/tag/v2.0.0
The CLI now only takes file paths, not glob patterns.
If you want to use glob patterns you should specify them in AVA's config, under the files key.
I understand that glob support is now in files, but why did it get _removed_ from the cli? did the args to the CLI not implicitly map into entries into the files configuration? thx :)
@cdaringe, in v1, you could pass directories and AVA would try and find test files inside of them. Combined with customizable file extensions it became quite hard to understand which files would be selected.
If Babel is enabled, AVA precompiles all test files based on the files configuration. It's simpler to reason that the CLI should receive files to execute without those necessarily impacting the pre-compilation.
Our bias for the CLI has been that configuration you always use should be in a configuration file, not a CLI argument. Thus, the CLI supports only a subset of the configuration.
Arguably I over-estimated how many people used globs on the CLI, even as a package.json run script, rather that configuring files. Though hopefully now that you can select which configuration to use through the CLI we've addressed most of those use cases.
Most helpful comment
@coopy thanks for the excellent issue report!
Most likely your shell is expanding the pattern, not AVA. Try quoting the patterns instead:
This works for me. (Closing this issue but please let me know if this helps!)