|
| 1 | +import path from "path"; |
| 2 | +import { RuleTester } from "eslint"; |
| 3 | +import { describe, it } from "vitest"; |
| 4 | +import tsParser from "@typescript-eslint/parser"; |
| 5 | +import rule from "./no-config-imports.js"; |
| 6 | + |
| 7 | +const ROOT = process.cwd(); |
| 8 | +const resolve = (p) => path.resolve(ROOT, p); |
| 9 | + |
| 10 | +const ruleTester = new RuleTester({ |
| 11 | + languageOptions: { |
| 12 | + parser: tsParser, |
| 13 | + parserOptions: { ecmaVersion: 2022, sourceType: "module" }, |
| 14 | + }, |
| 15 | +}); |
| 16 | + |
| 17 | +describe("no-config-imports", () => { |
| 18 | + it("should not report any violations", () => { |
| 19 | + ruleTester.run("no-config-imports", rule, { |
| 20 | + valid: [ |
| 21 | + { |
| 22 | + filename: resolve("src/some/module.ts"), |
| 23 | + code: 'import type { UserConfig } from "../common/config.js";\n', |
| 24 | + }, |
| 25 | + { |
| 26 | + filename: resolve("src/some/module.ts"), |
| 27 | + code: 'import { something } from "../common/logger.js";\n', |
| 28 | + }, |
| 29 | + { |
| 30 | + filename: resolve("src/some/module.ts"), |
| 31 | + code: 'import type * as Cfg from "../common/config.js";\n', |
| 32 | + }, |
| 33 | + { |
| 34 | + filename: resolve("src/index.ts"), |
| 35 | + code: 'import { driverOptions } from "../common/config.js";\n', |
| 36 | + }, |
| 37 | + ], |
| 38 | + invalid: [], |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + it("should report rule violations", () => { |
| 43 | + ruleTester.run("no-config-imports", rule, { |
| 44 | + valid: [], |
| 45 | + invalid: [ |
| 46 | + { |
| 47 | + filename: resolve("src/another/module.ts"), |
| 48 | + code: 'import { driverOptions } from "../common/config.js";\n', |
| 49 | + errors: [{ messageId: "noConfigImports" }], |
| 50 | + }, |
| 51 | + { |
| 52 | + filename: resolve("src/another/module.ts"), |
| 53 | + code: 'import configDefault from "../common/config.js";\n', |
| 54 | + errors: [{ messageId: "noConfigImports" }], |
| 55 | + }, |
| 56 | + { |
| 57 | + filename: resolve("src/another/module.ts"), |
| 58 | + code: 'import * as cfg from "../common/config.js";\n', |
| 59 | + errors: [{ messageId: "noConfigImports" }], |
| 60 | + }, |
| 61 | + { |
| 62 | + filename: resolve("src/another/module.ts"), |
| 63 | + code: 'import { type UserConfig, driverOptions } from "../common/config.js";\n', |
| 64 | + errors: [{ messageId: "noConfigImports" }], |
| 65 | + }, |
| 66 | + ], |
| 67 | + }); |
| 68 | + }); |
| 69 | +}); |
0 commit comments