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.
- package/.github/FUNDING.yml +14 -14
- package/.github/dependabot.yml +11 -11
- package/.github/workflows/auto-dev-release.yml +173 -173
- package/.github/workflows/npm-test.yaml +96 -96
- package/.github/workflows/update-core.yaml +131 -131
- package/CONTRIBUTIONS.md +27 -27
- package/LICENSE +661 -661
- package/README.md +110 -110
- package/dev/dev.config.json +8 -3
- package/dev/dev.spec.json +30 -30
- package/dev/index.js +5 -5
- package/package.json +47 -47
- package/samples/.doc-detective.json +94 -94
- package/samples/doc-content-detect.md +10 -10
- package/samples/doc-content-inline-tests.md +23 -23
- package/samples/docker-hello.spec.json +15 -15
- package/samples/env +2 -2
- package/samples/http.spec.yaml +37 -37
- package/samples/kitten-search-detect.md +7 -7
- package/samples/kitten-search-inline.md +15 -15
- package/samples/kitten-search.spec.json +28 -28
- package/samples/local-gui.md +5 -5
- package/samples/tests.spec.json +70 -70
- package/samples/variables.env +4 -4
- package/scripts/bump-sync-version-core.js +110 -108
- package/src/checkDependencies.js +84 -84
- package/src/index.js +72 -72
- package/src/utils.js +1023 -1023
- package/test/artifacts/cleanup.spec.json +18 -18
- package/test/artifacts/config.json +6 -6
- package/test/artifacts/doc-content.md +23 -23
- package/test/artifacts/env +2 -2
- package/test/artifacts/httpRequest.spec.yaml +37 -37
- package/test/artifacts/runShell.spec.json +29 -29
- package/test/artifacts/setup.spec.json +18 -18
- package/test/artifacts/test.spec.json +46 -46
- package/test/resolvedTests.test.js +193 -193
- package/test/runTests.test.js +53 -53
- package/test/server/index.js +185 -185
- package/test/server/public/index.html +174 -174
- package/test/test-config.json +12 -12
- package/test/test-results.json +124 -124
- package/test/utils.test.js +298 -298
- package/reference.png +0 -0
package/test/server/index.js
CHANGED
|
@@ -1,185 +1,185 @@
|
|
|
1
|
-
const express = require("express");
|
|
2
|
-
const bodyParser = require("body-parser");
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Creates an echo server that can serve static content and echo back API requests
|
|
8
|
-
* @param {Object} options - Configuration options
|
|
9
|
-
* @param {number} [options.port=8092] - Port to run the server on
|
|
10
|
-
* @param {string} [options.staticDir="public"] - Directory to serve static files from
|
|
11
|
-
* @param {Function} [options.modifyResponse] - Function to modify responses before sending
|
|
12
|
-
* @returns {Object} Server object with start and stop methods
|
|
13
|
-
*/
|
|
14
|
-
function createServer(options = {}) {
|
|
15
|
-
const {
|
|
16
|
-
port = 8092,
|
|
17
|
-
staticDir = "public",
|
|
18
|
-
modifyResponse = (req, body) => body,
|
|
19
|
-
} = options;
|
|
20
|
-
|
|
21
|
-
const app = express();
|
|
22
|
-
let server = null;
|
|
23
|
-
|
|
24
|
-
// Parse JSON and urlencoded bodies
|
|
25
|
-
app.use(bodyParser.json({ limit: "10mb" }));
|
|
26
|
-
app.use(bodyParser.urlencoded({ extended: true }));
|
|
27
|
-
|
|
28
|
-
// Serve static files if a directory is provided
|
|
29
|
-
if (staticDir && fs.existsSync(staticDir)) {
|
|
30
|
-
app.use(express.static(staticDir));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Echo API endpoint that returns the request body
|
|
34
|
-
app.all("/api/:path", (req, res) => {
|
|
35
|
-
try {
|
|
36
|
-
const requestBody = req.method === "GET" ? req.query : req.body;
|
|
37
|
-
const modifiedResponse = modifyResponse(req, requestBody);
|
|
38
|
-
console.log("Request:", {
|
|
39
|
-
Method: req.method,
|
|
40
|
-
Path: req.path,
|
|
41
|
-
Query: req.query,
|
|
42
|
-
Headers: req.headers,
|
|
43
|
-
Body: req.body,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
res.set("x-server", "doc-detective-echo-server");
|
|
47
|
-
|
|
48
|
-
console.log("Response:", { Body: modifiedResponse });
|
|
49
|
-
|
|
50
|
-
res.json(modifiedResponse);
|
|
51
|
-
} catch (error) {
|
|
52
|
-
console.error("Error processing request:", error);
|
|
53
|
-
res.status(500).json({ error: "Internal server error" });
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Endpoint for testing DOC_DETECTIVE_API - returns resolved tests
|
|
58
|
-
app.get("/api/resolved-tests", (req, res) => {
|
|
59
|
-
try {
|
|
60
|
-
// Check for x-runner-token header
|
|
61
|
-
const token = req.headers['x-runner-token'];
|
|
62
|
-
|
|
63
|
-
if (!token || token !== 'test-token-123') {
|
|
64
|
-
return res.status(401).json({ error: "Unauthorized" });
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Return a valid resolvedTests object
|
|
68
|
-
const resolvedTests = {
|
|
69
|
-
"resolvedTestsId": "api-resolved-tests-id",
|
|
70
|
-
"config": {
|
|
71
|
-
"logLevel": "info"
|
|
72
|
-
},
|
|
73
|
-
"specs": [
|
|
74
|
-
{
|
|
75
|
-
"specId": "api-spec",
|
|
76
|
-
"tests": [
|
|
77
|
-
{
|
|
78
|
-
"testId": "api-test",
|
|
79
|
-
"contexts": [
|
|
80
|
-
{
|
|
81
|
-
"contextId": "api-context",
|
|
82
|
-
"steps": [
|
|
83
|
-
{
|
|
84
|
-
"stepId": "step-1",
|
|
85
|
-
"checkLink": `http://localhost:${port}`
|
|
86
|
-
}
|
|
87
|
-
]
|
|
88
|
-
}
|
|
89
|
-
]
|
|
90
|
-
}
|
|
91
|
-
]
|
|
92
|
-
}
|
|
93
|
-
]
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
res.json(resolvedTests);
|
|
97
|
-
} catch (error) {
|
|
98
|
-
console.error("Error processing resolved tests request:", error);
|
|
99
|
-
res.status(500).json({ error: "Internal server error" });
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
return {
|
|
104
|
-
/**
|
|
105
|
-
* Start the server
|
|
106
|
-
* @returns {Promise} Promise that resolves with the server address
|
|
107
|
-
*/
|
|
108
|
-
|
|
109
|
-
start: () => {
|
|
110
|
-
return new Promise((resolve, reject) => {
|
|
111
|
-
try {
|
|
112
|
-
server = app.listen(port, () => {
|
|
113
|
-
const serverAddress = `http://localhost:${port}`;
|
|
114
|
-
console.log(`Echo server running at ${serverAddress}`);
|
|
115
|
-
resolve(serverAddress);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
server.on("error", (error) => {
|
|
119
|
-
console.error(`Failed to start server: ${error.message}`);
|
|
120
|
-
reject(error);
|
|
121
|
-
});
|
|
122
|
-
} catch (error) {
|
|
123
|
-
console.error(`Error setting up server: ${error.message}`);
|
|
124
|
-
reject(error);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Stop the server
|
|
131
|
-
* @returns {Promise} Promise that resolves when server is stopped
|
|
132
|
-
*/
|
|
133
|
-
stop: () => {
|
|
134
|
-
return new Promise((resolve) => {
|
|
135
|
-
if (server) {
|
|
136
|
-
server.close((error) => {
|
|
137
|
-
if (error) {
|
|
138
|
-
console.error("Error stopping server:", error);
|
|
139
|
-
reject(error);
|
|
140
|
-
} else {
|
|
141
|
-
console.log("Echo server stopped");
|
|
142
|
-
server = null;
|
|
143
|
-
resolve();
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
} else {
|
|
147
|
-
resolve();
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Get the Express app instance
|
|
154
|
-
* @returns {Object} Express app
|
|
155
|
-
*/
|
|
156
|
-
getApp: () => app,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Export the function
|
|
161
|
-
module.exports = { createServer };
|
|
162
|
-
|
|
163
|
-
// If this file is run directly, start a server
|
|
164
|
-
if (require.main === module) {
|
|
165
|
-
const server = createServer({
|
|
166
|
-
port: process.env.PORT || 8092,
|
|
167
|
-
staticDir:
|
|
168
|
-
process.env.STATIC_DIR ||
|
|
169
|
-
path.join(process.cwd(), "./test/server/public"),
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
server.start();
|
|
173
|
-
|
|
174
|
-
// Handle graceful shutdown
|
|
175
|
-
const shutdown = () => {
|
|
176
|
-
console.log("Shutting down server...");
|
|
177
|
-
server
|
|
178
|
-
.stop()
|
|
179
|
-
.then(() => process.exit(0))
|
|
180
|
-
.catch(() => process.exit(1));
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
process.on("SIGINT", shutdown);
|
|
184
|
-
process.on("SIGTERM", shutdown);
|
|
185
|
-
}
|
|
1
|
+
const express = require("express");
|
|
2
|
+
const bodyParser = require("body-parser");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates an echo server that can serve static content and echo back API requests
|
|
8
|
+
* @param {Object} options - Configuration options
|
|
9
|
+
* @param {number} [options.port=8092] - Port to run the server on
|
|
10
|
+
* @param {string} [options.staticDir="public"] - Directory to serve static files from
|
|
11
|
+
* @param {Function} [options.modifyResponse] - Function to modify responses before sending
|
|
12
|
+
* @returns {Object} Server object with start and stop methods
|
|
13
|
+
*/
|
|
14
|
+
function createServer(options = {}) {
|
|
15
|
+
const {
|
|
16
|
+
port = 8092,
|
|
17
|
+
staticDir = "public",
|
|
18
|
+
modifyResponse = (req, body) => body,
|
|
19
|
+
} = options;
|
|
20
|
+
|
|
21
|
+
const app = express();
|
|
22
|
+
let server = null;
|
|
23
|
+
|
|
24
|
+
// Parse JSON and urlencoded bodies
|
|
25
|
+
app.use(bodyParser.json({ limit: "10mb" }));
|
|
26
|
+
app.use(bodyParser.urlencoded({ extended: true }));
|
|
27
|
+
|
|
28
|
+
// Serve static files if a directory is provided
|
|
29
|
+
if (staticDir && fs.existsSync(staticDir)) {
|
|
30
|
+
app.use(express.static(staticDir));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Echo API endpoint that returns the request body
|
|
34
|
+
app.all("/api/:path", (req, res) => {
|
|
35
|
+
try {
|
|
36
|
+
const requestBody = req.method === "GET" ? req.query : req.body;
|
|
37
|
+
const modifiedResponse = modifyResponse(req, requestBody);
|
|
38
|
+
console.log("Request:", {
|
|
39
|
+
Method: req.method,
|
|
40
|
+
Path: req.path,
|
|
41
|
+
Query: req.query,
|
|
42
|
+
Headers: req.headers,
|
|
43
|
+
Body: req.body,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
res.set("x-server", "doc-detective-echo-server");
|
|
47
|
+
|
|
48
|
+
console.log("Response:", { Body: modifiedResponse });
|
|
49
|
+
|
|
50
|
+
res.json(modifiedResponse);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error("Error processing request:", error);
|
|
53
|
+
res.status(500).json({ error: "Internal server error" });
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Endpoint for testing DOC_DETECTIVE_API - returns resolved tests
|
|
58
|
+
app.get("/api/resolved-tests", (req, res) => {
|
|
59
|
+
try {
|
|
60
|
+
// Check for x-runner-token header
|
|
61
|
+
const token = req.headers['x-runner-token'];
|
|
62
|
+
|
|
63
|
+
if (!token || token !== 'test-token-123') {
|
|
64
|
+
return res.status(401).json({ error: "Unauthorized" });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Return a valid resolvedTests object
|
|
68
|
+
const resolvedTests = {
|
|
69
|
+
"resolvedTestsId": "api-resolved-tests-id",
|
|
70
|
+
"config": {
|
|
71
|
+
"logLevel": "info"
|
|
72
|
+
},
|
|
73
|
+
"specs": [
|
|
74
|
+
{
|
|
75
|
+
"specId": "api-spec",
|
|
76
|
+
"tests": [
|
|
77
|
+
{
|
|
78
|
+
"testId": "api-test",
|
|
79
|
+
"contexts": [
|
|
80
|
+
{
|
|
81
|
+
"contextId": "api-context",
|
|
82
|
+
"steps": [
|
|
83
|
+
{
|
|
84
|
+
"stepId": "step-1",
|
|
85
|
+
"checkLink": `http://localhost:${port}`
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
res.json(resolvedTests);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error("Error processing resolved tests request:", error);
|
|
99
|
+
res.status(500).json({ error: "Internal server error" });
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
/**
|
|
105
|
+
* Start the server
|
|
106
|
+
* @returns {Promise} Promise that resolves with the server address
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
start: () => {
|
|
110
|
+
return new Promise((resolve, reject) => {
|
|
111
|
+
try {
|
|
112
|
+
server = app.listen(port, () => {
|
|
113
|
+
const serverAddress = `http://localhost:${port}`;
|
|
114
|
+
console.log(`Echo server running at ${serverAddress}`);
|
|
115
|
+
resolve(serverAddress);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
server.on("error", (error) => {
|
|
119
|
+
console.error(`Failed to start server: ${error.message}`);
|
|
120
|
+
reject(error);
|
|
121
|
+
});
|
|
122
|
+
} catch (error) {
|
|
123
|
+
console.error(`Error setting up server: ${error.message}`);
|
|
124
|
+
reject(error);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Stop the server
|
|
131
|
+
* @returns {Promise} Promise that resolves when server is stopped
|
|
132
|
+
*/
|
|
133
|
+
stop: () => {
|
|
134
|
+
return new Promise((resolve) => {
|
|
135
|
+
if (server) {
|
|
136
|
+
server.close((error) => {
|
|
137
|
+
if (error) {
|
|
138
|
+
console.error("Error stopping server:", error);
|
|
139
|
+
reject(error);
|
|
140
|
+
} else {
|
|
141
|
+
console.log("Echo server stopped");
|
|
142
|
+
server = null;
|
|
143
|
+
resolve();
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
resolve();
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Get the Express app instance
|
|
154
|
+
* @returns {Object} Express app
|
|
155
|
+
*/
|
|
156
|
+
getApp: () => app,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Export the function
|
|
161
|
+
module.exports = { createServer };
|
|
162
|
+
|
|
163
|
+
// If this file is run directly, start a server
|
|
164
|
+
if (require.main === module) {
|
|
165
|
+
const server = createServer({
|
|
166
|
+
port: process.env.PORT || 8092,
|
|
167
|
+
staticDir:
|
|
168
|
+
process.env.STATIC_DIR ||
|
|
169
|
+
path.join(process.cwd(), "./test/server/public"),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
server.start();
|
|
173
|
+
|
|
174
|
+
// Handle graceful shutdown
|
|
175
|
+
const shutdown = () => {
|
|
176
|
+
console.log("Shutting down server...");
|
|
177
|
+
server
|
|
178
|
+
.stop()
|
|
179
|
+
.then(() => process.exit(0))
|
|
180
|
+
.catch(() => process.exit(1));
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
process.on("SIGINT", shutdown);
|
|
184
|
+
process.on("SIGTERM", shutdown);
|
|
185
|
+
}
|