Ava: Default test filename convention __tests__ not working

Created on 25 May 2016  ยท  9Comments  ยท  Source: avajs/ava

As the implementer of this extension to the list of default filenames I feel embarrassed that I didn't test this out sooner, but if you see this repo it follows the convention in my project. Unfortunately, running the tests (after npm install) you'll get:

   1 exception


   โœ– Couldn't find any files to test

The project has the following structure:

~/Desktop/ava-bug-test-filename-conventions (master)
๐Ÿ‘พ  $ tree -I node_modules
.
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ public
    โ””โ”€โ”€ js
        โ””โ”€โ”€ __tests__
            โ””โ”€โ”€ thing.js

3 directories, 2 files

Am I doing something wrong or is there a bug here?

bug

All 9 comments

I've updated the project to demonstrate some other patterns that I expect should work but don't. Here's the structure now:

~/Desktop/ava-bug-test-filename-conventions (master)
๐Ÿ‘พ  $ tree -I node_modules
.
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ public
โ”‚ย ย  โ”œโ”€โ”€ js
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ __tests__
โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ thing.js
โ”‚ย ย  โ”œโ”€โ”€ test-thing.js
โ”‚ย ย  โ””โ”€โ”€ thing.test.js
โ”œโ”€โ”€ test
โ”‚ย ย  โ””โ”€โ”€ thing.js
โ”œโ”€โ”€ test-thing.js
โ””โ”€โ”€ test.js

4 directories, 7 files

And here's the output (with --verbose):

~/Desktop/ava-bug-test-filename-conventions (master)
๐Ÿ‘พ  $ npm t

  โœ” test โ€บ works
  โœ” thing โ€บ works
  โœ” test โ€บ thing โ€บ works

  3 tests passed [14:07:15]

I would expect the other tests to run and the output to be more like:

~/Desktop/ava-bug-test-filename-conventions (master)
๐Ÿ‘พ  $ npm t

  โœ” test โ€บ works
  โœ” thing โ€บ works
  โœ” test โ€บ thing โ€บ works
  โœ” public โ€บ thing โ€บ works
  โœ” public โ€บ thing.test โ€บ works
  โœ” public โ€บ js โ€บ __tests__ โ€บ thing โ€บ works

  6 tests passed [14:07:15]

Or something like that. Am I missing something?

Hmm. That's a bummer.

Can you open a PR, with a fixture directory, and a failing unit test for ava-files.

We didn't have a good example to follow when you implemented this, but there's one there now (the one about duplicates)

this is the problem I believe https://github.com/avajs/ava/blob/master/cli.js#L168, beacuse of that line this https://github.com/avajs/ava/blob/master/lib/ava-files.js#L34 never gets a chance to work

Those defaults should just be removed from cli.js there's no point in having two places with default files

@nfcampos is correct. Removing that from the CLI in my local node_modules fixes the issue and my output is like this:

~/Desktop/ava-bug-test-filename-conventions (master)
๐Ÿ‘พ  $ npm t

  โœ” test โ€บ works
  โœ” public โ€บ js โ€บ thing โ€บ works
  โœ” thing โ€บ works
  โœ” test โ€บ thing โ€บ works
  โœ” public โ€บ thing โ€บ works

  5 tests passed [14:18:04]

(Note, I was incorrect in what I expected before, this is now correct).

Haha, sorry, another update. I changed the test names to make things easier. Here's the output that I get (after removing the lines that @nfcampos mentions):

~/Desktop/ava-bug-test-filename-conventions (master)
๐Ÿ‘พ  $ npm t

  โœ” test โ€บ test.js
  โœ” public โ€บ thing โ€บ public/thing.test.js
  โœ” thing โ€บ test-thing.js
  โœ” public โ€บ js โ€บ thing โ€บ public/js/__tests__/thing.js
  โœ” test โ€บ thing โ€บ test/thing.js

  5 tests passed [14:20:44]

Comparing it to the project tree:

~/Desktop/ava-bug-test-filename-conventions (master)
๐Ÿ‘พ  $ tree -I node_modules
.
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ public
โ”‚ย ย  โ”œโ”€โ”€ js
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ __tests__
โ”‚ย ย  โ”‚ย ย      โ””โ”€โ”€ thing.js
โ”‚ย ย  โ”œโ”€โ”€ test-thing.js
โ”‚ย ย  โ””โ”€โ”€ thing.test.js
โ”œโ”€โ”€ test
โ”‚ย ย  โ””โ”€โ”€ thing.js
โ”œโ”€โ”€ test-thing.js
โ””โ”€โ”€ test.js

4 directories, 7 files

You can see that public/test-thing.js is not present in the output. I'm guessing that was never supported and is not actually the expectation after all...

I'll try to file a PR to remove those lines from the CLI and see if I can get a test working. Thanks!

@kentcdodds public/test-thing.js not being in the output is because the default pattern that deals with test-*.js only finds files in the top level directory

Published in 0.15.1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

avaly picture avaly  ยท  4Comments

electerious picture electerious  ยท  3Comments

ivogabe picture ivogabe  ยท  5Comments

dlumma picture dlumma  ยท  4Comments

fleg picture fleg  ยท  3Comments