Search code examples
ava

What do I name my files? How do I run a single test?


In jest one names a file thing.jest.ts. You can then run jest thing.jest.ts or point jest at a folder of test files eg jest some_folder/sub_folder.

How do I do this with AVA?


Things that don't work:

  1. Can't use wildcards
$ ava /**/*.test.ts
✖ /**/*.test.ts does not exist.
  1. Can't directly point to a file... maybe typescript doesn't work
$ ava ./src/Derivations/Sources/__tests/Source.test.ts 
  1. Can't run with ts-node
$ ts-node ./src/Derivations/Sources/__tests/Source.test.ts 
Test files must be run with the AVA CLI:
    $ ava src/Derivations/Sources/__tests/Source.test.ts    

Solution

  • This just requires some config. By default though, AVA does not currently (Jan 2020) support Typescript files.

    https://github.com/avajs/ava/blob/master/docs/recipes/typescript.md

    You can configure AVA to recognize TypeScript files. Then, with ts-node installed (npm i ts-node --save-dev), you can compile them on the fly.

    package.json:

    {
        "ava": {
            "compileEnhancements": false,
            "extensions": [
                "ts"
            ],
            "require": [
                "ts-node/register"
            ]
        }
    }