Skip to content

Default test filename convention __tests__ not working #875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kentcdodds opened this issue May 25, 2016 · 9 comments
Closed

Default test filename convention __tests__ not working #875

kentcdodds opened this issue May 25, 2016 · 9 comments
Labels
bug current functionality does not work as desired

Comments

@kentcdodds
Copy link
Contributor

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?

@kentcdodds
Copy link
Contributor Author

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?

@jamestalmage
Copy link
Contributor

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)

@nfcampos
Copy link
Contributor

nfcampos commented May 25, 2016

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

@nfcampos
Copy link
Contributor

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

@kentcdodds
Copy link
Contributor Author

@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).

@kentcdodds
Copy link
Contributor Author

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...

@kentcdodds
Copy link
Contributor Author

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

@jamestalmage jamestalmage added bug current functionality does not work as desired assigned labels May 25, 2016
kentcdodds pushed a commit to kentcdodds/ava that referenced this issue May 25, 2016
The default files should be in one place (`ava-files.js`).
Right now the defaults provided in `ava-files.js` aren't being used
because the CLI pre-populates them.

Closes avajs#875
@nfcampos
Copy link
Contributor

@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

kentcdodds pushed a commit to kentcdodds/ava that referenced this issue May 25, 2016
The default files should be in one place (`ava-files.js`).
Right now the defaults provided in `ava-files.js` aren't being used
because the CLI pre-populates them.

Closes avajs#875
kentcdodds pushed a commit to kentcdodds/ava that referenced this issue May 25, 2016
The default files should be in one place (`ava-files.js`).
Right now the defaults provided in `ava-files.js` aren't being used
because the CLI pre-populates them.

Closes avajs#875
kentcdodds pushed a commit to kentcdodds/ava that referenced this issue May 25, 2016
The default files should be in one place (`ava-files.js`).
Right now the defaults provided in `ava-files.js` aren't being used
because the CLI pre-populates them.

Closes avajs#875
@jamestalmage
Copy link
Contributor

Published in 0.15.1

AlexandreMalaj added a commit to SlimIO/Config that referenced this issue Apr 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug current functionality does not work as desired
Projects
None yet
Development

No branches or pull requests

3 participants