doc-detective 3.4.1-dev.1 → 3.5.0-dev.0

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.
Files changed (44) hide show
  1. package/.github/FUNDING.yml +14 -14
  2. package/.github/dependabot.yml +11 -11
  3. package/.github/workflows/auto-dev-release.yml +173 -173
  4. package/.github/workflows/npm-test.yaml +96 -96
  5. package/.github/workflows/update-core.yaml +131 -131
  6. package/CONTRIBUTIONS.md +27 -27
  7. package/LICENSE +661 -661
  8. package/README.md +110 -110
  9. package/dev/dev.config.json +8 -3
  10. package/dev/dev.spec.json +30 -30
  11. package/dev/index.js +5 -5
  12. package/package.json +47 -47
  13. package/samples/.doc-detective.json +94 -94
  14. package/samples/doc-content-detect.md +10 -10
  15. package/samples/doc-content-inline-tests.md +23 -23
  16. package/samples/docker-hello.spec.json +15 -15
  17. package/samples/env +2 -2
  18. package/samples/http.spec.yaml +37 -37
  19. package/samples/kitten-search-detect.md +7 -7
  20. package/samples/kitten-search-inline.md +15 -15
  21. package/samples/kitten-search.spec.json +28 -28
  22. package/samples/local-gui.md +5 -5
  23. package/samples/tests.spec.json +70 -70
  24. package/samples/variables.env +4 -4
  25. package/scripts/bump-sync-version-core.js +110 -108
  26. package/src/checkDependencies.js +84 -84
  27. package/src/index.js +72 -72
  28. package/src/utils.js +1023 -1023
  29. package/test/artifacts/cleanup.spec.json +18 -18
  30. package/test/artifacts/config.json +6 -6
  31. package/test/artifacts/doc-content.md +23 -23
  32. package/test/artifacts/env +2 -2
  33. package/test/artifacts/httpRequest.spec.yaml +37 -37
  34. package/test/artifacts/runShell.spec.json +29 -29
  35. package/test/artifacts/setup.spec.json +18 -18
  36. package/test/artifacts/test.spec.json +46 -46
  37. package/test/resolvedTests.test.js +193 -193
  38. package/test/runTests.test.js +53 -53
  39. package/test/server/index.js +185 -185
  40. package/test/server/public/index.html +174 -174
  41. package/test/test-config.json +12 -12
  42. package/test/test-results.json +124 -124
  43. package/test/utils.test.js +298 -298
  44. package/reference.png +0 -0
@@ -1,84 +1,84 @@
1
- #!/usr/bin/env node
2
-
3
- const path = require("path");
4
- const fs = require("fs");
5
- const readline = require("readline");
6
-
7
- // Check if package.json exists, and if it's for doc-detective
8
- if (fs.existsSync(path.resolve(process.cwd(), "package.json"))) {
9
- try {
10
- const json = JSON.parse(
11
- fs.readFileSync(path.resolve(process.cwd(), "package.json"))
12
- );
13
- if (json.name === "doc-detective") {
14
- // Check if dependencies are installed
15
- checkDependencies();
16
- }
17
- } catch (error) {
18
- console.error(`Failed to parse package.json: ${error.message}`);
19
- }
20
- }
21
-
22
- // Check if dependencies are installed
23
- function checkDependencies() {
24
- if (!fs.existsSync(path.resolve(process.cwd(), "node_modules"))) {
25
- const rl = readline.createInterface({
26
- input: process.stdin,
27
- output: process.stdout,
28
- });
29
-
30
- // Handle SIGINT (Ctrl+C)
31
- rl.on('SIGINT', () => {
32
- console.log('\nOperation cancelled by user');
33
- rl.close();
34
- process.exit(0);
35
- });
36
-
37
- rl.question(
38
- "It looks like you haven't installed the local dependencies yet. Would you like to install them now? (yes/no): ",
39
- (answer) => {
40
- const normalizedAnswer = answer.toLowerCase().trim();
41
- if (normalizedAnswer === "yes" || normalizedAnswer === "y") {
42
- console.log("Installing dependencies. This may take a few minutes.");
43
- const { spawn } = require("child_process");
44
- const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
45
- const install = spawn(npmCmd, ["install"], {
46
- stdio: "inherit",
47
- shell: true
48
- });
49
-
50
- // Set timeout
51
- const timeout = setTimeout(() => {
52
- console.error('Installation timed out after 5 minutes');
53
- install.kill();
54
- rl.close();
55
- }, 5 * 60 * 1000);
56
-
57
- install.on("close", (code) => {
58
- clearTimeout(timeout);
59
- if (code !== 0) {
60
- console.error(
61
- `Failed to install dependencies (exit code ${code}). Try running 'npm install' manually and check for errors.`
62
- );
63
- process.exit(1);
64
- } else {
65
- console.log("Dependencies installed successfully.");
66
- }
67
- rl.close();
68
- });
69
-
70
- install.on("error", (error) => {
71
- clearTimeout(timeout);
72
- console.error(`Failed to start 'npm install': ${error.message}`);
73
- rl.close();
74
- process.exit(1);
75
- });
76
- } else {
77
- console.log("Dependencies not installed. Please run 'npm install' manually before proceeding.");
78
- rl.close();
79
- process.exit(1);
80
- }
81
- }
82
- );
83
- }
84
- }
1
+ #!/usr/bin/env node
2
+
3
+ const path = require("path");
4
+ const fs = require("fs");
5
+ const readline = require("readline");
6
+
7
+ // Check if package.json exists, and if it's for doc-detective
8
+ if (fs.existsSync(path.resolve(process.cwd(), "package.json"))) {
9
+ try {
10
+ const json = JSON.parse(
11
+ fs.readFileSync(path.resolve(process.cwd(), "package.json"))
12
+ );
13
+ if (json.name === "doc-detective") {
14
+ // Check if dependencies are installed
15
+ checkDependencies();
16
+ }
17
+ } catch (error) {
18
+ console.error(`Failed to parse package.json: ${error.message}`);
19
+ }
20
+ }
21
+
22
+ // Check if dependencies are installed
23
+ function checkDependencies() {
24
+ if (!fs.existsSync(path.resolve(process.cwd(), "node_modules"))) {
25
+ const rl = readline.createInterface({
26
+ input: process.stdin,
27
+ output: process.stdout,
28
+ });
29
+
30
+ // Handle SIGINT (Ctrl+C)
31
+ rl.on('SIGINT', () => {
32
+ console.log('\nOperation cancelled by user');
33
+ rl.close();
34
+ process.exit(0);
35
+ });
36
+
37
+ rl.question(
38
+ "It looks like you haven't installed the local dependencies yet. Would you like to install them now? (yes/no): ",
39
+ (answer) => {
40
+ const normalizedAnswer = answer.toLowerCase().trim();
41
+ if (normalizedAnswer === "yes" || normalizedAnswer === "y") {
42
+ console.log("Installing dependencies. This may take a few minutes.");
43
+ const { spawn } = require("child_process");
44
+ const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
45
+ const install = spawn(npmCmd, ["install"], {
46
+ stdio: "inherit",
47
+ shell: true
48
+ });
49
+
50
+ // Set timeout
51
+ const timeout = setTimeout(() => {
52
+ console.error('Installation timed out after 5 minutes');
53
+ install.kill();
54
+ rl.close();
55
+ }, 5 * 60 * 1000);
56
+
57
+ install.on("close", (code) => {
58
+ clearTimeout(timeout);
59
+ if (code !== 0) {
60
+ console.error(
61
+ `Failed to install dependencies (exit code ${code}). Try running 'npm install' manually and check for errors.`
62
+ );
63
+ process.exit(1);
64
+ } else {
65
+ console.log("Dependencies installed successfully.");
66
+ }
67
+ rl.close();
68
+ });
69
+
70
+ install.on("error", (error) => {
71
+ clearTimeout(timeout);
72
+ console.error(`Failed to start 'npm install': ${error.message}`);
73
+ rl.close();
74
+ process.exit(1);
75
+ });
76
+ } else {
77
+ console.log("Dependencies not installed. Please run 'npm install' manually before proceeding.");
78
+ rl.close();
79
+ process.exit(1);
80
+ }
81
+ }
82
+ );
83
+ }
84
+ }
package/src/index.js CHANGED
@@ -1,72 +1,72 @@
1
- #!/usr/bin/env node
2
-
3
- const { runTests } = require("doc-detective-core");
4
- const {
5
- setArgs,
6
- setConfig,
7
- outputResults,
8
- setMeta,
9
- getVersionData,
10
- log,
11
- getResolvedTestsFromEnv,
12
- reportResults,
13
- } = require("./utils");
14
- const { argv } = require("node:process");
15
- const path = require("path");
16
- const fs = require("fs");
17
-
18
- // Run
19
- setMeta();
20
- main(argv);
21
-
22
- // Run
23
- async function main(argv) {
24
- // Find index of `doc-detective` or `run` in argv
25
- const index = argv.findIndex(
26
- (arg) => arg.endsWith("doc-detective") || arg.endsWith("index.js")
27
- );
28
- // Set args
29
- argv = setArgs(argv);
30
-
31
- // Get .doc-detective JSON or YAML config, if it exists, preferring a config arg if provided
32
- const configPathJSON = path.resolve(process.cwd(), ".doc-detective.json");
33
- const configPathYAML = path.resolve(process.cwd(), ".doc-detective.yaml");
34
- const configPathYML = path.resolve(process.cwd(), ".doc-detective.yml");
35
- const configPath = fs.existsSync(argv.config)
36
- ? argv.config
37
- : fs.existsSync(configPathJSON)
38
- ? configPathJSON
39
- : fs.existsSync(configPathYAML)
40
- ? configPathYAML
41
- : fs.existsSync(configPathYML)
42
- ? configPathYML
43
- : null;
44
-
45
- // Set config
46
- const config = await setConfig({ configPath: configPath, args: argv });
47
-
48
- log(
49
- `CLI:VERSION INFO:\n${JSON.stringify(getVersionData(), null, 2)}`,
50
- "debug",
51
- config
52
- );
53
- log(`CLI:CONFIG:\n${JSON.stringify(config, null, 2)}`, "debug", config);
54
-
55
- // Check for DOC_DETECTIVE_API environment variable
56
- let api = await getResolvedTestsFromEnv(config);
57
- let resolvedTests = api?.resolvedTests || null;
58
- let apiConfig = api?.apiConfig || null;
59
-
60
- // Run tests
61
- const output = config.output;
62
- const results = resolvedTests
63
- ? await runTests(config, { resolvedTests })
64
- : await runTests(config);
65
-
66
- if (apiConfig) {
67
- await reportResults({ apiConfig, results });
68
- } else {
69
- // Output results
70
- await outputResults(config, output, results, { command: "runTests" });
71
- }
72
- }
1
+ #!/usr/bin/env node
2
+
3
+ const { runTests } = require("doc-detective-core");
4
+ const {
5
+ setArgs,
6
+ setConfig,
7
+ outputResults,
8
+ setMeta,
9
+ getVersionData,
10
+ log,
11
+ getResolvedTestsFromEnv,
12
+ reportResults,
13
+ } = require("./utils");
14
+ const { argv } = require("node:process");
15
+ const path = require("path");
16
+ const fs = require("fs");
17
+
18
+ // Run
19
+ setMeta();
20
+ main(argv);
21
+
22
+ // Run
23
+ async function main(argv) {
24
+ // Find index of `doc-detective` or `run` in argv
25
+ const index = argv.findIndex(
26
+ (arg) => arg.endsWith("doc-detective") || arg.endsWith("index.js")
27
+ );
28
+ // Set args
29
+ argv = setArgs(argv);
30
+
31
+ // Get .doc-detective JSON or YAML config, if it exists, preferring a config arg if provided
32
+ const configPathJSON = path.resolve(process.cwd(), ".doc-detective.json");
33
+ const configPathYAML = path.resolve(process.cwd(), ".doc-detective.yaml");
34
+ const configPathYML = path.resolve(process.cwd(), ".doc-detective.yml");
35
+ const configPath = fs.existsSync(argv.config)
36
+ ? argv.config
37
+ : fs.existsSync(configPathJSON)
38
+ ? configPathJSON
39
+ : fs.existsSync(configPathYAML)
40
+ ? configPathYAML
41
+ : fs.existsSync(configPathYML)
42
+ ? configPathYML
43
+ : null;
44
+
45
+ // Set config
46
+ const config = await setConfig({ configPath: configPath, args: argv });
47
+
48
+ log(
49
+ `CLI:VERSION INFO:\n${JSON.stringify(getVersionData(), null, 2)}`,
50
+ "debug",
51
+ config
52
+ );
53
+ log(`CLI:CONFIG:\n${JSON.stringify(config, null, 2)}`, "debug", config);
54
+
55
+ // Check for DOC_DETECTIVE_API environment variable
56
+ let api = await getResolvedTestsFromEnv(config);
57
+ let resolvedTests = api?.resolvedTests || null;
58
+ let apiConfig = api?.apiConfig || null;
59
+
60
+ // Run tests
61
+ const output = config.output;
62
+ const results = resolvedTests
63
+ ? await runTests(config, { resolvedTests })
64
+ : await runTests(config);
65
+
66
+ if (apiConfig) {
67
+ await reportResults({ apiConfig, results });
68
+ } else {
69
+ // Output results
70
+ await outputResults(config, output, results, { command: "runTests" });
71
+ }
72
+ }