Skip to content

Latest commit

 

History

History
53 lines (35 loc) · 1.54 KB

no-import-test-files.md

File metadata and controls

53 lines (35 loc) · 1.54 KB

Ensure no test files are imported anywhere

Translations: Français

This rule will verify that you don't import any test files. It will consider the root of the project to be the closest folder containing a package.json file, and will not do anything if it can't find one. Test files in node_modules will not be linted as they are ignored by ESLint.

Fail

// File: src/index.js
// Invalid because *.test.js is considered as a test file.
const tests = require('./index.test.js');
// File: src/index.js
// Invalid because any files inside __tests__ are considered test files
const tests = require('./__tests__/index.js');

test('foo', t => {
	t.pass();
});

Pass

// File: src/index.js
const sinon = require('sinon');
// File: src/index.js
const utils = require('./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.

You can set the options like this:

"ava/no-import-test-files": ["error", {"files": ["lib/**/*.test.js", "utils/**/*.test.js"]}]