Skip to content
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

If specifying a directory, tests in subdirectories should be run too #249

Closed
rightaway opened this issue Nov 21, 2015 · 16 comments
Closed
Assignees
Labels
bug current functionality does not work as desired help wanted

Comments

@rightaway
Copy link

If I do ava test where test is a directory, it only runs the files directly under test. But if I had subdirectories under it, those don't get run. I think it should run all tests in that directory recursively. Or at least there should be a command line flag like -r to get this behavior.

@sindresorhus
Copy link
Member

It's intentionally not recursive, as a good default and simplicity. If you need it to be recursive just specify the appropriate glob pattern. Like: $ ava test/**.

@rightaway
Copy link
Author

Ok. Now if I have a file test/test1.js and test/subtest/test2.js (each with one test called runTest in it) and run ava test/**/*.js (glob pattern in ZSH) on the command line, the output looks like this

test2 > runTest
test > test1 > runTest

But it should look more like

test1 > runTest
subtest > test2 > runTest

At least while nested groups aren't available (#222) using directories is a good way to organize structure, so the output should be in line with that.

The beginning test doesn't appear above since that's the 'root' test folder, but if there's no option to specify a directory and a recursive flag then I don't see how it would know that test shouldn't be printed there.

That's why I think allowing to specify a directory with a recursive flag (so it's not the default and not a breaking change) would be useful, because then ava can format the results appropriately. Because using glob patterns ava just receives a list of filenames to test and isn't aware of a 'root'.

@sindresorhus
Copy link
Member

We don't add options lightly and we try very hard to keep AVA simple. You can solve this with a glob pattern. We'll fix the output somehow :)

@sindresorhus sindresorhus added the bug current functionality does not work as desired label Nov 21, 2015
@rightaway
Copy link
Author

A suggestion of how it could look. After seeing all the files passed in with the glob pattern it should strip the leading directories that are all in common. The way if someone passes in a pattern like some/sub/directory/**/*.js, and the only files that appear are some/sub/directory/sub/path/test1.js and some/sub/directory/sub/path/test2.js, then the part in common some/sub/directory/sub/path should not appear in the output.

@sindresorhus
Copy link
Member

Agreed, that's what I was thinking too.

@Qix-
Copy link
Contributor

Qix- commented Nov 21, 2015

I think it should be recursive by default.

In my case, I want to mimic my lib/ folder with test files in order to yield more succinct output with nested files.

Further, this is how other languages' test systems work and is analogous to those for me, personally - hence my decision to structure my tests like this.

As of now, I have to do ava test/**/*.js which is just fine, but it wasn't what I was expecting at first.


Then again, I see that's not what's happening anyway.

Nested files, to me, should have their file prefixes (in my opinion). Right now it's flat. Not sure if this is because I'm specifying files on the command line, or what.

screen shot 2015-11-21 at 06 21 22

@sindresorhus
Copy link
Member

@jamestalmage @vdemedes Thoughts on making it recursive by default? I'm warming up to the idea.

@Qix-
Copy link
Contributor

Qix- commented Dec 21, 2015

All AVA really needs to do is include the file in question and ignore it if it doesn't import the test function.

@jamestalmage
Copy link
Contributor

All AVA really needs to do is include the file in question and ignore it if it doesn't import the test function.

I'd prefer to have it throw an error. We fork for each of those and that is expensive. We automatically ignore files with a _ prefix, so use that for test helpers.

Nested files, to me, should have their file prefixes (in my opinion). Right now it's flat. Not sure if this is because I'm specifying files on the command line, or what.

I'm not sure what you mean. Their directory as part of the prefix? Right now we only prefix with the filename (and just the filename) if there is more than one test file. I think it makes sense to prefix directories (find the common base directory of all test files and prefix from there).

@vadimdemedes
Copy link
Contributor

I like this suggestion, we could simplify paths and remove the need for globs.

@sindresorhus
Copy link
Member

Alright. Let's go for this.

@brandon93s
Copy link

+1 on making AVA recursive by default. It's the behavior I was expecting initially and doesn't force the user to conform to a standard structure.

@ariporad
Copy link
Contributor

@sindresorhus: Do you want it to be recursive by default, or just to display directories up to a common root?

@sindresorhus
Copy link
Member

@ariporad Both

@ariporad
Copy link
Contributor

@sindresorhus: Ok, I'll take care of it. Can you assign this to me (or give me perms to do that if you prefer)?

@Qix-
Copy link
Contributor

Qix- commented Dec 26, 2015

@ariporad just submit a pull request :)

ariporad added a commit to ariporad/ava that referenced this issue Dec 26, 2015
ariporad added a commit to ariporad/ava that referenced this issue Dec 26, 2015
ariporad added a commit to ariporad/ava that referenced this issue Dec 26, 2015
ariporad added a commit to ariporad/ava that referenced this issue Dec 26, 2015
ariporad added a commit to ariporad/ava that referenced this issue Dec 26, 2015
ariporad added a commit to ariporad/ava that referenced this issue Dec 26, 2015
ariporad added a commit to ariporad/ava that referenced this issue Dec 26, 2015
ariporad added a commit to ariporad/ava that referenced this issue Dec 26, 2015
ariporad added a commit to ariporad/ava that referenced this issue Dec 26, 2015
ariporad added a commit to ariporad/ava that referenced this issue Dec 27, 2015
ariporad added a commit to ariporad/ava that referenced this issue Dec 27, 2015
@ariporad ariporad self-assigned this Dec 27, 2015
ariporad added a commit to ariporad/ava that referenced this issue Dec 28, 2015
Also, add tests and documentation.

Fixes avajs#249.
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 help wanted
Projects
None yet
Development

No branches or pull requests

7 participants