@testsmith/api-spector 0.0.5 → 0.0.8
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/out/main/chunks/request-handler-C1b53aHR.js +985 -0
- package/out/main/index.js +52 -517
- package/out/main/runner.js +26 -22
- package/out/renderer/assets/{index-KbYng3S3.js → index-CNACdUVN.js} +13363 -7809
- package/out/renderer/assets/index-Dmfghjyp.css +2 -0
- package/out/renderer/index.html +2 -2
- package/package.json +29 -28
- package/out/main/chunks/script-runner-CmdLWmKN.js +0 -511
- package/out/renderer/assets/index-f4ppKNTS.css +0 -1877
package/out/main/runner.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const promises = require("fs/promises");
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const undici = require("undici");
|
|
6
|
-
const
|
|
6
|
+
const requestHandler = require("./chunks/request-handler-C1b53aHR.js");
|
|
7
7
|
require("crypto");
|
|
8
8
|
require("vm");
|
|
9
9
|
require("dayjs");
|
|
@@ -150,7 +150,7 @@ async function loadEnvironments(workspace, dir) {
|
|
|
150
150
|
}
|
|
151
151
|
return envs;
|
|
152
152
|
}
|
|
153
|
-
async function executeRequest(req, collectionVars, envVars, globals, verbose) {
|
|
153
|
+
async function executeRequest(req, collectionVars, envVars, globals, verbose, tls) {
|
|
154
154
|
const base = {
|
|
155
155
|
requestId: req.id,
|
|
156
156
|
name: req.name,
|
|
@@ -164,7 +164,7 @@ async function executeRequest(req, collectionVars, envVars, globals, verbose) {
|
|
|
164
164
|
let updatedGlobals = { ...globals };
|
|
165
165
|
let preScriptError;
|
|
166
166
|
if (req.preRequestScript?.trim()) {
|
|
167
|
-
const r = await
|
|
167
|
+
const r = await requestHandler.runScript(req.preRequestScript, {
|
|
168
168
|
envVars: { ...envVars },
|
|
169
169
|
collectionVars: { ...collectionVars },
|
|
170
170
|
globals: { ...globals },
|
|
@@ -175,41 +175,41 @@ async function executeRequest(req, collectionVars, envVars, globals, verbose) {
|
|
|
175
175
|
updatedEnvVars = r.updatedEnvVars;
|
|
176
176
|
updatedCollectionVars = r.updatedCollectionVars;
|
|
177
177
|
updatedGlobals = r.updatedGlobals;
|
|
178
|
-
|
|
179
|
-
await
|
|
178
|
+
requestHandler.patchGlobals(r.updatedGlobals);
|
|
179
|
+
await requestHandler.persistGlobals();
|
|
180
180
|
if (verbose && r.consoleOutput.length) r.consoleOutput.forEach((l) => console.log(color(` [pre] ${l}`, C.gray)));
|
|
181
181
|
if (r.error) console.error(color(` [pre-script error] ${r.error}`, C.red));
|
|
182
182
|
}
|
|
183
|
-
const vars =
|
|
184
|
-
const resolvedUrl =
|
|
183
|
+
const vars = requestHandler.mergeVars(updatedEnvVars, updatedCollectionVars, updatedGlobals, localVars);
|
|
184
|
+
const resolvedUrl = requestHandler.buildUrl(req.url, req.params, vars);
|
|
185
185
|
base.resolvedUrl = resolvedUrl;
|
|
186
186
|
const start = Date.now();
|
|
187
187
|
try {
|
|
188
188
|
const authH = {};
|
|
189
189
|
if (req.auth.type === "bearer") {
|
|
190
190
|
let token = req.auth.token ?? "";
|
|
191
|
-
if (!token && req.auth.tokenSecretRef) token = await
|
|
192
|
-
if (token) authH["Authorization"] = `Bearer ${
|
|
191
|
+
if (!token && req.auth.tokenSecretRef) token = await requestHandler.getSecret(req.auth.tokenSecretRef) ?? "";
|
|
192
|
+
if (token) authH["Authorization"] = `Bearer ${requestHandler.interpolate(token, vars)}`;
|
|
193
193
|
}
|
|
194
194
|
const headers = new undici.Headers();
|
|
195
195
|
for (const h of req.headers) {
|
|
196
|
-
if (h.enabled && h.key) headers.set(
|
|
196
|
+
if (h.enabled && h.key) headers.set(requestHandler.interpolate(h.key, vars), requestHandler.interpolate(h.value, vars));
|
|
197
197
|
}
|
|
198
198
|
for (const [k, v] of Object.entries(authH)) headers.set(k, v);
|
|
199
199
|
let body;
|
|
200
200
|
if (req.body.mode === "json" && req.body.json) {
|
|
201
|
-
body =
|
|
201
|
+
body = requestHandler.interpolate(req.body.json, vars);
|
|
202
202
|
if (!headers.has("content-type")) headers.set("Content-Type", "application/json");
|
|
203
203
|
} else if (req.body.mode === "raw" && req.body.raw) {
|
|
204
|
-
body =
|
|
204
|
+
body = requestHandler.interpolate(req.body.raw, vars);
|
|
205
205
|
if (!headers.has("content-type")) headers.set("Content-Type", req.body.rawContentType ?? "text/plain");
|
|
206
206
|
} else if (req.body.mode === "graphql" && req.body.graphql) {
|
|
207
207
|
const gql = req.body.graphql;
|
|
208
|
-
const gqlBody = { query:
|
|
208
|
+
const gqlBody = { query: requestHandler.interpolate(gql.query, vars) };
|
|
209
209
|
const rawVars = gql.variables?.trim();
|
|
210
210
|
if (rawVars) {
|
|
211
211
|
try {
|
|
212
|
-
gqlBody.variables = JSON.parse(
|
|
212
|
+
gqlBody.variables = JSON.parse(requestHandler.interpolate(rawVars, vars));
|
|
213
213
|
} catch {
|
|
214
214
|
}
|
|
215
215
|
}
|
|
@@ -217,10 +217,12 @@ async function executeRequest(req, collectionVars, envVars, globals, verbose) {
|
|
|
217
217
|
body = JSON.stringify(gqlBody);
|
|
218
218
|
if (!headers.has("content-type")) headers.set("Content-Type", "application/json");
|
|
219
219
|
}
|
|
220
|
+
const dispatcher = await requestHandler.buildDispatcher(void 0, tls);
|
|
220
221
|
const fetchResp = await undici.fetch(resolvedUrl, {
|
|
221
222
|
method: req.method,
|
|
222
223
|
headers,
|
|
223
|
-
body: ["GET", "HEAD"].includes(req.method) ? void 0 : body
|
|
224
|
+
body: ["GET", "HEAD"].includes(req.method) ? void 0 : body,
|
|
225
|
+
...dispatcher ? { dispatcher } : {}
|
|
224
226
|
});
|
|
225
227
|
const responseBody = await fetchResp.text();
|
|
226
228
|
const durationMs = Date.now() - start;
|
|
@@ -240,7 +242,7 @@ async function executeRequest(req, collectionVars, envVars, globals, verbose) {
|
|
|
240
242
|
let consoleOutput = [];
|
|
241
243
|
let postScriptError;
|
|
242
244
|
if (req.postRequestScript?.trim()) {
|
|
243
|
-
const r = await
|
|
245
|
+
const r = await requestHandler.runScript(req.postRequestScript, {
|
|
244
246
|
envVars: updatedEnvVars,
|
|
245
247
|
collectionVars: updatedCollectionVars,
|
|
246
248
|
globals: updatedGlobals,
|
|
@@ -250,8 +252,8 @@ async function executeRequest(req, collectionVars, envVars, globals, verbose) {
|
|
|
250
252
|
testResults = r.testResults;
|
|
251
253
|
consoleOutput = r.consoleOutput;
|
|
252
254
|
postScriptError = r.error;
|
|
253
|
-
|
|
254
|
-
await
|
|
255
|
+
requestHandler.patchGlobals(r.updatedGlobals);
|
|
256
|
+
await requestHandler.persistGlobals();
|
|
255
257
|
if (verbose && r.consoleOutput.length) r.consoleOutput.forEach((l) => console.log(color(` [post] ${l}`, C.gray)));
|
|
256
258
|
}
|
|
257
259
|
const allPassed = testResults.every((t) => t.passed);
|
|
@@ -311,7 +313,7 @@ async function main() {
|
|
|
311
313
|
console.error(color(`Error: could not read workspace file: ${wsPath}`, C.red));
|
|
312
314
|
process.exit(1);
|
|
313
315
|
}
|
|
314
|
-
await
|
|
316
|
+
await requestHandler.loadGlobals(wsDir);
|
|
315
317
|
const collections = await loadCollections(workspace, wsDir);
|
|
316
318
|
const environments = await loadEnvironments(workspace, wsDir);
|
|
317
319
|
const env = envName ? environments.find((e) => e.name.toLowerCase() === envName.toLowerCase()) ?? null : null;
|
|
@@ -334,12 +336,14 @@ async function main() {
|
|
|
334
336
|
const items = collectTagged(col.rootFolder, col.requests, col.collectionVariables ?? {}, filterTags);
|
|
335
337
|
if (items.length === 0) continue;
|
|
336
338
|
if (!firstColName) firstColName = col.name;
|
|
337
|
-
const envVars = await
|
|
338
|
-
const globals =
|
|
339
|
+
const envVars = await requestHandler.buildEnvVars(env);
|
|
340
|
+
const globals = requestHandler.getGlobals();
|
|
339
341
|
console.log(color(` ┌ ${col.name}`, C.bold, C.white));
|
|
342
|
+
const workspaceTls = workspace.settings?.tls;
|
|
343
|
+
const effectiveTls = col.tls ? { ...workspaceTls, ...col.tls } : workspaceTls;
|
|
340
344
|
let bailed = false;
|
|
341
345
|
for (const item of items) {
|
|
342
|
-
const result = await executeRequest(item.request, item.collectionVars, envVars, globals, verbose);
|
|
346
|
+
const result = await executeRequest(item.request, item.collectionVars, envVars, globals, verbose, effectiveTls);
|
|
343
347
|
printResult(result, verbose);
|
|
344
348
|
allResults.push(result);
|
|
345
349
|
summary.total++;
|