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

Fix default helper files glob to cover helper files inside subdirectories #1320

Closed
wants to merge 1 commit into from
Closed

Conversation

grvcoelho
Copy link

Description

When we have a helpers folder inside a subdirectory (e.g: test/unit/helpers), the helper files are not transpiled by Ava.

This PR fixes the glob that finds the defaultHelperFiles to cover subdirectories as well.

Related

This fixes #1319

@novemberborn
Copy link
Member

I'm not sure about this… we already have issues with helper globbing performance (#1288). Helper exclusion isn't great either (#909). Perhaps we should solve those problems first.

Just spitballing here, but what if:

  • files patterns that match files cause those files to be treated as tests, not helpers
    • We support negation patterns to refine selections if necessary
    • We exclude {project-dir}/node_modules by default, though ideally you can override this by providing a more specific path
  • files patterns that match directories mean that containing files are treated as tests, unless they're inside fixtures and helpers directories (that are children of the matched directories), or start with _ (regardless of how deeply they are nested)

This wouldn't really help your use case, but I think it makes test file matching more understandable. We could then add support for helper patterns, so you can match those and we transpile them. A utility command that prints out what files are matched and how they're treated would also be useful.

@grvcoelho
Copy link
Author

I'm not sure about this… we already have issues with helper globbing performance (#1288). Helper exclusion isn't great either (#909). Perhaps we should solve those problems first.

@novemberborn: I've read the discussions and I'm not sure if I understood the problem correctly, but the issue with #1288 is because of number of files and not globbing itself, right?

Because, ATM in my case, if I rename everything inside my helpers folder to have a _ prefix, it will be considered a helper and be transpiled. So overall, it is the same amount of files, I just don't need to put the _ prefix.

ATM, _ prefixed helpers are transpiled inside subdirectories, but helpers that are inside helpers folder are not. So the behaviors are different if you decide do _-prefix your helpers or to put them inside helpers folder.

We could then add support for helper patterns, so you can match those and we transpile them.

That would be great in the future 🙂

@novemberborn
Copy link
Member

I've read the discussions and I'm not sure if I understood the problem correctly, but the issue with #1288 is because of number of files and not globbing itself, right?

I think it's because of the ** which matches any directory, leading to a lot of matching.

I'm not saying this PR isn't an improvement, it's just that the whole helper story is a bit of a mess and I'm not sure whether we should add more twists to it.

@sindresorhus
Copy link
Member

sindresorhus commented Mar 24, 2017

I'm also concerned about the performance implications of this.


files patterns that match files cause those files to be treated as tests, not helpers

@novemberborn How is this different from how it already works? Or do you mean the ability to do $ ava _foo.js and have it run as a test instead of being a helper?

@novemberborn
Copy link
Member

files patterns that match files cause those files to be treated as tests, not helpers

@novemberborn How is this different from how it already works? Or do you mean the ability to do $ ava _foo.js and have it run as a test instead of being a helper?

@sindresorhus uhm, I hadn't even thought of it like that. I guess if you don't use a pattern it could be used as-is…? Probably easier to never treat any _-prefixed file as a test.

@wmertens
Copy link

wmertens commented Aug 4, 2017

This approach seems to slow down my AVA runs a lot, I think it descends into my build/ dir but I don't really know, there is no debugging output for the globbing.

How about not scanning for helper files, but instead somehow intercepting the require mechanism that Babel uses to transpile, only allowing it to transpile imports that match helper globs?

@wmertens
Copy link

wmertens commented Aug 4, 2017

I just went into the module, prepended the helper globs with my source dirs (e.g. '{src,lib}/**/__tests__/helpers/**/*.js'), and ava run time decreased by 20s!

@novemberborn
Copy link
Member

This approach seems to slow down my AVA runs a lot, I think it descends into my build/ dir but I don't really know, there is no debugging output for the globbing.

@wmertens is this a comment on this PR, or AVA's current behavior?

How about not scanning for helper files, but instead somehow intercepting the require mechanism that Babel uses to transpile, only allowing it to transpile imports that match helper globs?

This is tricky to do performantly at the moment.

Let's move the performance discussion to #1228 (comment).

@novemberborn
Copy link
Member

I still don't think adding more patterns is the right answer here. Improving the files matching, and supporting helpers patterns should be sufficient.

@grvcoelho #1319 is valid though. I'm sorry this is taking so long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ava does not transpile helpers!
5 participants