@t0.labs/daxta 1.1.7 → 1.2.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/README.md +54 -26
- package/assets/viewer.html +37 -11
- package/dist/build/build-spec.d.ts +2 -0
- package/dist/build/build-spec.js +69 -20
- package/dist/build/incremental.d.ts +2 -0
- package/dist/build/incremental.js +6 -2
- package/dist/catalog/index.d.ts +2 -1
- package/dist/catalog/index.js +38 -3
- package/dist/catalog/it-case.js +16 -5
- package/dist/catalog/test-title.js +3 -0
- package/dist/cli/discover-test.js +24 -22
- package/dist/cli/inject-main.js +22 -22
- package/dist/cli/install.d.ts +1 -0
- package/dist/cli/install.js +20 -6
- package/dist/cli/main.js +282 -23
- package/dist/cli/test.js +9 -4
- package/dist/cli/titles.js +57 -35
- package/dist/cli/tree.js +230 -75
- package/dist/cli/ui.d.ts +18 -0
- package/dist/cli/ui.js +124 -1
- package/dist/cli/uninstall.js +5 -3
- package/dist/config.d.ts +31 -1
- package/dist/config.js +8 -0
- package/dist/export/postman.d.ts +150 -0
- package/dist/export/postman.js +351 -0
- package/dist/jest/reporter.js +1 -1
- package/dist/recorder/index.js +85 -9
- package/dist/setup.js +6 -0
- package/package.json +1 -1
- package/assets/readme/demo.html +0 -1896
- package/dist/cli/start.d.ts +0 -13
- package/dist/cli/start.js +0 -103
package/dist/recorder/index.js
CHANGED
|
@@ -70,7 +70,7 @@ function pickHeaders(request) {
|
|
|
70
70
|
const name = rawName.toLowerCase();
|
|
71
71
|
if (SKIP_HEADERS.has(name))
|
|
72
72
|
continue;
|
|
73
|
-
if (name !== 'content-type' && !name.startsWith('x-'))
|
|
73
|
+
if (name !== 'content-type' && name !== 'authorization' && !name.startsWith('x-'))
|
|
74
74
|
continue;
|
|
75
75
|
if (rawValue == null || rawValue === '')
|
|
76
76
|
continue;
|
|
@@ -78,27 +78,102 @@ function pickHeaders(request) {
|
|
|
78
78
|
}
|
|
79
79
|
return Object.keys(headers).length ? headers : undefined;
|
|
80
80
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
function pickFetchHeaders(initHeaders) {
|
|
82
|
+
if (!initHeaders)
|
|
83
|
+
return undefined;
|
|
84
|
+
const headerObj = {};
|
|
85
|
+
if (typeof initHeaders.forEach === 'function') {
|
|
86
|
+
initHeaders.forEach((val, key) => {
|
|
87
|
+
headerObj[key] = val;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else if (Array.isArray(initHeaders)) {
|
|
91
|
+
for (const pair of initHeaders) {
|
|
92
|
+
if (Array.isArray(pair) && pair.length >= 2)
|
|
93
|
+
headerObj[String(pair[0])] = pair[1];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else if (typeof initHeaders === 'object') {
|
|
97
|
+
Object.assign(headerObj, initHeaders);
|
|
98
|
+
}
|
|
99
|
+
return pickHeaders({ header: headerObj });
|
|
100
|
+
}
|
|
101
|
+
function tryParseJson(raw) {
|
|
102
|
+
if (!raw)
|
|
103
|
+
return undefined;
|
|
104
|
+
try {
|
|
105
|
+
return JSON.parse(raw);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return raw;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function recordHttpHit(params) {
|
|
112
|
+
const url = new URL(params.rawUrl, 'http://localhost');
|
|
84
113
|
const test = currentTestName();
|
|
85
|
-
const
|
|
114
|
+
const method = (params.method || 'GET').toLowerCase();
|
|
115
|
+
const pathTemplate = (0, path_util_1.templatize)(url.pathname, test, method);
|
|
86
116
|
if (!pathTemplate)
|
|
87
117
|
return;
|
|
88
118
|
const query = Object.fromEntries(url.searchParams.entries());
|
|
89
119
|
const pathParams = (0, path_util_1.extractPathParams)(pathTemplate, url.pathname);
|
|
90
120
|
hits.push({
|
|
91
|
-
method
|
|
121
|
+
method,
|
|
92
122
|
path: pathTemplate,
|
|
123
|
+
status: params.status ?? 0,
|
|
124
|
+
reqBody: params.reqBody,
|
|
125
|
+
resBody: params.resBody,
|
|
126
|
+
query: Object.keys(query).length ? query : undefined,
|
|
127
|
+
pathParams: Object.keys(pathParams).length ? pathParams : undefined,
|
|
128
|
+
headers: params.headers,
|
|
129
|
+
test,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
function recordFromSuperagent(request, res) {
|
|
133
|
+
recordHttpHit({
|
|
134
|
+
method: request.method || 'GET',
|
|
135
|
+
rawUrl: request.url || '',
|
|
93
136
|
status: res.status ?? 0,
|
|
94
137
|
reqBody: request._data,
|
|
95
138
|
resBody: res.body,
|
|
96
|
-
query: Object.keys(query).length ? query : undefined,
|
|
97
|
-
pathParams: Object.keys(pathParams).length ? pathParams : undefined,
|
|
98
139
|
headers: pickHeaders(request),
|
|
99
|
-
test,
|
|
100
140
|
});
|
|
101
141
|
}
|
|
142
|
+
function patchFetch() {
|
|
143
|
+
if (g.__DAXTA_FETCH_PATCHED__ || typeof globalThis.fetch !== 'function')
|
|
144
|
+
return;
|
|
145
|
+
g.__DAXTA_FETCH_PATCHED__ = true;
|
|
146
|
+
const originalFetch = globalThis.fetch;
|
|
147
|
+
globalThis.fetch = async function daxtaFetch(input, init) {
|
|
148
|
+
const response = await originalFetch.call(this, input, init);
|
|
149
|
+
try {
|
|
150
|
+
const rawUrl = typeof input === 'string' ? input : input instanceof URL ? input.toString() : input.url;
|
|
151
|
+
const method = init?.method || (typeof input === 'object' && input !== null && 'method' in input ? input.method : 'GET');
|
|
152
|
+
const reqBody = typeof init?.body === 'string' ? tryParseJson(init.body) : undefined;
|
|
153
|
+
const headers = pickFetchHeaders(init?.headers ?? (typeof input === 'object' && input !== null && 'headers' in input ? input.headers : undefined));
|
|
154
|
+
let resBody;
|
|
155
|
+
try {
|
|
156
|
+
const text = await response.clone().text();
|
|
157
|
+
resBody = text ? tryParseJson(text) : undefined;
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// ignore unread/uncloneable body
|
|
161
|
+
}
|
|
162
|
+
recordHttpHit({
|
|
163
|
+
method,
|
|
164
|
+
rawUrl,
|
|
165
|
+
status: response.status,
|
|
166
|
+
reqBody,
|
|
167
|
+
resBody,
|
|
168
|
+
headers,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
// recording must never fail a test
|
|
173
|
+
}
|
|
174
|
+
return response;
|
|
175
|
+
};
|
|
176
|
+
}
|
|
102
177
|
function patchSuperagent(superagent) {
|
|
103
178
|
const proto = superagent.Request?.prototype;
|
|
104
179
|
if (!proto?.end || proto.__daxtaPatched)
|
|
@@ -143,6 +218,7 @@ function install() {
|
|
|
143
218
|
// ignore
|
|
144
219
|
}
|
|
145
220
|
}
|
|
221
|
+
patchFetch();
|
|
146
222
|
if (!g.__DAXTA_FLUSH_HOOK__) {
|
|
147
223
|
g.__DAXTA_FLUSH_HOOK__ = true;
|
|
148
224
|
const flushSafe = () => {
|
package/dist/setup.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const incremental_1 = require("./build/incremental");
|
|
4
|
+
const config_1 = require("./config");
|
|
3
5
|
const recorder_1 = require("./recorder");
|
|
4
6
|
(0, recorder_1.install)();
|
|
5
7
|
afterAll(() => {
|
|
8
|
+
if ((0, config_1.getConfig)().writeMode === 'incremental') {
|
|
9
|
+
(0, incremental_1.flushAndRebuild)({ silent: true, html: true });
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
6
12
|
(0, recorder_1.flush)();
|
|
7
13
|
});
|