Skip to content

Commit

Permalink
Support extensions, files and helpers in no-ignored-test-files and no…
Browse files Browse the repository at this point in the history
…-import-test-files rules

Fixes #252.
  • Loading branch information
novemberborn committed Jun 10, 2019
1 parent 67c27b4 commit 428d70d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
17 changes: 17 additions & 0 deletions docs/rules/no-ignored-test-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,20 @@ test('foo', t => {
t.pass();
});
```

## Options

This rule supports the following options:

* `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.
* `files`: an array of glob patterns to select test files. Overrides the `files` configuration otherwise used by AVA itself.
* `helpers`: an array of glob patterns to select helper files. Overrides the `helpers` configuration otherwise used by AVA itself.
* `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.

See also [AVA's configuration](https://github.com/avajs/ava/blob/master/docs/06-configuration.md#options).

You can set the options like this:

```js
"ava/no-ignored-test-files": ["error", {"files": ["lib/**/*.test.js", "utils/**/*.test.js"]}]
```
15 changes: 15 additions & 0 deletions docs/rules/no-import-test-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@ import sinon from 'sinon';
// File: src/index.js
import utils from './utils';
```

## Options

This rule supports the following options:

* `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.
* `files`: an array of glob patterns to select test files. Overrides the `files` configuration otherwise used by AVA itself.

See also [AVA's configuration](https://github.com/avajs/ava/blob/master/docs/06-configuration.md#options).

You can set the options like this:

```js
"ava/no-ignored-test-files": ["error", {"files": ["lib/**/*.test.js", "utils/**/*.test.js"]}]
```
19 changes: 18 additions & 1 deletion rules/no-ignored-test-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const createAvaRule = require('../create-ava-rule');

const create = context => {
const filename = context.getFilename();
const [overrides] = context.options;

if (filename === '<text>') {
return {};
Expand All @@ -25,7 +26,7 @@ const create = context => {
return;
}

const avaHelper = util.loadAvaHelper(filename);
const avaHelper = util.loadAvaHelper(filename, overrides);
if (!avaHelper) {
return {};
}
Expand All @@ -47,12 +48,28 @@ const create = context => {
});
};

const schema = [{
type: 'object',
properties: {
extensions: {
type: 'array'
},
files: {
type: 'array'
},
helpers: {
type: 'array'
}
}
}];

module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl(__filename)
},
schema,
type: 'suggestion'
}
};
16 changes: 15 additions & 1 deletion rules/no-import-test-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const isFileImport = name => path.isAbsolute(name) || name.startsWith('./') || n

const create = context => {
const filename = context.getFilename();
const [overrides] = context.options;

if (filename === '<text>') {
return {};
Expand All @@ -27,7 +28,7 @@ const create = context => {
}

if (!loadedAvaHelper) {
avaHelper = util.loadAvaHelper(filename);
avaHelper = util.loadAvaHelper(filename, overrides);
loadedAvaHelper = true;
}

Expand Down Expand Up @@ -60,12 +61,25 @@ const create = context => {
};
};

const schema = [{
type: 'object',
properties: {
extensions: {
type: 'array'
},
files: {
type: 'array'
}
}
}];

module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl(__filename)
},
schema,
type: 'suggestion'
}
};
4 changes: 2 additions & 2 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const pkgDir = require('pkg-dir');
const resolveFrom = require('resolve-from');
const pkg = require('./package');

exports.loadAvaHelper = filename => {
exports.loadAvaHelper = (filename, overrides) => {
const rootDir = pkgDir.sync(filename);
if (!rootDir) {
return undefined;
Expand All @@ -16,7 +16,7 @@ exports.loadAvaHelper = filename => {
}

const avaHelper = require(avaHelperPath);
return avaHelper.load(rootDir);
return avaHelper.load(rootDir, overrides);
};

const functionExpressions = [
Expand Down

0 comments on commit 428d70d

Please sign in to comment.