doc-detective 3.4.0-dev.1 → 3.4.0-dev.2
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.
- package/package.json +3 -3
- package/reference.png +0 -0
- package/src/utils.js +25 -0
- package/test/utils.test.js +53 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doc-detective",
|
|
3
|
-
"version": "3.4.0-dev.
|
|
3
|
+
"version": "3.4.0-dev.2",
|
|
4
4
|
"description": "Treat doc content as testable assertions to validate doc accuracy and product UX.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"doc-detective": "src/index.js"
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"homepage": "https://github.com/doc-detective/doc-detective#readme",
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@ffmpeg-installer/ffmpeg": "^1.1.0",
|
|
36
|
-
"doc-detective-common": "^3.4.0
|
|
37
|
-
"doc-detective-core": "^3.4.0
|
|
36
|
+
"doc-detective-common": "^3.4.0",
|
|
37
|
+
"doc-detective-core": "^3.4.0",
|
|
38
38
|
"yargs": "^17.7.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
package/reference.png
CHANGED
|
Binary file
|
package/src/utils.js
CHANGED
|
@@ -67,6 +67,31 @@ async function setConfig({ configPath, args }) {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
// Check for DOC_DETECTIVE_CONFIG environment variable
|
|
71
|
+
if (process.env.DOC_DETECTIVE_CONFIG) {
|
|
72
|
+
try {
|
|
73
|
+
// Parse the environment variable as JSON
|
|
74
|
+
const envConfig = JSON.parse(process.env.DOC_DETECTIVE_CONFIG);
|
|
75
|
+
|
|
76
|
+
// Validate the environment variable config
|
|
77
|
+
const envValidation = validate({
|
|
78
|
+
schemaKey: "config_v3",
|
|
79
|
+
object: envConfig,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (!envValidation.valid) {
|
|
83
|
+
console.error("Invalid config from DOC_DETECTIVE_CONFIG environment variable.", envValidation.errors);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Merge with file config, preferring environment variable config (use raw envConfig, not validated with defaults)
|
|
88
|
+
config = { ...config, ...envConfig };
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error(`Error parsing DOC_DETECTIVE_CONFIG environment variable: ${error.message}`);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
70
95
|
// Validate config
|
|
71
96
|
const validation = validate({
|
|
72
97
|
schemaKey: "config_v3",
|
package/test/utils.test.js
CHANGED
|
@@ -204,6 +204,59 @@ describe("Util tests", function () {
|
|
|
204
204
|
// Clean up
|
|
205
205
|
fs.unlinkSync(outputResultsPath);
|
|
206
206
|
});
|
|
207
|
+
|
|
208
|
+
// Test environment variable config detection
|
|
209
|
+
it("Config from DOC_DETECTIVE_CONFIG environment variable is loaded and merged", async function () {
|
|
210
|
+
this.timeout(5000);
|
|
211
|
+
|
|
212
|
+
// Save the original environment variable value
|
|
213
|
+
const originalEnvConfig = process.env.DOC_DETECTIVE_CONFIG;
|
|
214
|
+
|
|
215
|
+
try {
|
|
216
|
+
// Test 1: Valid environment variable config without file config
|
|
217
|
+
process.env.DOC_DETECTIVE_CONFIG = JSON.stringify({
|
|
218
|
+
logLevel: "debug"
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const config1 = await setConfig({ args: setArgs(["node", "runTests.js"]) });
|
|
222
|
+
expect(config1.logLevel).to.equal("debug");
|
|
223
|
+
|
|
224
|
+
// Test 2: Environment variable config merged with file config (env var takes precedence)
|
|
225
|
+
process.env.DOC_DETECTIVE_CONFIG = JSON.stringify({
|
|
226
|
+
logLevel: "error"
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
const config2 = await setConfig({
|
|
230
|
+
configPath: "./test/test-config.json",
|
|
231
|
+
args: setArgs(["node", "runTests.js", "--config", "./test/test-config.json"])
|
|
232
|
+
});
|
|
233
|
+
// Environment variable should override file config
|
|
234
|
+
expect(config2.logLevel).to.equal("error");
|
|
235
|
+
// Check that other values from file config are preserved
|
|
236
|
+
expect(config2.telemetry.send).to.equal(false);
|
|
237
|
+
|
|
238
|
+
// Test 3: Environment variable config with command line args (args take precedence)
|
|
239
|
+
process.env.DOC_DETECTIVE_CONFIG = JSON.stringify({
|
|
240
|
+
logLevel: "warning",
|
|
241
|
+
input: "env-input.json"
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
const config3 = await setConfig({
|
|
245
|
+
args: setArgs(["node", "runTests.js", "--input", "cli-input.json", "--logLevel", "debug"])
|
|
246
|
+
});
|
|
247
|
+
// Command line args should override environment variable
|
|
248
|
+
expect(config3.logLevel).to.equal("debug");
|
|
249
|
+
expect(config3.input).to.deep.equal([path.resolve(process.cwd(), "cli-input.json")]);
|
|
250
|
+
|
|
251
|
+
} finally {
|
|
252
|
+
// Restore the original environment variable value
|
|
253
|
+
if (originalEnvConfig !== undefined) {
|
|
254
|
+
process.env.DOC_DETECTIVE_CONFIG = originalEnvConfig;
|
|
255
|
+
} else {
|
|
256
|
+
delete process.env.DOC_DETECTIVE_CONFIG;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
});
|
|
207
260
|
});
|
|
208
261
|
|
|
209
262
|
// Deeply compares two objects
|