Ava: Harmonize test file & source pattern handling

Created on 7 Apr 2016  路  9Comments  路  Source: avajs/ava

Handling of test file patterns should be harmonized with how source patterns are handled (#614):

  • Use the default patterns if files is empty, _or_ if it only contains negated patterns
  • Apply specified negated patterns together with the default exclusion patterns
  • Allow specified patterns to override the default exclusion patterns

The default exclusion patterns for source files are relative to the current working (node_modules/**/*) however the test file exclusion patterns can apply anywhere (**/node_modules/**). I guess that makes sense, though I'm not sure how to override the default exclusion patterns. Maybe that's not necessary for test files?

Should we change the source exclusion patterns? Or do those make more sense relative to the current working directory?


Implementation wise I think we can move the file selection tests in test/api.js to a new test/ava-files.js test file. We can set up a fixture directory to exercise the globbing behavior.

enhancement globbing

Most helpful comment

@novemberborn Exactly this example is occurring in my project. Is there any way to bypass this?

All 9 comments

The default exclusion patterns for source files are relative to the current working (node_modules/**/*) however the test file exclusion patterns can apply anywhere (**/node_modules/**)

I think the source file pattern should be made to match the test file pattern.

I guess that makes sense, though I'm not sure how to override the default exclusion patterns. Maybe that's not necessary for test files?

Aren't you doing exactly that (overriding the defaults) in #614?

I think the source file pattern should be made to match the test file pattern.

Yea maybe. Here's the list of source excludes. coverage may be tricky.

I guess that makes sense, though I'm not sure how to override the default exclusion patterns. Maybe that's not necessary for test files?

Aren't you doing exactly that (overriding the defaults) in #614?

Yes, but that's based on the path prefix. So node_modules/whatever maps to node_modules/**/*. That's trickier when the exclude patterns are recursive (**/node_modules/**). Now every path component needs to be checked. Though I guess that answers my question :)

Maybe we should move all this manipulation code into an external library.

coverage may be tricky.

Why?

@jamestalmage it's a fairly generic name when ignoring deeply nested directories. I doubt anybody would put legitimate code in say .sass-cache.

Allow specified patterns to override the default exclusion patterns

For example if you mimick your lib directory inside the test directory and you have actual helper modules inside lib/helpers, you may want to put their tests in test/helpers. You should be able to add test/helpers to the files pattern so that AVA looks for test files in that directory. See https://github.com/avajs/ava/issues/909#issuecomment-228455326.

@novemberborn Exactly this example is occurring in my project. Is there any way to bypass this?

@buzinas not currently, no. You'll have to pick a different directory name.

The default exclusion patterns for source files are relative to the current working (node_modules//) however the test file exclusion patterns can apply anywhere (/node_modules/*). I guess that makes sense, though I'm not sure how to override the default exclusion patterns. Maybe that's not necessary for test files?

Currently this prevents tests from being shared through an npm package. Specifying an explicit node_modules/my-package/*.js pattern should select those tests in spite of the exclusion pattern. See https://github.com/avajs/ava/pull/1136#issuecomment-264709272.

There's more discussion in this PR: https://github.com/avajs/ava/pull/1320#issuecomment-288768089


At this point we're looking for help in summarizing the discussion into an actionable proposal, and then writing the code.

Was this page helpful?
0 / 5 - 0 ratings