doc-detective 2.9.0-dev.1 → 2.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,204 +1,204 @@
1
- const { setArgs, setConfig, outputResults } = require("../src/utils");
2
- const path = require("path");
3
- const { expect, should, assert } = require("chai");
4
- const fs = require("fs");
5
-
6
- describe("Util tests", function () {
7
- // Test that arguments are parsed correctly
8
- it("Yargs parses arguments correctly", function () {
9
- const argSets = [
10
- {
11
- args: ["node", "runTests.js", "--input", "input.spec.json"],
12
- expected: { i: "input.spec.json" },
13
- },
14
- {
15
- args: [
16
- "node",
17
- "runTests.js",
18
- "--input",
19
- "input.spec.json",
20
- "--logLevel",
21
- "debug",
22
- ],
23
- expected: { i: "input.spec.json", l: "debug" },
24
- },
25
- {
26
- args: [
27
- "node",
28
- "runTests.js",
29
- "--input",
30
- "input.spec.json",
31
- "--logLevel",
32
- "debug",
33
- "--config",
34
- "config.json",
35
- ],
36
-
37
- expected: { i: "input.spec.json", l: "debug", c: "config.json" },
38
- },
39
- {
40
- args: [
41
- "node",
42
- "runTests.js",
43
- "--input",
44
- "input.spec.json",
45
- "--output",
46
- ".",
47
- "--logLevel",
48
- "debug",
49
- "--config",
50
- "config.json",
51
- ],
52
- expected: {
53
- i: "input.spec.json",
54
- o: ".",
55
- l: "debug",
56
- c: "config.json",
57
- },
58
- },
59
- {
60
- args: [
61
- "node",
62
- "runTests.js",
63
- "--input",
64
- "input.spec.json",
65
- "--output",
66
- ".",
67
- "--logLevel",
68
- "debug",
69
- "--config",
70
- "config.json",
71
- "--recursive",
72
- "false",
73
- "--setup",
74
- "setup.spec.json",
75
- "--cleanup",
76
- "cleanup.spec.json",
77
- ],
78
- expected: {
79
- i: "input.spec.json",
80
- o: ".",
81
- l: "debug",
82
- c: "config.json",
83
- r: "false",
84
- setup: "setup.spec.json",
85
- cleanup: "cleanup.spec.json",
86
- },
87
- },
88
- ];
89
- argSets.forEach((argSet) => {
90
- expect(setArgs(argSet.args)).to.deep.include(argSet.expected);
91
- });
92
- });
93
-
94
- // Test that config overrides are set correctly
95
- it("Config overrides are set correctly", function () {
96
- configSets = [
97
- {
98
- // Input override
99
- args: ["node", "runTests.js", "--input", "input.spec.json"],
100
- expected: { input: "input.spec.json" },
101
- },
102
- {
103
- // Input and logLevel overrides
104
- args: [
105
- "node",
106
- "runTests.js",
107
- "--input",
108
- "input.spec.json",
109
- "--logLevel",
110
- "debug",
111
- ],
112
- expected: { input: "input.spec.json", logLevel: "debug" },
113
- },
114
- {
115
- // Input, logLevel, and setup overrides
116
- args: [
117
- "node",
118
- "runTests.js",
119
- "--input",
120
- "input.spec.json",
121
- "--logLevel",
122
- "debug",
123
- "--setup",
124
- "setup.spec.json",
125
- ],
126
- expected: {
127
- input: "input.spec.json",
128
- logLevel: "debug",
129
- runTests: { setup: "setup.spec.json" },
130
- },
131
- },
132
- {
133
- // Referenced config without overrides
134
- args: ["node", "runTests.js", "--config", "./test/test-config.json"],
135
- expected: {
136
- input: ".",
137
- output: ".",
138
- logLevel: "silent",
139
- recursive: true,
140
- runTests: {
141
- setup: ".",
142
- cleanup: ".",
143
- },
144
- },
145
- },
146
- {
147
- // Referenced config with overrides
148
- args: [
149
- "node",
150
- "runTests.js",
151
- "--config",
152
- "./test/test-config.json",
153
- "--input",
154
- "input.spec.json",
155
- ],
156
- expected: {
157
- input: "input.spec.json",
158
- output: ".",
159
- logLevel: "silent",
160
- recursive: true,
161
- runTests: {
162
- setup: ".",
163
- cleanup: ".",
164
- },
165
- },
166
- },
167
- ];
168
-
169
- configSets.forEach((configSet) => {
170
- const configResult = setConfig({}, setArgs(configSet.args));
171
- deepObjectExpect(configResult, configSet.expected);
172
- });
173
- });
174
-
175
- // Test that results output correctly.
176
- it("Results output correctly", async () => {
177
- // Output test-results.json, make sure it exists, and clean it up.
178
- const inputResultsPath = path.resolve("./test/test-results.json");
179
- const inputResultsJSON = require(inputResultsPath);
180
- const outputResultsPath = path.resolve("./test/output-test-results.json");
181
- // Output results
182
- await outputResults(null, outputResultsPath, inputResultsJSON);
183
- // Check that output file exists
184
- expect(fs.existsSync(outputResultsPath)).to.equal(true);
185
- // Clean up
186
- fs.unlinkSync(outputResultsPath);
187
- });
188
- });
189
-
190
- // Deeply compares two objects
191
- function deepObjectExpect(actual, expected) {
192
- // Check that actual has all the keys of expected
193
- Object.entries(expected).forEach(([key, value]) => {
194
- // If value is an object, recursively check it
195
- if (typeof value === "object") {
196
- deepObjectExpect(actual[key], expected[key]);
197
- } else {
198
- // Otherwise, check that the value is correct
199
- const expectedObject = {};
200
- expectedObject[key] = value;
201
- expect(actual).to.deep.include(expectedObject);
202
- }
203
- });
204
- }
1
+ const { setArgs, setConfig, outputResults } = require("../src/utils");
2
+ const path = require("path");
3
+ const { expect, should, assert } = require("chai");
4
+ const fs = require("fs");
5
+
6
+ describe("Util tests", function () {
7
+ // Test that arguments are parsed correctly
8
+ it("Yargs parses arguments correctly", function () {
9
+ const argSets = [
10
+ {
11
+ args: ["node", "runTests.js", "--input", "input.spec.json"],
12
+ expected: { i: "input.spec.json" },
13
+ },
14
+ {
15
+ args: [
16
+ "node",
17
+ "runTests.js",
18
+ "--input",
19
+ "input.spec.json",
20
+ "--logLevel",
21
+ "debug",
22
+ ],
23
+ expected: { i: "input.spec.json", l: "debug" },
24
+ },
25
+ {
26
+ args: [
27
+ "node",
28
+ "runTests.js",
29
+ "--input",
30
+ "input.spec.json",
31
+ "--logLevel",
32
+ "debug",
33
+ "--config",
34
+ "config.json",
35
+ ],
36
+
37
+ expected: { i: "input.spec.json", l: "debug", c: "config.json" },
38
+ },
39
+ {
40
+ args: [
41
+ "node",
42
+ "runTests.js",
43
+ "--input",
44
+ "input.spec.json",
45
+ "--output",
46
+ ".",
47
+ "--logLevel",
48
+ "debug",
49
+ "--config",
50
+ "config.json",
51
+ ],
52
+ expected: {
53
+ i: "input.spec.json",
54
+ o: ".",
55
+ l: "debug",
56
+ c: "config.json",
57
+ },
58
+ },
59
+ {
60
+ args: [
61
+ "node",
62
+ "runTests.js",
63
+ "--input",
64
+ "input.spec.json",
65
+ "--output",
66
+ ".",
67
+ "--logLevel",
68
+ "debug",
69
+ "--config",
70
+ "config.json",
71
+ "--recursive",
72
+ "false",
73
+ "--setup",
74
+ "setup.spec.json",
75
+ "--cleanup",
76
+ "cleanup.spec.json",
77
+ ],
78
+ expected: {
79
+ i: "input.spec.json",
80
+ o: ".",
81
+ l: "debug",
82
+ c: "config.json",
83
+ r: "false",
84
+ setup: "setup.spec.json",
85
+ cleanup: "cleanup.spec.json",
86
+ },
87
+ },
88
+ ];
89
+ argSets.forEach((argSet) => {
90
+ expect(setArgs(argSet.args)).to.deep.include(argSet.expected);
91
+ });
92
+ });
93
+
94
+ // Test that config overrides are set correctly
95
+ it("Config overrides are set correctly", function () {
96
+ configSets = [
97
+ {
98
+ // Input override
99
+ args: ["node", "runTests.js", "--input", "input.spec.json"],
100
+ expected: { input: "input.spec.json" },
101
+ },
102
+ {
103
+ // Input and logLevel overrides
104
+ args: [
105
+ "node",
106
+ "runTests.js",
107
+ "--input",
108
+ "input.spec.json",
109
+ "--logLevel",
110
+ "debug",
111
+ ],
112
+ expected: { input: "input.spec.json", logLevel: "debug" },
113
+ },
114
+ {
115
+ // Input, logLevel, and setup overrides
116
+ args: [
117
+ "node",
118
+ "runTests.js",
119
+ "--input",
120
+ "input.spec.json",
121
+ "--logLevel",
122
+ "debug",
123
+ "--setup",
124
+ "setup.spec.json",
125
+ ],
126
+ expected: {
127
+ input: "input.spec.json",
128
+ logLevel: "debug",
129
+ runTests: { setup: "setup.spec.json" },
130
+ },
131
+ },
132
+ {
133
+ // Referenced config without overrides
134
+ args: ["node", "runTests.js", "--config", "./test/test-config.json"],
135
+ expected: {
136
+ input: ".",
137
+ output: ".",
138
+ logLevel: "silent",
139
+ recursive: true,
140
+ runTests: {
141
+ setup: ".",
142
+ cleanup: ".",
143
+ },
144
+ },
145
+ },
146
+ {
147
+ // Referenced config with overrides
148
+ args: [
149
+ "node",
150
+ "runTests.js",
151
+ "--config",
152
+ "./test/test-config.json",
153
+ "--input",
154
+ "input.spec.json",
155
+ ],
156
+ expected: {
157
+ input: "input.spec.json",
158
+ output: ".",
159
+ logLevel: "silent",
160
+ recursive: true,
161
+ runTests: {
162
+ setup: ".",
163
+ cleanup: ".",
164
+ },
165
+ },
166
+ },
167
+ ];
168
+
169
+ configSets.forEach((configSet) => {
170
+ const configResult = setConfig({}, setArgs(configSet.args));
171
+ deepObjectExpect(configResult, configSet.expected);
172
+ });
173
+ });
174
+
175
+ // Test that results output correctly.
176
+ it("Results output correctly", async () => {
177
+ // Output test-results.json, make sure it exists, and clean it up.
178
+ const inputResultsPath = path.resolve("./test/test-results.json");
179
+ const inputResultsJSON = require(inputResultsPath);
180
+ const outputResultsPath = path.resolve("./test/output-test-results.json");
181
+ // Output results
182
+ await outputResults(null, outputResultsPath, inputResultsJSON);
183
+ // Check that output file exists
184
+ expect(fs.existsSync(outputResultsPath)).to.equal(true);
185
+ // Clean up
186
+ fs.unlinkSync(outputResultsPath);
187
+ });
188
+ });
189
+
190
+ // Deeply compares two objects
191
+ function deepObjectExpect(actual, expected) {
192
+ // Check that actual has all the keys of expected
193
+ Object.entries(expected).forEach(([key, value]) => {
194
+ // If value is an object, recursively check it
195
+ if (typeof value === "object") {
196
+ deepObjectExpect(actual[key], expected[key]);
197
+ } else {
198
+ // Otherwise, check that the value is correct
199
+ const expectedObject = {};
200
+ expectedObject[key] = value;
201
+ expect(actual).to.deep.include(expectedObject);
202
+ }
203
+ });
204
+ }
Binary file
Binary file