Ava: `files` vs. `source` vs. `match`?

Created on 27 Jul 2017  Β·  9Comments  Β·  Source: avajs/ava

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:

  • Are files the test files? Shouldn’t test be in the name of this property?
  • Is source all files (tests and implementations)? Is this option needed for the --watch mode?

    • Would it make sense to just specify the implementations here and to watch (the union of) the test files and the implementation files?

  • match looks like an additional filter mechanism. Why is such a mechanism needed?
documentation

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-files
  • match - 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*'.

All 9 comments

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-files
  • match - 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 ;)

Was this page helpful?
0 / 5 - 0 ratings