@testsmith/api-spector 0.0.7 → 0.0.9
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/mock-server-C0RlwZf_.js +240 -0
- package/out/main/chunks/request-handler-9MdHOWVf.js +1041 -0
- package/out/main/index.js +54 -519
- package/out/main/mock.js +3 -1
- package/out/main/runner.js +28 -23
- package/out/preload/index.js +4 -0
- package/out/renderer/assets/{index-x-2wMDPZ.js → index-C67sPzTG.js} +5986 -5315
- package/out/renderer/assets/index-YkI5DFME.css +2 -0
- package/out/renderer/index.html +2 -2
- package/package.json +1 -1
- package/out/main/chunks/mock-server-ZB7zpXh9.js +0 -102
- package/out/main/chunks/script-runner-CmdLWmKN.js +0 -511
- package/out/renderer/assets/index-DRGkbz0a.css +0 -2
package/out/main/mock.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
const promises = require("fs/promises");
|
|
4
4
|
const path = require("path");
|
|
5
|
-
const mockServer = require("./chunks/mock-server-
|
|
5
|
+
const mockServer = require("./chunks/mock-server-C0RlwZf_.js");
|
|
6
6
|
require("http");
|
|
7
7
|
require("crypto");
|
|
8
|
+
require("vm");
|
|
9
|
+
require("dayjs");
|
|
8
10
|
const C = {
|
|
9
11
|
reset: "\x1B[0m",
|
|
10
12
|
bold: "\x1B[1m",
|
package/out/main/runner.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
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-9MdHOWVf.js");
|
|
7
7
|
require("crypto");
|
|
8
|
-
require("vm");
|
|
9
8
|
require("dayjs");
|
|
9
|
+
require("vm");
|
|
10
10
|
require("tv4");
|
|
11
11
|
require("jsonpath-plus");
|
|
12
12
|
require("@xmldom/xmldom");
|
|
@@ -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,42 @@ 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
|
|
184
|
-
const
|
|
183
|
+
const dynamicVars = await requestHandler.buildDynamicVars();
|
|
184
|
+
const vars = requestHandler.mergeVars(updatedEnvVars, updatedCollectionVars, updatedGlobals, localVars, dynamicVars);
|
|
185
|
+
const resolvedUrl = requestHandler.buildUrl(req.url, req.params, vars);
|
|
185
186
|
base.resolvedUrl = resolvedUrl;
|
|
186
187
|
const start = Date.now();
|
|
187
188
|
try {
|
|
188
189
|
const authH = {};
|
|
189
190
|
if (req.auth.type === "bearer") {
|
|
190
191
|
let token = req.auth.token ?? "";
|
|
191
|
-
if (!token && req.auth.tokenSecretRef) token = await
|
|
192
|
-
if (token) authH["Authorization"] = `Bearer ${
|
|
192
|
+
if (!token && req.auth.tokenSecretRef) token = await requestHandler.getSecret(req.auth.tokenSecretRef) ?? "";
|
|
193
|
+
if (token) authH["Authorization"] = `Bearer ${requestHandler.interpolate(token, vars)}`;
|
|
193
194
|
}
|
|
194
195
|
const headers = new undici.Headers();
|
|
195
196
|
for (const h of req.headers) {
|
|
196
|
-
if (h.enabled && h.key) headers.set(
|
|
197
|
+
if (h.enabled && h.key) headers.set(requestHandler.interpolate(h.key, vars), requestHandler.interpolate(h.value, vars));
|
|
197
198
|
}
|
|
198
199
|
for (const [k, v] of Object.entries(authH)) headers.set(k, v);
|
|
199
200
|
let body;
|
|
200
201
|
if (req.body.mode === "json" && req.body.json) {
|
|
201
|
-
body =
|
|
202
|
+
body = requestHandler.interpolate(req.body.json, vars);
|
|
202
203
|
if (!headers.has("content-type")) headers.set("Content-Type", "application/json");
|
|
203
204
|
} else if (req.body.mode === "raw" && req.body.raw) {
|
|
204
|
-
body =
|
|
205
|
+
body = requestHandler.interpolate(req.body.raw, vars);
|
|
205
206
|
if (!headers.has("content-type")) headers.set("Content-Type", req.body.rawContentType ?? "text/plain");
|
|
206
207
|
} else if (req.body.mode === "graphql" && req.body.graphql) {
|
|
207
208
|
const gql = req.body.graphql;
|
|
208
|
-
const gqlBody = { query:
|
|
209
|
+
const gqlBody = { query: requestHandler.interpolate(gql.query, vars) };
|
|
209
210
|
const rawVars = gql.variables?.trim();
|
|
210
211
|
if (rawVars) {
|
|
211
212
|
try {
|
|
212
|
-
gqlBody.variables = JSON.parse(
|
|
213
|
+
gqlBody.variables = JSON.parse(requestHandler.interpolate(rawVars, vars));
|
|
213
214
|
} catch {
|
|
214
215
|
}
|
|
215
216
|
}
|
|
@@ -217,10 +218,12 @@ async function executeRequest(req, collectionVars, envVars, globals, verbose) {
|
|
|
217
218
|
body = JSON.stringify(gqlBody);
|
|
218
219
|
if (!headers.has("content-type")) headers.set("Content-Type", "application/json");
|
|
219
220
|
}
|
|
221
|
+
const dispatcher = await requestHandler.buildDispatcher(void 0, tls);
|
|
220
222
|
const fetchResp = await undici.fetch(resolvedUrl, {
|
|
221
223
|
method: req.method,
|
|
222
224
|
headers,
|
|
223
|
-
body: ["GET", "HEAD"].includes(req.method) ? void 0 : body
|
|
225
|
+
body: ["GET", "HEAD"].includes(req.method) ? void 0 : body,
|
|
226
|
+
...dispatcher ? { dispatcher } : {}
|
|
224
227
|
});
|
|
225
228
|
const responseBody = await fetchResp.text();
|
|
226
229
|
const durationMs = Date.now() - start;
|
|
@@ -240,7 +243,7 @@ async function executeRequest(req, collectionVars, envVars, globals, verbose) {
|
|
|
240
243
|
let consoleOutput = [];
|
|
241
244
|
let postScriptError;
|
|
242
245
|
if (req.postRequestScript?.trim()) {
|
|
243
|
-
const r = await
|
|
246
|
+
const r = await requestHandler.runScript(req.postRequestScript, {
|
|
244
247
|
envVars: updatedEnvVars,
|
|
245
248
|
collectionVars: updatedCollectionVars,
|
|
246
249
|
globals: updatedGlobals,
|
|
@@ -250,8 +253,8 @@ async function executeRequest(req, collectionVars, envVars, globals, verbose) {
|
|
|
250
253
|
testResults = r.testResults;
|
|
251
254
|
consoleOutput = r.consoleOutput;
|
|
252
255
|
postScriptError = r.error;
|
|
253
|
-
|
|
254
|
-
await
|
|
256
|
+
requestHandler.patchGlobals(r.updatedGlobals);
|
|
257
|
+
await requestHandler.persistGlobals();
|
|
255
258
|
if (verbose && r.consoleOutput.length) r.consoleOutput.forEach((l) => console.log(color(` [post] ${l}`, C.gray)));
|
|
256
259
|
}
|
|
257
260
|
const allPassed = testResults.every((t) => t.passed);
|
|
@@ -311,7 +314,7 @@ async function main() {
|
|
|
311
314
|
console.error(color(`Error: could not read workspace file: ${wsPath}`, C.red));
|
|
312
315
|
process.exit(1);
|
|
313
316
|
}
|
|
314
|
-
await
|
|
317
|
+
await requestHandler.loadGlobals(wsDir);
|
|
315
318
|
const collections = await loadCollections(workspace, wsDir);
|
|
316
319
|
const environments = await loadEnvironments(workspace, wsDir);
|
|
317
320
|
const env = envName ? environments.find((e) => e.name.toLowerCase() === envName.toLowerCase()) ?? null : null;
|
|
@@ -334,12 +337,14 @@ async function main() {
|
|
|
334
337
|
const items = collectTagged(col.rootFolder, col.requests, col.collectionVariables ?? {}, filterTags);
|
|
335
338
|
if (items.length === 0) continue;
|
|
336
339
|
if (!firstColName) firstColName = col.name;
|
|
337
|
-
const envVars = await
|
|
338
|
-
const globals =
|
|
340
|
+
const envVars = await requestHandler.buildEnvVars(env);
|
|
341
|
+
const globals = requestHandler.getGlobals();
|
|
339
342
|
console.log(color(` ┌ ${col.name}`, C.bold, C.white));
|
|
343
|
+
const workspaceTls = workspace.settings?.tls;
|
|
344
|
+
const effectiveTls = col.tls ? { ...workspaceTls, ...col.tls } : workspaceTls;
|
|
340
345
|
let bailed = false;
|
|
341
346
|
for (const item of items) {
|
|
342
|
-
const result = await executeRequest(item.request, item.collectionVars, envVars, globals, verbose);
|
|
347
|
+
const result = await executeRequest(item.request, item.collectionVars, envVars, globals, verbose, effectiveTls);
|
|
343
348
|
printResult(result, verbose);
|
|
344
349
|
allResults.push(result);
|
|
345
350
|
summary.total++;
|
package/out/preload/index.js
CHANGED
|
@@ -79,6 +79,10 @@ const api = {
|
|
|
79
79
|
// ─── Contract testing ─────────────────────────────────────────────────────
|
|
80
80
|
runContracts: (payload) => electron.ipcRenderer.invoke("contract:run", payload),
|
|
81
81
|
inferContractSchema: (jsonBody) => electron.ipcRenderer.invoke("contract:inferSchema", jsonBody),
|
|
82
|
+
// ─── Script hooks ─────────────────────────────────────────────────────────
|
|
83
|
+
runScriptHook: (payload) => electron.ipcRenderer.invoke("script:run-hook", payload),
|
|
84
|
+
// ─── Zoom ─────────────────────────────────────────────────────────────────
|
|
85
|
+
setZoomFactor: (factor) => electron.webFrame.setZoomFactor(factor),
|
|
82
86
|
// ─── Platform ─────────────────────────────────────────────────────────────
|
|
83
87
|
platform: process.platform
|
|
84
88
|
};
|