| 1 | import { ESLint } from "eslint"; |
| 2 | import path from "path"; |
| 3 | import { fileURLToPath } from "url"; |
| 4 | import fs from "fs"; |
| 5 | |
| 6 | let USE_ESM = false; |
| 7 | try { |
| 8 | const type = fs |
| 9 | .readFileSync(new URL("../../../../.module-type", import.meta.url), "utf-8") |
| 10 | .trim(); |
| 11 | USE_ESM = type === "module"; |
| 12 | } catch {} |
| 13 | |
| 14 | describe("Babel config files", () => { |
| 15 | const itESM = USE_ESM ? it : it.skip; |
| 16 | const itNode12upNoESM = |
| 17 | USE_ESM || parseInt(process.versions.node) < 12 ? it.skip : it; |
| 18 | |
| 19 | itESM("works with babel.config.mjs", async () => { |
| 20 | const engine = new ESLint({ ignore: false }); |
| 21 | expect( |
| 22 | await engine.lintFiles([ |
| 23 | path.resolve( |
| 24 | path.dirname(fileURLToPath(import.meta.url)), |
| 25 | `../fixtures/mjs-config-file/a.js`, |
| 26 | ), |
| 27 | ]), |
| 28 | ).toMatchObject([{ errorCount: 0 }]); |
| 29 | }); |
| 30 | |
| 31 | itNode12upNoESM( |
| 32 | "experimental worker works with babel.config.mjs", |
| 33 | async () => { |
| 34 | const engine = new ESLint({ ignore: false }); |
| 35 | expect( |
| 36 | await engine.lintFiles( |
| 37 | path.resolve( |
| 38 | path.dirname(fileURLToPath(import.meta.url)), |
| 39 | `../fixtures/mjs-config-file-babel-7/a.js`, |
| 40 | ), |
| 41 | ), |
| 42 | ).toMatchObject([{ errorCount: 0 }]); |
| 43 | }, |
| 44 | ); |
| 45 | }); |