Itβs not clear to me what the difference is between the following three package.json properties. Would you mind explaining in the readme (AFAICT, it isnβt documented elsewhere, either)?
"files": [
"my-test-folder/*.js",
"!**/not-this-file.js"
],
"source": [
"**/*.{js,jsx}",
"!dist/**/*"
],
"match": [
"*oo",
"!foo"
],
Questions:
files the test files? Shouldnβt test be in the name of this property?source all files (tests and implementations)? Is this option needed for the --watch mode?match looks like an additional filter mechanism. Why is such a mechanism needed?You're right. We need to document this better.
In short:
files - Your test files. You can define them there instead of doing $ ava file1.js file2.js ...source - Source (non-test) files not detected automatically in watch mode. See https://github.com/avajs/ava/blob/master/docs/recipes/watch-mode.md#source-files-and-test-filesmatch - Not really useful in the package.json config, but can be useful on the command-line to filter down tests by test title. Let's say you only want to run the tests which names start with uni, you could do $ ava --match='uni*'.Perfect explanation, thanks! Just copy-paste this underneath the code snippet in the readme? Alternatively, it could be the start of a stand-alone file documenting the AVA properties in package.json.
Using the following "match pattern"
"ava": {
"files": [
"test/**/*.test.js"
],
ava still tries to run files that are not test files and should not be matched, such as test/swagger/_utils/utils.js. What am I missing?
$ ava test/swagger/_utils/
TAP version 13
# No tests found in test/swagger/_utils/utils.js, make sure to import "ava" at the top of your test file
not ok 1 - No tests found in test/swagger/_utils/utils.js, make sure to import "ava" at the top of your test file
@kristianmandrup this works for me:
β― tree -I node_modules
.
βββ package-lock.json
βββ package.json
βββ test
βββ foo.test.js
βββ swagger
βββ _utils
βββ utils.js
3 directories, 4 files
β― npx ava --verbose
β [anonymous]
1 test passed [17:17:34]
With the same settings? Yes, it works only if you run ava without specifying a subfolder of tests to run, otherwise the pattern is matched relative to the path.
$ ava test/swagger/_utils/
I believe the pattern should always be applied to the full filename of each file encountered, not the file name relative to the base path, ie. in this case test/swagger/_utils/
Ah, no, when you run ava test/swagger/_utils/ that overrides the files config. Moreover, if you pass a directory, AVA treats all contained .js files are tests. Instead you need to repeat your glob, e.g. ava 'test/swagger/*.test.js'.
Would be nice if there was just a little documentation on how this works. Thanks ;)
@kristianmandrup Fair enough, I was just looking and it's not really explained. But I think you found the right issue to bring it up in π
Would you be interested in doing a PR to clear this up?
OK, will do ;)
Most helpful comment
You're right. We need to document this better.
In short:
files- Your test files. You can define them there instead of doing$ ava file1.js file2.js ...source- Source (non-test) files not detected automatically in watch mode. See https://github.com/avajs/ava/blob/master/docs/recipes/watch-mode.md#source-files-and-test-filesmatch- Not really useful in the package.json config, but can be useful on the command-line to filter down tests by test title. Let's say you only want to run the tests which names start withuni, you could do$ ava --match='uni*'.