/
extracted-config.js
151 lines (109 loc) · 4.56 KB
/
extracted-config.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* STOP!!! DO NOT MODIFY.
*
* This file is part of the ongoing work to move the eslintrc-style config
* system into the @eslint/eslintrc package. This file needs to remain
* unchanged in order for this work to proceed.
*
* If you think you need to change this file, please contact @nzakas first.
*
* Thanks in advance for your cooperation.
*/
/**
* @fileoverview Tests for ExtractedConfig class.
* @author Toru Nagashima <https://github.com/mysticatea>
*/
"use strict";
const assert = require("assert");
const { ExtractedConfig } = require("../../../../lib/cli-engine/config-array/extracted-config");
describe("'ExtractedConfig' class", () => {
describe("'constructor()' should create an instance.", () => {
/** @type {ExtractedConfig} */
let config;
beforeEach(() => {
config = new ExtractedConfig();
});
it("should have 'env' property.", () => {
assert.deepStrictEqual(config.env, {});
});
it("should have 'globals' property.", () => {
assert.deepStrictEqual(config.globals, {});
});
it("should have 'parser' property.", () => {
assert.deepStrictEqual(config.parser, null);
});
it("should have 'parserOptions' property.", () => {
assert.deepStrictEqual(config.parserOptions, {});
});
it("should have 'plugins' property.", () => {
assert.deepStrictEqual(config.plugins, {});
});
it("should have 'processor' property.", () => {
assert.deepStrictEqual(config.processor, null);
});
it("should have 'rules' property.", () => {
assert.deepStrictEqual(config.rules, {});
});
it("should have 'settings' property.", () => {
assert.deepStrictEqual(config.settings, {});
});
});
describe("'toCompatibleObjectAsConfigFileContent()' method should return a valid config data.", () => {
/** @type {ExtractedConfig} */
let config;
beforeEach(() => {
config = new ExtractedConfig();
});
it("should use 'env' property as is.", () => {
config.env = { a: true };
const data = config.toCompatibleObjectAsConfigFileContent();
assert.deepStrictEqual(data.env, { a: true });
});
it("should use 'globals' as is.", () => {
config.globals = { a: true };
const data = config.toCompatibleObjectAsConfigFileContent();
assert.deepStrictEqual(data.globals, { a: true });
});
it("should use 'parser.filePath' for 'parser' property.", () => {
config.parser = {
definition: {},
error: null,
filePath: "/path/to/a/parser",
id: "parser",
importerName: "importer name",
importerPath: "importer path"
};
const data = config.toCompatibleObjectAsConfigFileContent();
assert.deepStrictEqual(data.parser, "/path/to/a/parser");
});
it("should use 'null' for 'parser' property if 'parser' property is 'null'.", () => {
const data = config.toCompatibleObjectAsConfigFileContent();
assert.deepStrictEqual(data.parser, null);
});
it("should use 'parserOptions' property as is.", () => {
config.parserOptions = { a: true };
const data = config.toCompatibleObjectAsConfigFileContent();
assert.deepStrictEqual(data.parserOptions, { a: true });
});
it("should use the keys of 'plugins' property for 'plugins' property.", () => {
config.plugins = { a: {}, b: {} };
const data = config.toCompatibleObjectAsConfigFileContent();
assert.deepStrictEqual(data.plugins, ["b", "a"]);
});
it("should not use 'processor' property.", () => {
config.processor = "foo/.md";
const data = config.toCompatibleObjectAsConfigFileContent();
assert.deepStrictEqual(data.processor, void 0);
});
it("should use 'rules' property as is.", () => {
config.rules = { a: 1, b: 2 };
const data = config.toCompatibleObjectAsConfigFileContent();
assert.deepStrictEqual(data.rules, { a: 1, b: 2 });
});
it("should use 'settings' property as is.", () => {
config.settings = { a: 1 };
const data = config.toCompatibleObjectAsConfigFileContent();
assert.deepStrictEqual(data.settings, { a: 1 });
});
});
});