doc-detective 3.1.2-dev.3 → 3.1.3-dev.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.
- package/package.json +2 -2
- package/reference.png +0 -0
- package/src/index.js +8 -3
- package/src/utils.js +146 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doc-detective",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3-dev.1",
|
|
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"
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@ffmpeg-installer/ffmpeg": "^1.1.0",
|
|
36
36
|
"doc-detective-common": "^3.1.1",
|
|
37
|
-
"doc-detective-core": "^3.1.1",
|
|
37
|
+
"doc-detective-core": "^3.1.3-dev.1",
|
|
38
38
|
"yargs": "^17.7.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
package/reference.png
CHANGED
|
Binary file
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const { runTests, runCoverage } = require("doc-detective-core");
|
|
4
|
-
const {
|
|
5
|
-
const { setArgs, setConfig, outputResults, setMeta } = require("./utils");
|
|
4
|
+
const { setArgs, setConfig, outputResults, setMeta, getVersionData, log } = require("./utils");
|
|
6
5
|
const { argv } = require("node:process");
|
|
7
6
|
const path = require("path");
|
|
8
7
|
const fs = require("fs");
|
|
@@ -37,10 +36,16 @@ async function main(argv) {
|
|
|
37
36
|
// Set config
|
|
38
37
|
const config = await setConfig({ configPath: configPath, args: argv });
|
|
39
38
|
|
|
39
|
+
if (config.logLevel === "debug") {
|
|
40
|
+
console.log(`CLI:VERSION INFO:\n${JSON.stringify(getVersionData(), null, 2)}`);
|
|
41
|
+
console.log(`CLI:CONFIG:\n${JSON.stringify(config, null, 2)}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
40
44
|
// Run tests
|
|
41
45
|
const output = config.output;
|
|
42
46
|
const results = await runTests(config);
|
|
43
47
|
|
|
44
48
|
// Output results
|
|
45
49
|
await outputResults(config, output, results, { command: "runTests" });
|
|
46
|
-
|
|
50
|
+
|
|
51
|
+
}
|
package/src/utils.js
CHANGED
|
@@ -11,6 +11,7 @@ exports.setConfig = setConfig;
|
|
|
11
11
|
exports.outputResults = outputResults;
|
|
12
12
|
exports.spawnCommand = spawnCommand;
|
|
13
13
|
exports.setMeta = setMeta;
|
|
14
|
+
exports.getVersionData = getVersionData;
|
|
14
15
|
|
|
15
16
|
// Define args
|
|
16
17
|
function setArgs(args) {
|
|
@@ -40,8 +41,7 @@ function setArgs(args) {
|
|
|
40
41
|
type: "string",
|
|
41
42
|
})
|
|
42
43
|
.option("allow-unsafe", {
|
|
43
|
-
description:
|
|
44
|
-
"Allow execution of potentially unsafe tests",
|
|
44
|
+
description: "Allow execution of potentially unsafe tests",
|
|
45
45
|
type: "boolean",
|
|
46
46
|
})
|
|
47
47
|
.help()
|
|
@@ -257,7 +257,9 @@ const reporters = {
|
|
|
257
257
|
`${colors.yellow}Warnings: ${specs.warning}${colors.reset}`
|
|
258
258
|
);
|
|
259
259
|
if (specs.skipped > 0)
|
|
260
|
-
console.log(
|
|
260
|
+
console.log(
|
|
261
|
+
`${colors.yellow}Skipped: ${specs.skipped}${colors.reset}`
|
|
262
|
+
);
|
|
261
263
|
}
|
|
262
264
|
|
|
263
265
|
// Print tests summary if available
|
|
@@ -279,7 +281,9 @@ const reporters = {
|
|
|
279
281
|
`${colors.yellow}Warnings: ${tests.warning}${colors.reset}`
|
|
280
282
|
);
|
|
281
283
|
if (tests.skipped > 0)
|
|
282
|
-
console.log(
|
|
284
|
+
console.log(
|
|
285
|
+
`${colors.yellow}Skipped: ${tests.skipped}${colors.reset}`
|
|
286
|
+
);
|
|
283
287
|
}
|
|
284
288
|
|
|
285
289
|
// Print contexts summary if available
|
|
@@ -301,7 +305,9 @@ const reporters = {
|
|
|
301
305
|
`${colors.yellow}Warnings: ${contexts.warning}${colors.reset}`
|
|
302
306
|
);
|
|
303
307
|
if (contexts.skipped > 0)
|
|
304
|
-
console.log(
|
|
308
|
+
console.log(
|
|
309
|
+
`${colors.yellow}Skipped: ${contexts.skipped}${colors.reset}`
|
|
310
|
+
);
|
|
305
311
|
}
|
|
306
312
|
|
|
307
313
|
// Print steps summary if available
|
|
@@ -323,12 +329,16 @@ const reporters = {
|
|
|
323
329
|
`${colors.yellow}Warnings: ${steps.warning}${colors.reset}`
|
|
324
330
|
);
|
|
325
331
|
if (steps.skipped > 0)
|
|
326
|
-
console.log(
|
|
332
|
+
console.log(
|
|
333
|
+
`${colors.yellow}Skipped: ${steps.skipped}${colors.reset}`
|
|
334
|
+
);
|
|
327
335
|
}
|
|
328
336
|
|
|
329
337
|
// If all specs were skipped, call it out
|
|
330
338
|
if (allSpecsSkipped) {
|
|
331
|
-
console.log(
|
|
339
|
+
console.log(
|
|
340
|
+
`\n${colors.yellow}⚠️ All items were skipped. No specs passed or failed. ⚠️${colors.reset}`
|
|
341
|
+
);
|
|
332
342
|
}
|
|
333
343
|
|
|
334
344
|
// If we have specs with failures, display them
|
|
@@ -522,19 +532,31 @@ const reporters = {
|
|
|
522
532
|
if (skippedTests.length > 0) {
|
|
523
533
|
console.log(`\n${colors.yellow}Skipped Tests:${colors.reset}`);
|
|
524
534
|
skippedTests.forEach((item, i) => {
|
|
525
|
-
console.log(
|
|
535
|
+
console.log(
|
|
536
|
+
`${colors.yellow}${i + 1}. ${item.id} (from ${item.specId})${
|
|
537
|
+
colors.reset
|
|
538
|
+
}`
|
|
539
|
+
);
|
|
526
540
|
});
|
|
527
541
|
}
|
|
528
542
|
if (skippedContexts.length > 0) {
|
|
529
543
|
console.log(`\n${colors.yellow}Skipped Contexts:${colors.reset}`);
|
|
530
544
|
skippedContexts.forEach((item, i) => {
|
|
531
|
-
console.log(
|
|
545
|
+
console.log(
|
|
546
|
+
`${colors.yellow}${i + 1}. ${item.platform}/${
|
|
547
|
+
item.browser
|
|
548
|
+
} (from ${item.testId})${colors.reset}`
|
|
549
|
+
);
|
|
532
550
|
});
|
|
533
551
|
}
|
|
534
552
|
if (skippedSteps.length > 0) {
|
|
535
553
|
console.log(`\n${colors.yellow}Skipped Steps:${colors.reset}`);
|
|
536
554
|
skippedSteps.forEach((item, i) => {
|
|
537
|
-
console.log(
|
|
555
|
+
console.log(
|
|
556
|
+
`${colors.yellow}${i + 1}. ${item.platform}/${item.browser} - ${
|
|
557
|
+
item.stepId
|
|
558
|
+
}${colors.reset}`
|
|
559
|
+
);
|
|
538
560
|
});
|
|
539
561
|
}
|
|
540
562
|
} else if (!hasFailures && !allSpecsSkipped) {
|
|
@@ -681,3 +703,117 @@ function setMeta() {
|
|
|
681
703
|
meta.dist_interface = meta.dist_interface || "cli";
|
|
682
704
|
process.env["DOC_DETECTIVE_META"] = JSON.stringify(meta);
|
|
683
705
|
}
|
|
706
|
+
|
|
707
|
+
// Get version data programmatically (no console output)
|
|
708
|
+
function getVersionData() {
|
|
709
|
+
try {
|
|
710
|
+
// Get main package version
|
|
711
|
+
const mainPackage = require("../package.json");
|
|
712
|
+
const versionData = {
|
|
713
|
+
main: {
|
|
714
|
+
"doc-detective": {
|
|
715
|
+
version: mainPackage.version,
|
|
716
|
+
expected: "main package",
|
|
717
|
+
},
|
|
718
|
+
},
|
|
719
|
+
dependencies: {},
|
|
720
|
+
context: {
|
|
721
|
+
executionMethod: "direct node execution",
|
|
722
|
+
nodeVersion: process.version,
|
|
723
|
+
platform: `${os.platform()} ${os.arch()}`,
|
|
724
|
+
timestamp: new Date().toISOString(),
|
|
725
|
+
},
|
|
726
|
+
locations: {},
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
// Auto-discover all doc-detective-* packages in node_modules
|
|
730
|
+
const nodeModulesPath = path.resolve(process.cwd(), "node_modules");
|
|
731
|
+
const dependenciesToCheck = [];
|
|
732
|
+
|
|
733
|
+
if (fs.existsSync(nodeModulesPath)) {
|
|
734
|
+
const nodeModulesContents = fs.readdirSync(nodeModulesPath);
|
|
735
|
+
nodeModulesContents.forEach((dir) => {
|
|
736
|
+
if (dir.startsWith("doc-detective-") && dir !== "doc-detective") {
|
|
737
|
+
dependenciesToCheck.push(dir);
|
|
738
|
+
}
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// Detect execution method
|
|
743
|
+
const isNpx =
|
|
744
|
+
process.env.npm_execpath && process.env.npm_execpath.includes("npx");
|
|
745
|
+
const isNpm = process.env.npm_execpath && !isNpx;
|
|
746
|
+
|
|
747
|
+
if (isNpx) {
|
|
748
|
+
versionData.context.executionMethod = "npx";
|
|
749
|
+
} else if (isNpm) {
|
|
750
|
+
versionData.context.executionMethod = "npm";
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// Check installed versions of dependencies
|
|
754
|
+
dependenciesToCheck.sort().forEach((dep) => {
|
|
755
|
+
try {
|
|
756
|
+
// Try to read the dependency's package.json
|
|
757
|
+
const depPackagePath = path.resolve(
|
|
758
|
+
process.cwd(),
|
|
759
|
+
"node_modules",
|
|
760
|
+
dep,
|
|
761
|
+
"package.json"
|
|
762
|
+
);
|
|
763
|
+
if (fs.existsSync(depPackagePath)) {
|
|
764
|
+
const depPackage = JSON.parse(
|
|
765
|
+
fs.readFileSync(depPackagePath, "utf8")
|
|
766
|
+
);
|
|
767
|
+
const installedVersion = depPackage.version;
|
|
768
|
+
|
|
769
|
+
// Look for expected version in main package dependencies or devDependencies
|
|
770
|
+
const expectedVersion =
|
|
771
|
+
mainPackage.dependencies[dep] ||
|
|
772
|
+
mainPackage.devDependencies[dep] ||
|
|
773
|
+
"not specified in main package";
|
|
774
|
+
|
|
775
|
+
versionData.dependencies[dep] = {
|
|
776
|
+
installed: installedVersion,
|
|
777
|
+
expected: expectedVersion,
|
|
778
|
+
status:
|
|
779
|
+
expectedVersion !== "not specified in main package" &&
|
|
780
|
+
!expectedVersion.includes(installedVersion) &&
|
|
781
|
+
!installedVersion.includes(expectedVersion.replace(/[\^~]/, ""))
|
|
782
|
+
? "mismatch"
|
|
783
|
+
: "ok",
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
versionData.locations[dep] = path.resolve(
|
|
787
|
+
process.cwd(),
|
|
788
|
+
"node_modules",
|
|
789
|
+
dep
|
|
790
|
+
);
|
|
791
|
+
} else {
|
|
792
|
+
versionData.dependencies[dep] = {
|
|
793
|
+
installed: null,
|
|
794
|
+
expected:
|
|
795
|
+
mainPackage.dependencies[dep] ||
|
|
796
|
+
mainPackage.devDependencies[dep] ||
|
|
797
|
+
"not specified",
|
|
798
|
+
status: "not found",
|
|
799
|
+
error: "package.json not found",
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
} catch (error) {
|
|
803
|
+
versionData.dependencies[dep] = {
|
|
804
|
+
installed: null,
|
|
805
|
+
expected:
|
|
806
|
+
mainPackage.dependencies[dep] ||
|
|
807
|
+
mainPackage.devDependencies[dep] ||
|
|
808
|
+
"not specified",
|
|
809
|
+
status: "error",
|
|
810
|
+
error: error.message,
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
});
|
|
814
|
+
|
|
815
|
+
return versionData;
|
|
816
|
+
} catch (error) {
|
|
817
|
+
return { error: error.message };
|
|
818
|
+
}
|
|
819
|
+
}
|