Skip to content

Commit ecf8f4f

Browse files
committed
Support extensions, files and helpers in no-ignored-test-files and no-import-test-files rules
Fixes #252.
1 parent c8ddcc3 commit ecf8f4f

File tree

5 files changed

+67
-4
lines changed

5 files changed

+67
-4
lines changed

docs/rules/no-ignored-test-files.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,20 @@ test('foo', t => {
3636
t.pass();
3737
});
3838
```
39+
40+
## Options
41+
42+
This rule supports the following options:
43+
44+
* `extensions`: an array of extensions of the files that AVA recognizes as test files or helpers. Overrides *both* the `babel.extensions` *and* `extensions` configuration otherwise used by AVA itself.
45+
* `files`: an array of glob patterns to select test files. Overrides the `files` configuration otherwise used by AVA itself.
46+
* `helpers`: an array of glob patterns to select helper files. Overrides the `helpers` configuration otherwise used by AVA itself.
47+
* `sources`: an array of glob patterns to match files that, when changed, cause tests to be re-run (when in watch mode). Overrides the `sources` configuration otherwise used by AVA itself.
48+
49+
See also [AVA's configuration](https://github.com/avajs/ava/blob/master/docs/06-configuration.md#options).
50+
51+
You can set the options like this:
52+
53+
```js
54+
"ava/no-ignored-test-files": ["error", {"files": ["lib/**/*.test.js", "utils/**/*.test.js"]}]
55+
```

docs/rules/no-import-test-files.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,18 @@ import sinon from 'sinon';
3636
// File: src/index.js
3737
import utils from './utils';
3838
```
39+
40+
## Options
41+
42+
This rule supports the following options:
43+
44+
* `extensions`: an array of extensions of the files that AVA recognizes as test files or helpers. Overrides *both* the `babel.extensions` *and* `extensions` configuration otherwise used by AVA itself.
45+
* `files`: an array of glob patterns to select test files. Overrides the `files` configuration otherwise used by AVA itself.
46+
47+
See also [AVA's configuration](https://github.com/avajs/ava/blob/master/docs/06-configuration.md#options).
48+
49+
You can set the options like this:
50+
51+
```js
52+
"ava/no-ignored-test-files": ["error", {"files": ["lib/**/*.test.js", "utils/**/*.test.js"]}]
53+
```

rules/no-ignored-test-files.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const createAvaRule = require('../create-ava-rule');
55

66
const create = context => {
77
const filename = context.getFilename();
8+
const [overrides] = context.options;
89

910
if (filename === '<text>') {
1011
return {};
@@ -25,7 +26,7 @@ const create = context => {
2526
return;
2627
}
2728

28-
const avaHelper = util.loadAvaHelper(filename);
29+
const avaHelper = util.loadAvaHelper(filename, overrides);
2930
if (!avaHelper) {
3031
return {};
3132
}
@@ -47,12 +48,28 @@ const create = context => {
4748
});
4849
};
4950

51+
const schema = [{
52+
type: 'object',
53+
properties: {
54+
extensions: {
55+
type: 'array'
56+
},
57+
files: {
58+
type: 'array'
59+
},
60+
helpers: {
61+
type: 'array'
62+
}
63+
}
64+
}];
65+
5066
module.exports = {
5167
create,
5268
meta: {
5369
docs: {
5470
url: util.getDocsUrl(__filename)
5571
},
72+
schema,
5673
type: 'suggestion'
5774
}
5875
};

rules/no-import-test-files.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function isExternalModule(name) {
99

1010
const create = context => {
1111
const filename = context.getFilename();
12+
const [overrides] = context.options;
1213

1314
if (filename === '<text>') {
1415
return {};
@@ -30,7 +31,7 @@ const create = context => {
3031
}
3132

3233
if (!loadedAvaHelper) {
33-
avaHelper = util.loadAvaHelper(filename);
34+
avaHelper = util.loadAvaHelper(filename, overrides);
3435
loadedAvaHelper = true;
3536
}
3637

@@ -63,12 +64,25 @@ const create = context => {
6364
};
6465
};
6566

67+
const schema = [{
68+
type: 'object',
69+
properties: {
70+
extensions: {
71+
type: 'array'
72+
},
73+
files: {
74+
type: 'array'
75+
}
76+
}
77+
}];
78+
6679
module.exports = {
6780
create,
6881
meta: {
6982
docs: {
7083
url: util.getDocsUrl(__filename)
7184
},
85+
schema,
7286
type: 'suggestion'
7387
}
7488
};

util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const pkgDir = require('pkg-dir');
44
const resolveFrom = require('resolve-from');
55
const pkg = require('./package');
66

7-
exports.loadAvaHelper = filename => {
7+
exports.loadAvaHelper = (filename, overrides) => {
88
const rootDir = pkgDir.sync(filename);
99
if (!rootDir) {
1010
return undefined;
@@ -16,7 +16,7 @@ exports.loadAvaHelper = filename => {
1616
}
1717

1818
const avaHelper = require(avaHelperPath);
19-
return avaHelper.load(rootDir);
19+
return avaHelper.load(rootDir, overrides);
2020
};
2121

2222
const functionExpressions = [

0 commit comments

Comments
 (0)