-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
api.js
91 lines (68 loc) · 2.82 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* @fileoverview Tests for api.
* @author Gyandeep Singh
*/
"use strict";
//-----------------------------------------------------------------------------
// Requirements
//-----------------------------------------------------------------------------
const assert = require("chai").assert,
api = require("../../lib/api"),
{ FlatESLint } = require("../../lib/eslint"),
os = require("os");
//-----------------------------------------------------------------------------
// Tests
//-----------------------------------------------------------------------------
describe("api", () => {
it("should have ESLint exposed", () => {
assert.isFunction(api.ESLint);
});
it("should have RuleTester exposed", () => {
assert.isFunction(api.RuleTester);
});
it("should not have CLIEngine exposed", () => {
assert.isUndefined(api.CLIEngine);
});
it("should not have linter exposed", () => {
assert.isUndefined(api.linter);
});
it("should have Linter exposed", () => {
assert.isFunction(api.Linter);
});
it("should have SourceCode exposed", () => {
assert.isFunction(api.SourceCode);
});
describe("loadESLint", () => {
afterEach(() => {
delete process.env.ESLINT_USE_FLAT_CONFIG;
});
it("should be a function", () => {
assert.isFunction(api.loadESLint);
});
it("should return a Promise", () => {
assert.instanceOf(api.loadESLint(), Promise);
});
it("should return FlatESLint when useFlatConfig is true", async () => {
assert.strictEqual(await api.loadESLint({ useFlatConfig: true }), FlatESLint);
});
it("should return ESLint when useFlatConfig is false", async () => {
assert.strictEqual(await api.loadESLint({ useFlatConfig: false }), api.ESLint);
});
it("should return FlatESLint when useFlatConfig is not provided because we have eslint.config.js", async () => {
assert.strictEqual(await api.loadESLint(), FlatESLint);
});
it("should return ESLint when useFlatConfig is not provided and there is no eslint.config.js", async () => {
assert.strictEqual(await api.loadESLint({
cwd: os.tmpdir()
}), api.ESLint);
});
it("should return ESLint when useFlatConfig is not provided and ESLINT_USE_FLAT_CONFIG is false", async () => {
process.env.ESLINT_USE_FLAT_CONFIG = "false";
assert.strictEqual(await api.loadESLint(), api.ESLint);
});
it("should return FlatESLint when useFlatConfig is not provided and ESLINT_USE_FLAT_CONFIG is true", async () => {
process.env.ESLINT_USE_FLAT_CONFIG = "true";
assert.strictEqual(await api.loadESLint(), FlatESLint);
});
});
});