doc-detective-common 3.0.2 → 3.0.4-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/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "doc-detective-common",
3
- "version": "3.0.2",
3
+ "version": "3.0.4-dev.0",
4
4
  "description": "Shared components for Doc Detective projects.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
7
7
  "dereferenceSchemas": "node ./src/schemas/dereferenceSchemas.js",
8
- "test:full": "npm run dereferenceSchemas && npm run test",
8
+ "build": "npm run dereferenceSchemas",
9
+ "postbuild": "npm run test",
9
10
  "test": "mocha"
10
11
  },
11
12
  "repository": {
@@ -20,16 +21,16 @@
20
21
  "homepage": "https://github.com/doc-detective/doc-detective-common#readme",
21
22
  "devDependencies": {
22
23
  "chai": "^5.2.0",
23
- "mocha": "^11.1.0",
24
+ "mocha": "^11.2.2",
24
25
  "sinon": "^20.0.0"
25
26
  },
26
27
  "dependencies": {
27
- "@apidevtools/json-schema-ref-parser": "^12.0.1",
28
+ "@apidevtools/json-schema-ref-parser": "^12.0.2",
28
29
  "ajv": "^8.17.1",
29
30
  "ajv-errors": "^3.0.0",
30
31
  "ajv-formats": "^3.0.1",
31
32
  "ajv-keywords": "^5.1.0",
32
- "axios": "^1.8.4",
33
+ "axios": "^1.9.0",
33
34
  "uuid": "^11.1.0",
34
35
  "yaml": "^2.7.1"
35
36
  }
@@ -30,9 +30,12 @@ async function resolvePaths({
30
30
  const configPaths = [
31
31
  "input",
32
32
  "output",
33
- "envVariables",
33
+ "loadVariables",
34
34
  "setup",
35
35
  "cleanup",
36
+ "configPath",
37
+ "beforeAny",
38
+ "afterAll",
36
39
  "mediaDirectory",
37
40
  "downloadDirectory",
38
41
  "descriptionPath",
@@ -50,6 +53,7 @@ async function resolvePaths({
50
53
  "cleanup",
51
54
  "savePath",
52
55
  "saveDirectory",
56
+ "specPath",
53
57
  "descriptionPath",
54
58
  "workingDirectory",
55
59
  ];
@@ -131,7 +135,37 @@ async function resolvePaths({
131
135
  }
132
136
 
133
137
  for (const property of Object.keys(object)) {
134
- if (
138
+ // If the property is an array, recursively call resolvePaths for each item in the array
139
+ if (Array.isArray(object[property])) {
140
+ for (let i = 0; i < object[property].length; i++) {
141
+ const item = object[property][i];
142
+
143
+ // If the item is an object, recursively call resolvePaths to resolve paths within the object
144
+ if (typeof item === "object") {
145
+ await resolvePaths({
146
+ config: config,
147
+ object: item,
148
+ filePath: filePath,
149
+ nested: true,
150
+ objectType: objectType,
151
+ });
152
+ } else if (
153
+ typeof item === "string" &&
154
+ pathProperties.includes(property)
155
+ ) {
156
+ // Resolve the string path and write it back into the array
157
+ const resolved =
158
+ property === "path" &&
159
+ object.directory &&
160
+ path.isAbsolute(object.directory)
161
+ ? resolve(relativePathBase, item, object.directory)
162
+ : resolve(relativePathBase, item, filePath);
163
+ object[property][i] = resolved;
164
+ }
165
+ }
166
+ }
167
+ // If the property is an object, recursively call resolvePaths to resolve paths within the object
168
+ else if (
135
169
  typeof object[property] === "object" &&
136
170
  ((objectType === "spec" && !specNoResolve.includes(property)) ||
137
171
  objectType === "config")
@@ -145,27 +179,62 @@ async function resolvePaths({
145
179
  objectType: objectType,
146
180
  });
147
181
  } else if (typeof object[property] === "string") {
148
- // If the property is a string, check if it matches any of the path properties and resolve it if it does
149
- pathProperties.forEach((pathProperty) => {
150
- if (object[pathProperty]) {
151
- if (pathProperty === "path" && object.directory) {
152
- if (path.isAbsolute(object.directory)) {
153
- object[pathProperty] = resolve(
154
- relativePathBase,
155
- object[pathProperty],
156
- object.directory
157
- );
158
- }
159
- } else {
160
- object[pathProperty] = resolve(
161
- relativePathBase,
162
- object[pathProperty],
163
- filePath
164
- );
165
- }
182
+ // If the property begins with "https://" or "http://", skip it
183
+ if (
184
+ object[property].startsWith("https://") ||
185
+ object[property].startsWith("http://")
186
+ ) {
187
+ continue;
188
+ }
189
+ // Check if it matches any of the path properties and resolve it if it does
190
+ if (pathProperties.includes(property)) {
191
+ if (property === "path" && object.directory) {
192
+ const directory = path.isAbsolute(object.directory)
193
+ ? object.directory
194
+ : resolve(relativePathBase, object.directory, filePath);
195
+ object[property] = resolve(
196
+ relativePathBase,
197
+ object[property],
198
+ directory
199
+ );
200
+ } else {
201
+ object[property] = resolve(
202
+ relativePathBase,
203
+ object[property],
204
+ filePath
205
+ );
166
206
  }
167
- });
207
+ }
168
208
  }
169
209
  }
170
210
  return object;
171
211
  }
212
+
213
+ // If called directly, resolve paths in the provided object
214
+ if (require.main === module) {
215
+ (async () => {
216
+ // Example usage
217
+ const config = {
218
+ relativePathBase: "file",
219
+ };
220
+ const object = {
221
+ tests: [
222
+ {
223
+ steps: [
224
+ {
225
+ screenshot: {
226
+ path: "file.png",
227
+ directory:
228
+ "/home/hawkeyexl/Workspaces/doc-detective-common/screenshots",
229
+ },
230
+ },
231
+ ],
232
+ },
233
+ ],
234
+ };
235
+ const filePath = process.cwd();
236
+
237
+ await resolvePaths({ config, object, filePath });
238
+ console.log(JSON.stringify(object, null, 2));
239
+ })();
240
+ }
@@ -32,6 +32,7 @@ async function dereferenceSchemas() {
32
32
  "httpRequest_v3.schema.json",
33
33
  "openApi_v3.schema.json",
34
34
  "record_v3.schema.json",
35
+ "resolvedTests_v3.schema.json",
35
36
  "report_v3.schema.json",
36
37
  "runCode_v3.schema.json",
37
38
  "runShell_v3.schema.json",
@@ -12,6 +12,11 @@
12
12
  "description": "Identifier for the configuration.",
13
13
  "type": "string"
14
14
  },
15
+ "configPath": {
16
+ "description": "Path to the configuration file.",
17
+ "type": "string",
18
+ "readOnly": true
19
+ },
15
20
  "input": {
16
21
  "description": "Path(s) to test specifications and documentation source files. May be paths to specific files or to directories to scan for files.",
17
22
  "default": ".",
@@ -5297,10 +5302,78 @@
5297
5302
  "default": {
5298
5303
  "send": true
5299
5304
  }
5305
+ },
5306
+ "environment": {
5307
+ "type": "object",
5308
+ "description": "Environment information for the system running Doc Detective.",
5309
+ "readmeOnly": true,
5310
+ "additionalProperties": false,
5311
+ "required": [
5312
+ "platform"
5313
+ ],
5314
+ "properties": {
5315
+ "workingDirectory": {
5316
+ "description": "The current working directory of the process running Doc Detective.",
5317
+ "type": "string"
5318
+ },
5319
+ "platform": {
5320
+ "description": "The operating system type running Doc Detective.",
5321
+ "type": "string",
5322
+ "enum": [
5323
+ "linux",
5324
+ "mac",
5325
+ "windows"
5326
+ ]
5327
+ },
5328
+ "arch": {
5329
+ "description": "The processor architecture of the system running Doc Detective.",
5330
+ "type": "string",
5331
+ "enum": [
5332
+ "arm32",
5333
+ "arm64",
5334
+ "x32",
5335
+ "x64"
5336
+ ]
5337
+ }
5338
+ }
5300
5339
  }
5301
5340
  },
5302
5341
  "components": {
5303
5342
  "schemas": {
5343
+ "environment": {
5344
+ "type": "object",
5345
+ "description": "Environment information for the system running Doc Detective.",
5346
+ "readmeOnly": true,
5347
+ "additionalProperties": false,
5348
+ "required": [
5349
+ "platform"
5350
+ ],
5351
+ "properties": {
5352
+ "workingDirectory": {
5353
+ "description": "The current working directory of the process running Doc Detective.",
5354
+ "type": "string"
5355
+ },
5356
+ "platform": {
5357
+ "description": "The operating system type running Doc Detective.",
5358
+ "type": "string",
5359
+ "enum": [
5360
+ "linux",
5361
+ "mac",
5362
+ "windows"
5363
+ ]
5364
+ },
5365
+ "arch": {
5366
+ "description": "The processor architecture of the system running Doc Detective.",
5367
+ "type": "string",
5368
+ "enum": [
5369
+ "arm32",
5370
+ "arm64",
5371
+ "x32",
5372
+ "x64"
5373
+ ]
5374
+ }
5375
+ }
5376
+ },
5304
5377
  "markupDefinition": {
5305
5378
  "type": "object",
5306
5379
  "properties": {
@@ -9677,6 +9750,12 @@
9677
9750
  }
9678
9751
  }
9679
9752
  ]
9753
+ },
9754
+ {
9755
+ "environment": {
9756
+ "platform": "windows",
9757
+ "arch": "x64"
9758
+ }
9680
9759
  }
9681
9760
  ]
9682
9761
  }