doc-detective 2.15.1 → 2.16.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.
@@ -20,48 +20,38 @@ jobs:
20
20
  node:
21
21
  - 18
22
22
  - 20
23
+ - 22
23
24
  steps:
24
- - uses: actions/checkout@v3
25
-
26
- - uses: actions/setup-node@v3
25
+ - uses: actions/checkout@v4
26
+ - uses: actions/setup-node@v4
27
27
  with:
28
28
  node-version: ${{ matrix.node }}
29
-
30
- - name: Cache node_modules
31
- uses: actions/cache@v3
32
- with:
33
- # Cache key uses the contents of `package-lock.json` to identify unique cache
34
- key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
35
- restore-keys: |
36
- ${{ runner.OS }}-node-
37
- path: |
38
- node_modules
39
-
40
29
  - run: npm ci
41
-
42
30
  - run: npm test
43
31
 
44
32
  publish-npm:
45
33
  needs: build
46
34
  runs-on: ubuntu-latest
47
35
  steps:
48
- - uses: actions/checkout@v3
49
-
50
- - uses: actions/setup-node@v3
36
+ - uses: actions/checkout@v4
37
+ - uses: actions/setup-node@v4
51
38
  with:
52
39
  registry-url: https://registry.npmjs.org/
53
-
54
- - name: Cache node_modules
55
- uses: actions/cache@v3
56
- with:
57
- # Cache key uses the contents of `package-lock.json` to identify unique cache
58
- key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
59
- restore-keys: |
60
- ${{ runner.OS }}-node-
61
- path: |
62
- node_modules
63
-
64
40
  - run: npm ci
65
41
  - run: npm publish
66
42
  env:
67
43
  NODE_AUTH_TOKEN: ${{secrets.npm_token}}
44
+
45
+ # Test downstream consumers of the package
46
+ test-github-action:
47
+ name: Test GitHub Action
48
+ needs: publish-npm
49
+ runs-on: ubuntu-latest
50
+ steps:
51
+ - uses: actions/checkout@v4
52
+ - uses: doc-detective/github-action@latest
53
+ id: dd
54
+ with:
55
+ config: ./test/artifacts/config.json
56
+ input: ./test/artifacts/doc-content.md
57
+ exit_on_fail: "true"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doc-detective",
3
- "version": "2.15.1",
3
+ "version": "2.16.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"
@@ -32,8 +32,8 @@
32
32
  "homepage": "https://github.com/doc-detective/doc-detective#readme",
33
33
  "dependencies": {
34
34
  "@ffmpeg-installer/ffmpeg": "^1.1.0",
35
- "doc-detective-common": "^1.18.2",
36
- "doc-detective-core": "^2.15.1",
35
+ "doc-detective-common": "^1.19.1",
36
+ "doc-detective-core": "^2.16.0",
37
37
  "prompt-sync": "^4.2.0",
38
38
  "yargs": "^17.7.2"
39
39
  },
package/src/index.js CHANGED
@@ -39,7 +39,7 @@ async function main(argv) {
39
39
  config = require(configPath);
40
40
  }
41
41
  // Set config
42
- config = setConfig(config, argv);
42
+ config = await setConfig(config, argv);
43
43
  command = command || config.defaultCommand;
44
44
  // If no command, prompt user to select a command
45
45
  if (command !== "runTests" && command !== "runCoverage") {
package/src/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const yargs = require("yargs/yargs");
2
2
  const { hideBin } = require("yargs/helpers");
3
- const { validate } = require("doc-detective-common");
3
+ const { validate, resolvePaths } = require("doc-detective-common");
4
4
  const path = require("path");
5
5
  const fs = require("fs");
6
6
  const { spawn } = require("child_process");
@@ -62,7 +62,7 @@ function setArgs(args) {
62
62
  }
63
63
 
64
64
  // Override config values based on args
65
- function setConfig(config, args) {
65
+ async function setConfig(config, args) {
66
66
  // If no args, return config
67
67
  if (!args) return config;
68
68
 
@@ -74,6 +74,7 @@ function setConfig(config, args) {
74
74
  const validation = validate("config_v2", configContent);
75
75
  if (validation.valid) {
76
76
  config = configContent;
77
+ config = await resolvePaths(config, config, configPath);
77
78
  } else {
78
79
  // Output validation errors
79
80
  console.error("Invalid config file:");
@@ -85,17 +86,32 @@ function setConfig(config, args) {
85
86
  }
86
87
 
87
88
  // Override config values
88
- if (args.input) config.input = args.input;
89
- if (args.output) config.output = args.output;
90
- if (args.recursive) config.recursive = args.recursive;
91
- if (args.logLevel) config.logLevel = args.logLevel;
92
89
  if (
93
90
  (args.setup || args.cleanup || args.input || args.output) &&
94
91
  !config.runTests
95
92
  )
96
93
  config.runTests = {};
97
- if (args.input) config.runTests.input = args.input;
98
- if (args.output) config.runTests.output = args.output;
94
+ if (
95
+ (args.setup || args.cleanup || args.input || args.output) &&
96
+ !config.runCoverage
97
+ )
98
+ config.runCoverage = {};
99
+ if (args.input) {
100
+ config.input = args.input;
101
+ config.runCoverage.input = args.input;
102
+ config.runTests.input = args.input;
103
+ }
104
+ if (args.output) {
105
+ config.output = args.output;
106
+ config.runCoverage.output = args.output;
107
+ config.runTests.output = args.output;
108
+ }
109
+ if (args.recursive) {
110
+ config.recursive = args.recursive;
111
+ config.runCoverage.recursive = args.recursive;
112
+ config.runTests.recursive = args.recursive;
113
+ }
114
+ if (args.logLevel) config.logLevel = args.logLevel;
99
115
  if (args.setup) config.runTests.setup = args.setup;
100
116
  if (args.cleanup) config.runTests.cleanup = args.cleanup;
101
117
 
@@ -117,7 +133,7 @@ async function outputResults(config = {}, outputPath, results, options = {}) {
117
133
  // DEBUG
118
134
  // outputPath = "./foobar/results.json";
119
135
  // END DEBUG
120
-
136
+
121
137
  // Define supported output extensions
122
138
  const outputExtensions = [".json"];
123
139
 
@@ -3,9 +3,10 @@
3
3
  "input": ".",
4
4
  "output": ".",
5
5
  "recursive": true,
6
+ "relativePathBase": "file",
6
7
  "logLevel": "debug",
7
8
  "runTests": {
8
- "input": "./test/artifacts/test.spec.json",
9
+ "input": "test.spec.json",
9
10
  "output": ".",
10
11
  "setup": "",
11
12
  "cleanup": "",
@@ -8,7 +8,7 @@
8
8
  "steps": [
9
9
  {
10
10
  "action": "setVariables",
11
- "path": "test/artifacts/env"
11
+ "path": "env"
12
12
  },
13
13
  {
14
14
  "action": "httpRequest",
@@ -4,8 +4,8 @@
4
4
  {
5
5
  "id": "Do all the things! - Test",
6
6
  "description": "This test includes nearly every property across all actions.",
7
- "setup": "test/artifacts/setup.spec.json",
8
- "cleanup": "test/artifacts/cleanup.spec.json",
7
+ "setup": "setup.spec.json",
8
+ "cleanup": "cleanup.spec.json",
9
9
  "steps": [
10
10
  {
11
11
  "action": "setVariables",
@@ -1,23 +1,19 @@
1
1
  const path = require("path");
2
- const { spawnCommand } = require(path.resolve(__dirname,"../src/utils"));
2
+ const { spawnCommand } = require(path.resolve(__dirname, "../src/utils"));
3
3
  const assert = require("assert").strict;
4
4
  const fs = require("fs");
5
- const artifactPath = path.resolve(__dirname,"./artifacts");
5
+ const artifactPath = path.resolve(__dirname, "./artifacts");
6
+ const outputFile = path.resolve(`${artifactPath}/coverageResults.json`);
6
7
 
7
8
  describe("Perform coverage analysis successfully", function () {
8
9
  // Set indefinite timeout
9
10
  this.timeout(0);
10
11
  it("Should have 6 covered and 0 uncovered", async () => {
11
- const coverateResults = await spawnCommand(`node ./src/index.js runCoverage -c ${artifactPath}/config.json -i ${artifactPath}/doc-content.md -o ${artifactPath}`);
12
- // Find output file
13
- // console.log(coverateResults.stdout)
14
- const outputFiles = coverateResults.stdout.split("See results at ");
15
- const outputFile = outputFiles[outputFiles.length - 1].trim();
16
- // If output file is not found, throw an error
17
- if (!outputFile) {
18
- throw new Error(`Output file not found.\nOutput file: ${outputFile}\nCWD: ${process.cwd()}\nstdout: ${coverateResults.stdout}`);
19
- }
12
+ await spawnCommand(
13
+ `node ./src/index.js runCoverage -c ${artifactPath}/config.json -i ${artifactPath}/doc-content.md -o ${outputFile}`
14
+ );
20
15
  const result = require(outputFile);
16
+ fs.unlinkSync(outputFile);
21
17
  assert.equal(result.summary.covered, 6);
22
18
  assert.equal(result.summary.uncovered, 0);
23
19
  });
@@ -1,29 +1,19 @@
1
1
  const path = require("path");
2
- const { spawnCommand } = require(path.resolve(__dirname,"../src/utils"));
2
+ const { spawnCommand } = require(path.resolve(__dirname, "../src/utils"));
3
3
  const assert = require("assert").strict;
4
4
  const fs = require("fs");
5
- const artifactPath = path.resolve(__dirname,"./artifacts");
5
+ const artifactPath = path.resolve(__dirname, "./artifacts");
6
+ const outputFile = path.resolve(`${artifactPath}/testResults.json`);
6
7
 
7
8
  describe("Run tests sucessfully", function () {
8
9
  // Set indefinite timeout
9
10
  this.timeout(0);
10
11
  it("All specs pass", async () => {
11
- const runTests = await spawnCommand(
12
- `node ./src/index.js runTests -c ${artifactPath}/config.json -i ${artifactPath} -o ${artifactPath}`
13
- );
14
- // Find output file
15
- console.log(runTests.stdout)
16
- const outputFiles = runTests.stdout.split("See results at ");
17
- const outputFile = outputFiles[outputFiles.length - 1].trim();
18
- console.log(outputFile);
19
- console.log(fs.existsSync(outputFile));
20
- // If output file is not found, throw an error
21
- if (!outputFile) {
22
- throw new Error(`Output file not found.\nOutput file: ${outputFile}\nCWD: ${process.cwd()}\nstdout: ${runTests.stdout}`);
23
- }
24
- const result = JSON.parse(
25
- fs.readFileSync(outputFile, { encoding: "utf8" })
12
+ await spawnCommand(
13
+ `node ./src/index.js runTests -c ${artifactPath}/config.json -i ${artifactPath} -o ${outputFile}`
26
14
  );
15
+ const result = require(outputFile);
16
+ fs.unlinkSync(outputFile);
27
17
  assert.equal(result.summary.specs.fail, 0);
28
18
  });
29
19
  });
@@ -170,8 +170,8 @@ describe("Util tests", function () {
170
170
  },
171
171
  ];
172
172
 
173
- configSets.forEach((configSet) => {
174
- const configResult = setConfig({}, setArgs(configSet.args));
173
+ configSets.forEach(async (configSet) => {
174
+ const configResult = await setConfig({}, setArgs(configSet.args));
175
175
  deepObjectExpect(configResult, configSet.expected);
176
176
  });
177
177
  });
@@ -1,19 +0,0 @@
1
- name: Docker Image CI
2
-
3
- on:
4
- push:
5
- branches: [ "main" ]
6
- pull_request:
7
- branches: [ "main" ]
8
- workflow_dispatch:
9
-
10
- jobs:
11
-
12
- build:
13
-
14
- runs-on: macos-latest
15
-
16
- steps:
17
- - uses: actions/checkout@v3
18
- - name: Build the Docker image
19
- run: npm run docker:build:multiarch