{"record":{"id":"9261edacb1c939be","repo":"oxc-project/oxc","slug":"do-not-export-from-a-test-file","errorCode":null,"errorMessage":"Do not export from a test file.","messagePattern":"Do not export from a test file\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/jest/no_export.rs","lineNumber":14,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::context::LintContext;\nuse crate::rule::Rule;\nuse crate::utils::{\n    JestFnKind, JestGeneralFnKind, is_jest_file, iter_possible_jest_call_node,\n    parse_general_jest_fn_call,\n};\n\nfn no_export_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not export from a test file.\")\n        .with_help(\"If you want to share code between tests, move it into a separate file and import it from there.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoExport;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Prevents using exports if a file has one or more tests in it.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// This rule aims to eliminate duplicate runs of tests by exporting things from test files.\n    ///  If you import from a test file, then all the tests in that file will be run in each imported instance.\n    /// 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.\n    ///","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jest/no_export.rs#L1-L32","documentation":"This is oxlint's 'jest/no-export' diagnostic. It fires when a file that contains Jest tests (any recognized describe/test/it call from the jest plugin) also contains an ES export statement. Exporting from a test file invites other tests to import it, coupling suites together and causing double-execution or shared mutable state; the help suggests moving shared code into its own module.","triggerScenarios":"Enable the jest/no-export rule and lint a file where is_jest_file / iter_possible_jest_call_node finds a test or hook call AND the module record contains an export entry (export const ..., export function ...). Each export span gets the diagnostic.","commonSituations":"Test files that export helpers, fixtures, or mock factories 'for reuse by sibling tests' are the classic trigger — common in repos without a dedicated test-utils module. Also hit when a production module is accidentally renamed to a *.test.* file or a spec file gains an export during refactoring.","solutions":["Move the exported helpers/fixtures into a separate non-test module (e.g. test-utils.ts) and import them from the test files.","If the export is dead, delete it.","If the file is not really a test file, rename it so it no longer matches test file patterns.","For deliberate exceptions, disable the rule for that path via .oxlintrc.json overrides or an inline oxlint-disable comment."],"exampleFix":"// before (utils.test.ts)\nexport function makeUser() { return { id: 1 }; }\nit('creates user', () => { expect(makeUser().id).toBe(1); });\n\n// after (test-utils.ts)\nexport function makeUser() { return { id: 1 }; }\n\n// (utils.test.ts)\nimport { makeUser } from './test-utils';\nit('creates user', () => { expect(makeUser().id).toBe(1); });","handlingStrategy":"validation","validationCode":"// find exports inside test files\nconst { execSync } = require('node:child_process');\nconsole.log(execSync(\"rg -n '^\\\\s*export\\\\s+(const|function|class|default|\\\\{)' --glob '*.test.*' --glob '*.spec.*' tests/ src/\", { encoding: 'utf8' }));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a dedicated test-utils/helpers module for anything shared between spec files.","Never import from a *.test.* file; add a review rule against it.","Watch for accidental exports when renaming production files into test globs."],"tags":["lint","jest","testing","export","oxlint"],"backgroundTag":"export-from-test-file","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}