|
10 | 10 | //-----------------------------------------------------------------------------
|
11 | 11 |
|
12 | 12 | const assert = require("chai").assert,
|
13 |
| - api = require("../../lib/api"); |
| 13 | + api = require("../../lib/api"), |
| 14 | + { LegacyESLint } = require("../../lib/eslint/legacy-eslint"); |
14 | 15 |
|
15 | 16 | //-----------------------------------------------------------------------------
|
16 | 17 | // Tests
|
@@ -41,4 +42,42 @@ describe("api", () => {
|
41 | 42 | it("should have SourceCode exposed", () => {
|
42 | 43 | assert.isFunction(api.SourceCode);
|
43 | 44 | });
|
| 45 | + |
| 46 | + describe("loadESLint", () => { |
| 47 | + |
| 48 | + afterEach(() => { |
| 49 | + delete process.env.ESLINT_USE_FLAT_CONFIG; |
| 50 | + }); |
| 51 | + |
| 52 | + it("should be a function", () => { |
| 53 | + assert.isFunction(api.loadESLint); |
| 54 | + }); |
| 55 | + |
| 56 | + it("should return a Promise", () => { |
| 57 | + assert.instanceOf(api.loadESLint(), Promise); |
| 58 | + }); |
| 59 | + |
| 60 | + it("should return ESLint when useFlatConfig is true", async () => { |
| 61 | + assert.strictEqual(await api.loadESLint({ useFlatConfig: true }), api.ESLint); |
| 62 | + }); |
| 63 | + |
| 64 | + it("should return LegacyESLint when useFlatConfig is false", async () => { |
| 65 | + assert.strictEqual(await api.loadESLint({ useFlatConfig: false }), LegacyESLint); |
| 66 | + }); |
| 67 | + |
| 68 | + it("should return ESLint when useFlatConfig is not provided", async () => { |
| 69 | + assert.strictEqual(await api.loadESLint(), api.ESLint); |
| 70 | + }); |
| 71 | + |
| 72 | + it("should return LegacyESLint when useFlatConfig is not provided and ESLINT_USE_FLAT_CONFIG is false", async () => { |
| 73 | + process.env.ESLINT_USE_FLAT_CONFIG = "false"; |
| 74 | + assert.strictEqual(await api.loadESLint(), LegacyESLint); |
| 75 | + }); |
| 76 | + |
| 77 | + it("should return ESLint when useFlatConfig is not provided and ESLINT_USE_FLAT_CONFIG is true", async () => { |
| 78 | + process.env.ESLINT_USE_FLAT_CONFIG = "true"; |
| 79 | + assert.strictEqual(await api.loadESLint(), api.ESLint); |
| 80 | + }); |
| 81 | + }); |
| 82 | + |
44 | 83 | });
|
0 commit comments