@requesto/cli 1.8.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.
@@ -0,0 +1,121 @@
1
+ // ../../packages/engine/dist/scripts/sandbox-worker.js
2
+ import { parentPort } from "node:worker_threads";
3
+
4
+ // ../../packages/engine/dist/scripts/sandbox-core.js
5
+ var SHADOWED_GLOBALS = `
6
+ "use strict";
7
+ const self = undefined;
8
+ const fetch = undefined;
9
+ const XMLHttpRequest = undefined;
10
+ const importScripts = undefined;
11
+ const globalThis = undefined;
12
+ const global = undefined;
13
+ const process = undefined;
14
+ const require = undefined;
15
+ const Buffer = undefined;
16
+ const module = undefined;
17
+ const exports = undefined;
18
+ `;
19
+ function createExpect(actual, inverted = false) {
20
+ const pass = (condition, message) => {
21
+ const fails = inverted ? condition : !condition;
22
+ if (fails)
23
+ throw new Error(inverted ? `Expected NOT: ${message}` : message);
24
+ };
25
+ return {
26
+ toBe: (expected) => pass(Object.is(actual, expected), `Expected ${JSON.stringify(actual)} to be ${JSON.stringify(expected)}`),
27
+ toEqual: (expected) => pass(JSON.stringify(actual) === JSON.stringify(expected), `Expected ${JSON.stringify(actual)} to equal ${JSON.stringify(expected)}`),
28
+ toBeTruthy: () => pass(Boolean(actual), `Expected ${JSON.stringify(actual)} to be truthy`),
29
+ toBeFalsy: () => pass(!actual, `Expected ${JSON.stringify(actual)} to be falsy`),
30
+ toContain: (expected) => {
31
+ if (Array.isArray(actual)) {
32
+ pass(actual.includes(expected), `Expected array to contain ${JSON.stringify(expected)}`);
33
+ } else if (typeof actual === "string") {
34
+ pass(actual.includes(String(expected)), `Expected "${actual}" to contain "${String(expected)}"`);
35
+ } else {
36
+ throw new Error("toContain requires an array or string");
37
+ }
38
+ },
39
+ toHaveLength: (expected) => {
40
+ const len = actual?.length;
41
+ pass(len === expected, `Expected length ${String(len)} to equal ${String(expected)}`);
42
+ },
43
+ toBeGreaterThan: (expected) => pass(actual > expected, `Expected ${String(actual)} to be greater than ${String(expected)}`),
44
+ toBeLessThan: (expected) => pass(actual < expected, `Expected ${String(actual)} to be less than ${String(expected)}`),
45
+ toBeGreaterThanOrEqual: (expected) => pass(actual >= expected, `Expected ${String(actual)} to be >= ${String(expected)}`),
46
+ toBeLessThanOrEqual: (expected) => pass(actual <= expected, `Expected ${String(actual)} to be <= ${String(expected)}`),
47
+ toMatch: (pattern) => {
48
+ const regex = typeof pattern === "string" ? new RegExp(pattern) : pattern;
49
+ pass(regex.test(String(actual)), `Expected "${String(actual)}" to match ${String(regex)}`);
50
+ },
51
+ toBeNull: () => pass(actual === null, `Expected ${JSON.stringify(actual)} to be null`),
52
+ toBeUndefined: () => pass(actual === void 0, `Expected ${JSON.stringify(actual)} to be undefined`),
53
+ toBeDefined: () => pass(actual !== void 0, `Expected ${JSON.stringify(actual)} to be defined`),
54
+ get not() {
55
+ return createExpect(actual, !inverted);
56
+ }
57
+ };
58
+ }
59
+ function createEnvironment(env) {
60
+ const envStore = { ...env };
61
+ return {
62
+ store: envStore,
63
+ api: {
64
+ get: (key) => envStore[key] ?? "",
65
+ set: (key, value) => {
66
+ envStore[key] = String(value);
67
+ }
68
+ }
69
+ };
70
+ }
71
+ function executePreRequestScript(script, context) {
72
+ const { store, api } = createEnvironment(context.env);
73
+ const request = { ...context.request };
74
+ const fn = new Function("environment", "request", `${SHADOWED_GLOBALS}
75
+ ${script}`);
76
+ fn(api, request);
77
+ return { envOverrides: store };
78
+ }
79
+ function executeTestScript(script, context) {
80
+ const results = [];
81
+ const { response: responseCtx, request } = context;
82
+ const { store, api } = createEnvironment(context.env);
83
+ const response = {
84
+ status: responseCtx.status,
85
+ statusText: responseCtx.statusText,
86
+ headers: { ...responseCtx.headers },
87
+ body: responseCtx.body,
88
+ duration: responseCtx.duration,
89
+ json: () => JSON.parse(responseCtx.body)
90
+ };
91
+ const test = (name, fn2) => {
92
+ try {
93
+ fn2();
94
+ results.push({ name, passed: true });
95
+ } catch (err) {
96
+ results.push({
97
+ name,
98
+ passed: false,
99
+ error: err instanceof Error ? err.message : String(err)
100
+ });
101
+ }
102
+ };
103
+ const expect = (actual) => createExpect(actual);
104
+ const fn = new Function("test", "expect", "response", "request", "environment", `${SHADOWED_GLOBALS}
105
+ ${script}`);
106
+ fn(test, expect, response, request, api);
107
+ return { testResults: results, envOverrides: store };
108
+ }
109
+
110
+ // ../../packages/engine/dist/scripts/sandbox-worker.js
111
+ parentPort?.on("message", (message) => {
112
+ try {
113
+ if (message.type === "pre-request") {
114
+ parentPort?.postMessage(executePreRequestScript(message.script, message.context));
115
+ } else {
116
+ parentPort?.postMessage(executeTestScript(message.script, message.context));
117
+ }
118
+ } catch (err) {
119
+ parentPort?.postMessage({ error: err instanceof Error ? err.message : String(err) });
120
+ }
121
+ });
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@requesto/cli",
3
+ "version": "1.8.0",
4
+ "description": "Run your Requesto collections from the terminal and CI pipelines",
5
+ "type": "module",
6
+ "main": "dist/index.mjs",
7
+ "bin": {
8
+ "requesto": "./dist/index.mjs"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "engines": {
14
+ "node": ">=20"
15
+ },
16
+ "scripts": {
17
+ "dev": "tsx src/bin.ts",
18
+ "build": "node scripts/bundle.mjs",
19
+ "start": "node dist/index.mjs",
20
+ "test": "vitest run",
21
+ "test:watch": "vitest"
22
+ },
23
+ "dependencies": {
24
+ "commander": "^15.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^26.4.0",
28
+ "esbuild": "^0.28.1",
29
+ "requesto-backend": "1.8.0",
30
+ "requesto-engine": "1.8.0",
31
+ "tsx": "^4.23.1",
32
+ "typescript": "^7.0.2",
33
+ "vitest": "^4.1.10"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ }
38
+ }