Skip to content

Commit

Permalink
By default, select test and helpers inside 'tests' directories
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed Jun 1, 2019
1 parent 677578f commit b1e54b1
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion docs/05-command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $ npx ava --help

The above relies on your shell expanding the glob patterns.
Without arguments, AVA uses the following patterns:
**/test.js **/test-*.js **/*.spec.js **/*.test.js **/test/**/*.js **/__tests__/**/*.js
**/test.js **/test-*.js **/*.spec.js **/*.test.js **/test/**/*.js **/tests/**/*.js **/__tests__/**/*.js
```

*Note that the CLI will use your local install of AVA when available, even when run globally.*
Expand All @@ -42,6 +42,7 @@ AVA searches for test files using the following patterns:
* `**/*.spec.js`
* `**/*.test.js`
* `**/test/**/*.js`
* `**/tests/**/*.js`
* `**/__tests__/**/*.js`

Files inside `node_modules` are *always* ignored. So are files starting with `_`. These are treated as helpers.
Expand Down
2 changes: 1 addition & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ exports.run = async () => { // eslint-disable-line complexity
The above relies on your shell expanding the glob patterns.
Without arguments, AVA uses the following patterns:
**/test.js **/test-*.js **/*.spec.js **/*.test.js **/test/**/*.js **/__tests__/**/*.js
**/test.js **/test-*.js **/*.spec.js **/*.test.js **/test/**/*.js **/tests/**/*.js **/__tests__/**/*.js
`, {
flags: {
watch: {
Expand Down
3 changes: 2 additions & 1 deletion lib/globs.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ function normalizeGlobs(testPatterns, helperPatterns, sourcePatterns, extensions
`**/*.test.${extensionPattern}`,
`**/test-*.${extensionPattern}`,
`**/test.${extensionPattern}`,
`**/test/**/*.${extensionPattern}`
`**/test/**/*.${extensionPattern}`,
`**/tests/**/*.${extensionPattern}`
];

if (testPatterns) {
Expand Down
1 change: 1 addition & 0 deletions test/fixture/globs/default-patterns/tests/_foo-help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Empty
1 change: 1 addition & 0 deletions test/fixture/globs/default-patterns/tests/baz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Empty
1 change: 1 addition & 0 deletions test/fixture/globs/default-patterns/tests/deep/deep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Empty
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Empty
1 change: 1 addition & 0 deletions test/fixture/globs/default-patterns/tests/helpers/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Empty
12 changes: 9 additions & 3 deletions test/globs.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ test('findHelpersAndTests finds tests (just .js)', async t => {
'test-foo.js',
'test.js',
'test/baz.js',
'test/deep/deep.js'
'test/deep/deep.js',
'tests/baz.js',
'tests/deep/deep.js'
].map(file => path.join(fixtureDir, file)).sort();

const {tests: actual} = await globs.findHelpersAndTests({
Expand Down Expand Up @@ -307,7 +309,9 @@ test('findHelpersAndTests finds helpers (just .js)', async t => {
'sub/directory/__tests__/helpers/foo.js',
'sub/directory/__tests__/_foo.js',
'test/helpers/test.js',
'test/_foo-help.js'
'test/_foo-help.js',
'tests/_foo-help.js',
'tests/helpers/test.js'
].sort().map(file => path.join(fixtureDir, file));

const {helpers: actual} = await globs.findHelpersAndTests({
Expand Down Expand Up @@ -347,7 +351,9 @@ test('findTests finds tests (just .js)', async t => {
'test-foo.js',
'test.js',
'test/baz.js',
'test/deep/deep.js'
'test/deep/deep.js',
'tests/baz.js',
'tests/deep/deep.js'
].map(file => path.join(fixtureDir, file)).sort();

const {tests: actual} = await globs.findTests({
Expand Down

3 comments on commit b1e54b1

@niftylettuce
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be working in v2.0.0.

I still get the error message when I run npx ava:

✖ No tests found in test/helpers/index.js, make sure to import "ava" at the top of your test file

@novemberborn
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@niftylettuce you now need to explicitly specify glob patterns for your helpers (unless they start with an underscore and are otherwise matched by the default test file globs). See the third paragraph under Test file and helper selection https://github.com/avajs/ava/releases/tag/v2.0.0

@niftylettuce
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty

Please sign in to comment.