]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/shared/config-ops.js
2 * @fileoverview Tests for ConfigOps
3 * @author Nicholas C. Zakas
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
11 const assert
= require("chai").assert
,
12 leche
= require("leche"),
13 util
= require("util"),
14 ConfigOps
= require("../../../lib/shared/config-ops");
16 //------------------------------------------------------------------------------
18 //------------------------------------------------------------------------------
20 describe("ConfigOps", () => {
22 describe("getRuleSeverity()", () => {
23 const EXPECTED_RESULTS
= new Map([
39 ["invalid config", 0],
40 [["invalid config"], 0],
47 for (const key
of EXPECTED_RESULTS
.keys()) {
48 it(`returns ${util.inspect(EXPECTED_RESULTS.get(key))} for ${util.inspect(key)}`, () => {
49 assert
.strictEqual(ConfigOps
.getRuleSeverity(key
), EXPECTED_RESULTS
.get(key
));
54 describe("normalizeToStrings()", () => {
55 it("should convert 2 rule setting to error when rule has just a severity", () => {
63 ConfigOps
.normalizeToStrings(config
);
65 assert
.deepStrictEqual(config
, {
73 it("should convert 2 rule setting to error when rule has array with severity", () => {
76 foo
: [2, "something"],
81 ConfigOps
.normalizeToStrings(config
);
83 assert
.deepStrictEqual(config
, {
85 foo
: ["error", "something"],
91 it("should convert 1 rule setting to warn when rule has just a severity", () => {
99 ConfigOps
.normalizeToStrings(config
);
101 assert
.deepStrictEqual(config
, {
109 it("should convert 1 rule setting to warn when rule has array with severity", () => {
112 foo
: [1, "something"],
117 ConfigOps
.normalizeToStrings(config
);
119 assert
.deepStrictEqual(config
, {
121 foo
: ["warn", "something"],
127 it("should convert 0 rule setting to off when rule has just a severity", () => {
135 ConfigOps
.normalizeToStrings(config
);
137 assert
.deepStrictEqual(config
, {
145 it("should convert 0 rule setting to off when rule has array with severity", () => {
148 foo
: [0, "something"],
153 ConfigOps
.normalizeToStrings(config
);
155 assert
.deepStrictEqual(config
, {
157 foo
: ["off", "something"],
163 it("should convert 256 rule setting to off when rule has just a severity", () => {
171 ConfigOps
.normalizeToStrings(config
);
173 assert
.deepStrictEqual(config
, {
181 it("should convert 256 rule setting to off when rule has array with severity", () => {
184 foo
: [256, "something"],
189 ConfigOps
.normalizeToStrings(config
);
191 assert
.deepStrictEqual(config
, {
193 foo
: ["off", "something"],
200 describe("isError()", () => {
209 [["error", "foo"], true],
210 [["eRror", "bar"], true],
212 ], (input
, expected
) => {
214 it(`should return ${expected}when passed ${input}`, () => {
215 const result
= ConfigOps
.isErrorSeverity(input
);
217 assert
.strictEqual(result
, expected
);
224 describe("normalizeConfigGlobal", () => {
228 ["true", "writable"],
230 ["false", "readonly"],
232 ["writeable", "writable"],
233 ["writable", "writable"],
234 ["readable", "readonly"],
235 ["readonly", "readonly"],
236 ["writable", "writable"]
237 ].forEach(([input
, output
]) => {
238 it(util
.inspect(input
), () => {
239 assert
.strictEqual(ConfigOps
.normalizeConfigGlobal(input
), output
);
243 it("throws on other inputs", () => {
245 () => ConfigOps
.normalizeConfigGlobal("something else"),
246 /^'something else' is not a valid configuration for a global \(use 'readonly', 'writable', or 'off'\)$/u