/
linter.js
87 lines (70 loc) · 2.71 KB
/
linter.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
/**
* @fileoverview Test file for Linter class
* @author Gyandeep Singh
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const assert = require("chai").assert,
Linter = require("../../lib/linter");
//------------------------------------------------------------------------------
// Tests
// All the core logic has been tested inside eslint.js file
// Here we will be focusing more on the mutability portion of it
//------------------------------------------------------------------------------
/**
* extract the keys into an array
* @param {Map} mapObj - Map type object
* @returns {Array<*>} collection of all the keys
* @private
*/
function extractMapKeys(mapObj) {
const keys = [];
for (const key of mapObj.keys()) {
keys.push(key);
}
return keys;
}
describe("Linter", () => {
describe("mutability", () => {
let linter1 = null;
let linter2 = null;
beforeEach(() => {
linter1 = new Linter();
linter2 = new Linter();
});
describe("rules", () => {
it("with no changes, same rules are loaded", () => {
assert.sameDeepMembers(extractMapKeys(linter1.getRules()), extractMapKeys(linter2.getRules()));
});
it("loading rule in one doesnt change the other", () => {
linter1.defineRule("mock-rule", () => ({}));
assert.isTrue(linter1.getRules().has("mock-rule"), "mock rule is present");
assert.isFalse(linter2.getRules().has("mock-rule"), "mock rule is not present");
});
});
describe("environments", () => {
it("with no changes same env are loaded", () => {
assert.sameDeepMembers([linter1.environments.getAll()], [linter2.environments.getAll()]);
});
it("defining env in one doesnt change the other", () => {
linter1.environments.define("mock-env", true);
assert.isTrue(linter1.environments.get("mock-env"), "mock env is present");
assert.isNull(linter2.environments.get("mock-env"), "mock env is not present");
});
});
});
describe("verifyAndFix", () => {
it("Fixes the code", () => {
const linter = new Linter();
const messages = linter.verifyAndFix("var a", {
rules: {
semi: 2
}
}, { filename: "test.js" });
assert.equal(messages.output, "var a;", "Fixes were applied correctly");
assert.isTrue(messages.fixed);
});
});
});