noExportsInTest (not released)
Diagnostic Category: lint/nursery/noExportsInTest
Inspired from: no-export
Disallow using export
or module.exports
in files containing tests
This rule aims to eliminate duplicate runs of tests by exporting things from test files. If you import from a test file, then all the tests in that file will be run in each imported instance, so bottom line, don’t export from a test, but instead move helper functions into a separate file when they need to be shared across tests.
Examples
Section titled ExamplesInvalid
Section titled Invalidexport function myHelper() {}describe('a test', () => { expect(1).toBe(1);});
nursery/noExportsInTest.js:1:1 lint/nursery/noExportsInTest ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Do not export from a test file.
> 1 │ export function myHelper() {}
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │ describe('a test', () => {
3 │ expect(1).toBe(1);
Valid
Section titled Validfunction myHelper() {}describe('a test', () => { expect(1).toBe(1);});