doc-detective 2.17.1-dev.0 → 2.18.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.
package/README.md CHANGED
@@ -33,14 +33,7 @@ Doc Detective has multiple components to integrate with your workflows as you ne
33
33
 
34
34
  If you don't install Doc Detective globally, you'll be prompted to install the first time you run an `npx` command.
35
35
 
36
- ## (Optional) Get sample files
37
-
38
- To test a few samples, clone the repo and navigate to the `samples` directory:
39
-
40
- ```bash
41
- git clone https://github.com/doc-detective/doc-detective.git
42
- cd doc-detective/samples
43
- ```
36
+ **Note:** If you're working in a cloned `doc-detective` repository, run `npm i` to install local dependencies or the `npx` command in the next step will fail.
44
37
 
45
38
  ## Run tests
46
39
 
@@ -56,7 +49,7 @@ By default, Doc Detective scans the current directory for valid tests, but you c
56
49
  npx doc-detective runTests --input doc-content-inline-tests.md
57
50
  ```
58
51
 
59
- To customize your test, file type, and directory options, create a `.doc-detective.json` [config](https://doc-detective.com/reference/schemas/config.html) file. If a `.doc-detective.json` file exists in the directory when you run the comment, Doc Detective loads the config. Otherwise, you can specify a config path with the `--config` argument.
52
+ To customize your test, file type, and directory options, create a `.doc-detective.json` [config](https://doc-detective.com/docs/references/schemas/config.html) file. If a `.doc-detective.json` file exists in the directory when you run the comment, Doc Detective loads the config. Otherwise, you can specify a config path with the `--config` argument.
60
53
 
61
54
  ```bash
62
55
  npx doc-detective runTests --config .doc-detective.json
@@ -70,9 +63,13 @@ You can override config options with command-line arguments. For example, to run
70
63
  npx doc-detective runTests --config .doc-detective.json --input tests.spec.json
71
64
  ```
72
65
 
66
+ ### Check out some samples
67
+
68
+ You can find test and config samples in the [samples](https://github.com/doc-detective/doc-detective/tree/main/samples) directory.
69
+
73
70
  ## Check your test coverage
74
71
 
75
- You can check the test coverage of your documentation source files with the `runCoverage` command, specifying the source file or directory of source files with the `--input` argument. Doc Detective identifies potential areas of test coverage with file-format-specific regex, and supports CommonMark syntax natively. If you want to test coverage of a file with different syntax, update your the `fileTypes` object of your [config](https://doc-detective.com/reference/schemas/config.html) file accordingly.
72
+ You can check the test coverage of your documentation source files with the `runCoverage` command, specifying the source file or directory of source files with the `--input` argument. Doc Detective identifies potential areas of test coverage with file-format-specific regex, and supports CommonMark syntax natively. If you want to test coverage of a file with different syntax, update the `fileTypes` object of your [config](https://doc-detective.com/docs/references/schemas/config.html) file accordingly.
76
73
 
77
74
  ```bash
78
75
  npx doc-detective runCoverage --config .doc-detective.json --input doc-content.md
@@ -80,21 +77,21 @@ npx doc-detective runCoverage --config .doc-detective.json --input doc-content.m
80
77
 
81
78
  ## Concepts
82
79
 
83
- - [**Test specification**](https://doc-detective.com/reference/schemas/specification.html): A group of tests to run in one or more contexts. Conceptually parallel to a document.
84
- - [**Test**](https://doc-detective.com/reference/schemas/test.html): A sequence of steps to perform. Conceptually parallel to a procedure.
80
+ - [**Test specification**](https://doc-detective.com/docs/references/schemas/specification.html): A group of tests to run in one or more contexts. Conceptually parallel to a document.
81
+ - [**Test**](https://doc-detective.com/docs/references/schemas/test.html): A sequence of steps to perform. Conceptually parallel to a procedure.
85
82
  - **Step**: A portion of a test that includes a single action. Conceptually parallel to a step in a procedure.
86
83
  - **Action**: The task a performed in a step. Doc Detective supports a variety of actions:
87
- - [**checkLink**](https://doc-detective.com/reference/schemas/checkLink.html): Check if a URL returns an acceptable status code from a GET request.
88
- - [**find**](https://doc-detective.com/reference/schemas/find.html): Check if an element exists with the specified selector.
89
- - [**goTo**](https://doc-detective.com/reference/schemas/goTo.html): Navigate to a specified URL.
90
- - [**httpRequest**](https://doc-detective.com/reference/schemas/httpRequest.html): Perform a generic HTTP request, for example to an API.
91
- - [**runShell**](https://doc-detective.com/reference/schemas/runShell.html): Perform a native shell command.
92
- - [**saveScreenshot**](https://doc-detective.com/reference/schemas/saveScreenshot.html): Take a screenshot in PNG format.
93
- - [**setVariables**](https://doc-detective.com/reference/schemas/setVariables.html): Load environment variables from a `.env` file.
94
- - [**startRecording**](https://doc-detective.com/reference/schemas/startRecording.html) and [**stopRecording**](https://doc-detective.com/reference/schemas/stopRecording.html): Capture a video of test execution.
95
- - [**typeKeys**](https://doc-detective.com/reference/schemas/typeKeys.html): Type keys. To type special keys, begin and end the string with `$` and use the special key’s enum. For example, to type the Escape key, enter `$ESCAPE$`.
96
- - [**wait**](https://doc-detective.com/reference/schemas/wait.html): Pause before performing the next action.
97
- - [**Context**](https://doc-detective.com/reference/schemas/context.html): An application and platforms that support the tests.
84
+ - [**checkLink**](https://doc-detective.com/docs/references/schemas/checkLink.html): Check if a URL returns an acceptable status code from a GET request.
85
+ - [**find**](https://doc-detective.com/docs/references/schemas/find.html): Check if an element exists with the specified selector.
86
+ - [**goTo**](https://doc-detective.com/docs/references/schemas/goTo.html): Navigate to a specified URL.
87
+ - [**httpRequest**](https://doc-detective.com/docs/references/schemas/httpRequest.html): Perform a generic HTTP request, for example to an API.
88
+ - [**runShell**](https://doc-detective.com/docs/references/schemas/runShell.html): Perform a native shell command.
89
+ - [**saveScreenshot**](https://doc-detective.com/docs/references/schemas/saveScreenshot.html): Take a screenshot in PNG format.
90
+ - [**setVariables**](https://doc-detective.com/docs/references/schemas/setVariables.html): Load environment variables from a `.env` file.
91
+ - [**startRecording**](https://doc-detective.com/docs/references/schemas/startRecording.html) and [**stopRecording**](https://doc-detective.com/docs/references/schemas/stopRecording.html): Capture a video of test execution.
92
+ - [**typeKeys**](https://doc-detective.com/docs/references/schemas/typeKeys.html): Type keys. To type special keys, begin and end the string with `$` and use the special key’s enum. For example, to type the Escape key, enter `$ESCAPE$`.
93
+ - [**wait**](https://doc-detective.com/docs/references/schemas/wait.html): Pause before performing the next action.
94
+ - [**Context**](https://doc-detective.com/docs/references/schemas/context.html): An application and platforms that support the tests.
98
95
 
99
96
  ## Roadmap
100
97
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doc-detective",
3
- "version": "2.17.1-dev.0",
3
+ "version": "2.18.0-dev.0",
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"
@@ -9,7 +9,9 @@
9
9
  "scripts": {
10
10
  "mocha": "mocha",
11
11
  "test": "mocha test/*.test.js",
12
+ "prerunTests": "node ./src/checkDependencies.js",
12
13
  "runTests": "node ./src/index.js runTests",
14
+ "prerunCoverage": "node ./src/checkDependencies.js",
13
15
  "runCoverage": "node ./src/index.js runCoverage",
14
16
  "dev": "node ./dev"
15
17
  },
@@ -32,8 +34,8 @@
32
34
  "homepage": "https://github.com/doc-detective/doc-detective#readme",
33
35
  "dependencies": {
34
36
  "@ffmpeg-installer/ffmpeg": "^1.1.0",
35
- "doc-detective-common": "^1.20.0",
36
- "doc-detective-core": "^2.17.1-dev.0",
37
+ "doc-detective-common": "^1.21.0",
38
+ "doc-detective-core": "^2.18.0",
37
39
  "prompt-sync": "^4.2.0",
38
40
  "yargs": "^17.7.2"
39
41
  },
@@ -4,8 +4,8 @@
4
4
 
5
5
  - The landing page discusses what Doc Detective is, what it does, and who might find it useful.
6
6
 
7
- - [Get started](https://doc-detective.com/get-started.html) covers how to quickly get up and running with Doc Detective.
7
+ - [Get started](https://doc-detective.com/docs/get-started.html) covers how to quickly get up and running with Doc Detective.
8
8
 
9
- - The [references](https://doc-detective.com/reference/) detail the various JSON objects that Doc Detective expects for [configs](https://doc-detective.com/reference/schemas/config.html), [test specifications](https://doc-detective.com/reference/schemas/specification.html), [tests](https://doc-detective.com/reference/schemas/test), actions, and more. Open [typeKeys](https://doc-detective.com/reference/schemas/typeKeys.html)--or any other schema--and you'll find three sections: **Description**, **Fields**, and **Examples**.
9
+ - The [references](https://doc-detective.com/docs/category/schemas) detail the various JSON objects that Doc Detective expects for [configs](https://doc-detective.com/docs/references/schemas/config.html), [test specifications](https://doc-detective.com/docs/references/schemas/specification.html), [tests](https://doc-detective.com/docs/references/schemas/test), actions, and more. Open [typeKeys](https://doc-detective.com/docs/references/schemas/typeKeys.html)--or any other schema--and you'll find two sections: **Fields** and **Examples**.
10
10
 
11
11
  ![Search results.](reference.png)
@@ -8,18 +8,17 @@
8
8
 
9
9
  - The landing page discusses what Doc Detective is, what it does, and who might find it useful.
10
10
 
11
- - [Get started](https://doc-detective.com/get-started.html) covers how to quickly get up and running with Doc Detective.
11
+ - [Get started](https://doc-detective.com/docs/get-started.html) covers how to quickly get up and running with Doc Detective.
12
12
 
13
- [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/get-started.html"})
13
+ [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/docs/get-started.html"})
14
14
 
15
- - The [references](https://doc-detective.com/reference/) detail the various JSON objects that Doc Detective expects for [configs](https://doc-detective.com/reference/schemas/config.html), [test specifications](https://doc-detective.com/reference/schemas/specification.html), [tests](https://doc-detective.com/reference/schemas/test), actions, and more. Open [typeKeys](https://doc-detective.com/reference/schemas/typeKeys.html)--or any other schema--and you'll find three sections: **Description**, **Fields**, and **Examples**.
15
+ - The [references](https://doc-detective.com/docs/category/schemas) detail the various JSON objects that Doc Detective expects for [configs](https://doc-detective.com/docs/references/schemas/config.html), [test specifications](https://doc-detective.com/docs/references/schemas/specification.html), [tests](https://doc-detective.com/docs/references/schemas/test), actions, and more. Open [typeKeys](https://doc-detective.com/docs/references/schemas/typeKeys.html)--or any other schema--and you'll find two sections: **Fields** and **Examples**.
16
16
 
17
- [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/reference/"})
18
- [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/reference/schemas/config.html"})
19
- [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/reference/schemas/specification.html"})
20
- [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/reference/schemas/test.html"})
21
- [comment]: # (step {"action":"goTo", "url":"https://doc-detective.com/reference/schemas/typeKeys.html"})
22
- [comment]: # (step {"action":"find", "selector":"h2#description", "matchText":"Description"})
17
+ [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/docs/category/schemas"})
18
+ [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/docs/references/schemas/config.html"})
19
+ [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/docs/references/schemas/specification.html"})
20
+ [comment]: # (step {"action":"checkLink", "url":"https://doc-detective.com/docs/references/schemas/test.html"})
21
+ [comment]: # (step {"action":"goTo", "url":"https://doc-detective.com/docs/references/schemas/typeKeys.html"})
23
22
  [comment]: # (step {"action":"find", "selector":"h2#fields", "matchText":"Fields"})
24
23
  [comment]: # (step {"action":"find", "selector":"h2#examples", "matchText":"Examples"})
25
24
 
@@ -0,0 +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
+ }