@t0.labs/daxta 0.4.10 → 0.4.12
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 +3 -3
- package/assets/viewer.html +40 -10
- package/dist/build/build-spec.d.ts +1 -1
- package/dist/build/build-spec.js +41 -22
- package/dist/cli/jest-hooks.d.ts +2 -1
- package/dist/cli/jest-hooks.js +23 -1
- package/dist/serve/spec-utils.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,8 +33,8 @@ Jest finishes — Docs ready on /docs
|
|
|
33
33
|
Docs ready → http://localhost:3000/docs
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
1. **Install** attaches DAxTA as a Jest plugin (`setupFilesAfterEnv` + reporter). Your existing `test:integration` stays the entrypoint — DAxTA does not wrap the process.
|
|
37
|
-
2. **During the run** only traffic is recorded (disk flush). OpenAPI/HTML is
|
|
36
|
+
1. **Install** attaches DAxTA as a Jest plugin (`setupFilesAfterEnv` + reporter, and `globalSetup` when you don’t already have one). Your existing `test:integration` stays the entrypoint — DAxTA does not wrap the process.
|
|
37
|
+
2. **During the run** only traffic is recorded (disk flush). OpenAPI/HTML is rebuilt once when Jest finishes, from **this run’s hits only** (previous worker shards are cleared so examples do not stack).
|
|
38
38
|
3. `apiDocs(app)` in `main.ts` serves the generated viewer when `DAXTA_DOCS=true`.
|
|
39
39
|
|
|
40
40
|
|
|
@@ -78,7 +78,7 @@ npx @t0.labs/daxta uninstall
|
|
|
78
78
|
Otomatik temizler:
|
|
79
79
|
|
|
80
80
|
- `apiDocs` + `@t0.labs/daxta` import (`main.ts`)
|
|
81
|
-
- Jest `setup` + `jest-reporter`
|
|
81
|
+
- Jest `setup` + `jest-reporter` (+ `globalSetup` when missing)
|
|
82
82
|
- `daxta.config.*` ve `daxta/` output
|
|
83
83
|
- `.gitignore` / `.env` içindeki DAxTA satırları
|
|
84
84
|
- `@t0.labs/daxta` paketi
|
package/assets/viewer.html
CHANGED
|
@@ -2112,6 +2112,7 @@
|
|
|
2112
2112
|
const tagParts = segments.filter((part) => !String(part).startsWith("{"));
|
|
2113
2113
|
const tag = tagParts.length ? tagParts.join(" / ") : "API";
|
|
2114
2114
|
cleaned.tags = [tag];
|
|
2115
|
+
cleaned["x-tree-segments"] = segments;
|
|
2115
2116
|
tagNames.add(tag);
|
|
2116
2117
|
if (exportPath !== urlPath) cleaned["x-daxta-url-path"] = urlPath;
|
|
2117
2118
|
itemOut[method] = cleaned;
|
|
@@ -2253,21 +2254,52 @@
|
|
|
2253
2254
|
};
|
|
2254
2255
|
};
|
|
2255
2256
|
|
|
2257
|
+
const collectionFolderSegments = (urlPath, operation) => {
|
|
2258
|
+
const fromTree = operation && operation["x-tree-segments"];
|
|
2259
|
+
const parts = Array.isArray(fromTree) && fromTree.length
|
|
2260
|
+
? fromTree.map(String)
|
|
2261
|
+
: String(urlPath || "").split("/").filter(Boolean);
|
|
2262
|
+
const named = parts.filter((part) => part && !part.startsWith("{"));
|
|
2263
|
+
return named.length ? named : ["API"];
|
|
2264
|
+
};
|
|
2265
|
+
|
|
2266
|
+
const pushIntoFolderTree = (root, segments, requestItem) => {
|
|
2267
|
+
let level = root;
|
|
2268
|
+
for (let index = 0; index < segments.length; index += 1) {
|
|
2269
|
+
const name = segments[index];
|
|
2270
|
+
let folder = level.find((entry) => entry && entry.name === name && Array.isArray(entry.item) && !entry.request);
|
|
2271
|
+
if (!folder) {
|
|
2272
|
+
folder = { name, item: [] };
|
|
2273
|
+
level.push(folder);
|
|
2274
|
+
}
|
|
2275
|
+
if (index === segments.length - 1) folder.item.push(requestItem);
|
|
2276
|
+
else level = folder.item;
|
|
2277
|
+
}
|
|
2278
|
+
};
|
|
2279
|
+
|
|
2280
|
+
const sortCollectionTree = (items) => {
|
|
2281
|
+
const folders = items.filter((entry) => entry && Array.isArray(entry.item) && !entry.request);
|
|
2282
|
+
const requests = items.filter((entry) => entry && entry.request);
|
|
2283
|
+
folders.sort((left, right) => String(left.name).localeCompare(String(right.name)));
|
|
2284
|
+
for (const folder of folders) folder.item = sortCollectionTree(folder.item);
|
|
2285
|
+
requests.sort((left, right) => String(left.name).localeCompare(String(right.name)));
|
|
2286
|
+
return [...folders, ...requests];
|
|
2287
|
+
};
|
|
2288
|
+
|
|
2256
2289
|
/**
|
|
2257
2290
|
* Postman Collection v2.1 — example `name` = scenario title (not "Created" / "Bad Request").
|
|
2258
|
-
*
|
|
2291
|
+
* Folders follow the docs tree (v1 → admin → product), not a single joined tag.
|
|
2259
2292
|
*/
|
|
2260
2293
|
const buildPostmanCollection = (openapi) => {
|
|
2261
2294
|
const serverUrl = (openapi.servers && openapi.servers[0] && openapi.servers[0].url) || "{{baseUrl}}";
|
|
2262
|
-
const
|
|
2295
|
+
const root = [];
|
|
2263
2296
|
|
|
2264
2297
|
for (const [urlPath, pathItem] of Object.entries(openapi.paths || {})) {
|
|
2265
2298
|
if (!pathItem || typeof pathItem !== "object") continue;
|
|
2266
2299
|
for (const method of HTTP_EXPORT) {
|
|
2267
2300
|
const operation = pathItem[method];
|
|
2268
2301
|
if (!operation || typeof operation !== "object") continue;
|
|
2269
|
-
const
|
|
2270
|
-
if (!folders.has(folderName)) folders.set(folderName, []);
|
|
2302
|
+
const requestPath = operation["x-daxta-url-path"] || urlPath;
|
|
2271
2303
|
|
|
2272
2304
|
const headerParams = (operation.parameters || []).filter((param) => param && param.in === "header" && param.name);
|
|
2273
2305
|
const requestHeaders = headerParams.map((param) => ({
|
|
@@ -2288,7 +2320,7 @@
|
|
|
2288
2320
|
const baseRequest = {
|
|
2289
2321
|
method: method.toUpperCase(),
|
|
2290
2322
|
header: requestHeaders,
|
|
2291
|
-
url: postmanUrlFromPath(serverUrl,
|
|
2323
|
+
url: postmanUrlFromPath(serverUrl, requestPath),
|
|
2292
2324
|
description: operation.summary || "",
|
|
2293
2325
|
};
|
|
2294
2326
|
if (defaultBody !== undefined) {
|
|
@@ -2336,17 +2368,15 @@
|
|
|
2336
2368
|
}
|
|
2337
2369
|
}
|
|
2338
2370
|
|
|
2339
|
-
|
|
2340
|
-
name: operation.summary || method.toUpperCase() + " " +
|
|
2371
|
+
pushIntoFolderTree(root, collectionFolderSegments(urlPath, operation), {
|
|
2372
|
+
name: operation.summary || method.toUpperCase() + " " + requestPath,
|
|
2341
2373
|
request: baseRequest,
|
|
2342
2374
|
response: responses,
|
|
2343
2375
|
});
|
|
2344
2376
|
}
|
|
2345
2377
|
}
|
|
2346
2378
|
|
|
2347
|
-
const item =
|
|
2348
|
-
.sort(([a], [b]) => a.localeCompare(b))
|
|
2349
|
-
.map(([name, children]) => ({ name, item: children }));
|
|
2379
|
+
const item = sortCollectionTree(root);
|
|
2350
2380
|
|
|
2351
2381
|
return {
|
|
2352
2382
|
info: {
|
package/dist/build/build-spec.js
CHANGED
|
@@ -42,6 +42,7 @@ const catalog_1 = require("../catalog");
|
|
|
42
42
|
const config_1 = require("../config");
|
|
43
43
|
const dto_fields_1 = require("../fields/dto-fields");
|
|
44
44
|
const path_util_1 = require("../path.util");
|
|
45
|
+
const recorder_1 = require("../recorder");
|
|
45
46
|
const paths_1 = require("../serve/paths");
|
|
46
47
|
const viewer_store_1 = require("../serve/viewer-store");
|
|
47
48
|
const METHOD_RANK = { get: 0, post: 1, put: 2, patch: 3, delete: 4 };
|
|
@@ -403,33 +404,48 @@ function dedupeScenarios(scenarios) {
|
|
|
403
404
|
return true;
|
|
404
405
|
});
|
|
405
406
|
}
|
|
406
|
-
|
|
407
|
-
|
|
407
|
+
/** `hits-w{workerId}-p{pid}.json` leftover from a previous Jest run must not stack. */
|
|
408
|
+
function currentRunWorkerFiles(outDir) {
|
|
409
|
+
const names = (0, fs_1.readdirSync)(outDir).filter((fileName) => fileName.startsWith('hits-w') && fileName.endsWith('.json'));
|
|
410
|
+
if (!names.length)
|
|
408
411
|
return [];
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}
|
|
420
|
-
}));
|
|
412
|
+
const hitsJsonPath = (0, paths_1.getHitsJsonPath)();
|
|
413
|
+
const watermark = (0, fs_1.existsSync)(hitsJsonPath) ? (0, fs_1.statSync)(hitsJsonPath).mtimeMs - 1000 : 0;
|
|
414
|
+
const fromThisRun = names.filter((fileName) => (0, fs_1.statSync)(path.join(outDir, fileName)).mtimeMs >= watermark);
|
|
415
|
+
const pool = fromThisRun.length ? fromThisRun : names;
|
|
416
|
+
const newestByWorker = new Map();
|
|
417
|
+
for (const fileName of pool) {
|
|
418
|
+
const workerId = fileName.match(/^hits-w([^-]+)-p\d+\.json$/)?.[1] ?? fileName;
|
|
419
|
+
const mtime = (0, fs_1.statSync)(path.join(outDir, fileName)).mtimeMs;
|
|
420
|
+
const prev = newestByWorker.get(workerId);
|
|
421
|
+
if (!prev || mtime >= prev.mtime)
|
|
422
|
+
newestByWorker.set(workerId, { fileName, mtime });
|
|
421
423
|
}
|
|
422
|
-
|
|
424
|
+
return [...newestByWorker.values()].map((entry) => entry.fileName);
|
|
425
|
+
}
|
|
426
|
+
function readHitFile(filePath, label) {
|
|
423
427
|
try {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
const parsed = JSON.parse((0, fs_1.readFileSync)((0, paths_1.getHitsJsonPath)(), 'utf8'));
|
|
427
|
-
return canonicalizeHits(Array.isArray(parsed) ? parsed : []);
|
|
428
|
+
const parsed = JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
|
|
429
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
428
430
|
}
|
|
429
431
|
catch (error) {
|
|
430
|
-
console.error(
|
|
432
|
+
console.error(`DAxTA: skipped corrupt hits file ${label}:`, error);
|
|
433
|
+
return [];
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
function loadHits() {
|
|
437
|
+
if (!(0, fs_1.existsSync)((0, paths_1.getOutDir)()))
|
|
431
438
|
return [];
|
|
439
|
+
const workerFiles = currentRunWorkerFiles((0, paths_1.getOutDir)());
|
|
440
|
+
if (workerFiles.length) {
|
|
441
|
+
const loaded = canonicalizeHits(workerFiles.flatMap((fileName) => readHitFile(path.join((0, paths_1.getOutDir)(), fileName), fileName)));
|
|
442
|
+
if (loaded.length)
|
|
443
|
+
return loaded;
|
|
432
444
|
}
|
|
445
|
+
// Fallback after workers were cleaned — last completed run's hits.json
|
|
446
|
+
if (!(0, fs_1.existsSync)((0, paths_1.getHitsJsonPath)()))
|
|
447
|
+
return [];
|
|
448
|
+
return canonicalizeHits(readHitFile((0, paths_1.getHitsJsonPath)(), 'hits.json'));
|
|
433
449
|
}
|
|
434
450
|
function sortOperations(entries) {
|
|
435
451
|
return [...entries].sort((left, right) => {
|
|
@@ -737,13 +753,16 @@ function buildDaxtaSpec(options = {}) {
|
|
|
737
753
|
const refreshHtml = writeHtml && (operationsChanged || metaChanged || viewerTemplateNewerThanHtml());
|
|
738
754
|
const changed = operationsChanged || hitsChanged || metaChanged || refreshHtml;
|
|
739
755
|
if (changed) {
|
|
740
|
-
|
|
741
|
-
writeJson((0, paths_1.getHitsJsonPath)(), hits);
|
|
756
|
+
writeJson((0, paths_1.getHitsJsonPath)(), hits);
|
|
742
757
|
if (operationsChanged || metaChanged)
|
|
743
758
|
writeJson((0, paths_1.getSpecJsonPath)(), spec);
|
|
744
759
|
if (refreshHtml)
|
|
745
760
|
(0, fs_1.writeFileSync)((0, paths_1.getHtmlPath)(), toStandaloneHtml(spec));
|
|
746
761
|
}
|
|
762
|
+
else {
|
|
763
|
+
writeJson((0, paths_1.getHitsJsonPath)(), hits);
|
|
764
|
+
}
|
|
765
|
+
(0, recorder_1.clearWorkerHits)();
|
|
747
766
|
const operations = countOperations(spec);
|
|
748
767
|
const result = {
|
|
749
768
|
skipped: false,
|
package/dist/cli/jest-hooks.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ export declare function resolveJestConfigPath(cwd: string, options: {
|
|
|
6
6
|
}): string | null;
|
|
7
7
|
/**
|
|
8
8
|
* Inject DAxTA as a Jest plugin (setup + reporter). Does not wrap the test process.
|
|
9
|
-
* Supports JSON and JS/CJS/MJS/TS config files.
|
|
9
|
+
* Supports JSON and JS/CJS/MJS/TS config files. Adds globalSetup only when missing
|
|
10
|
+
* (does not replace an existing user globalSetup).
|
|
10
11
|
*/
|
|
11
12
|
export declare function injectJestHooks(jestConfigPath: string, dryRun?: boolean): string[];
|
|
12
13
|
/** Restore package.json script if it was wrapped as `daxta test --yes`. */
|
package/dist/cli/jest-hooks.js
CHANGED
|
@@ -43,6 +43,7 @@ const path = __importStar(require("path"));
|
|
|
43
43
|
const discover_test_1 = require("./discover-test");
|
|
44
44
|
const SETUP = '@t0.labs/daxta/setup';
|
|
45
45
|
const REPORTER = '@t0.labs/daxta/jest-reporter';
|
|
46
|
+
const GLOBAL_SETUP = '@t0.labs/daxta/jest-global-setup';
|
|
46
47
|
function loadJestJson(filePath) {
|
|
47
48
|
return JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
|
|
48
49
|
}
|
|
@@ -135,6 +136,13 @@ function injectIntoJsSource(source) {
|
|
|
135
136
|
notes.push(`setupFilesAfterEnv = [${SETUP}]`);
|
|
136
137
|
}
|
|
137
138
|
}
|
|
139
|
+
if (!/\bglobalSetup\s*:/.test(next) && !next.includes(GLOBAL_SETUP)) {
|
|
140
|
+
const inserted = insertIntoObjectLiteral(next, `globalSetup: '${GLOBAL_SETUP}',`);
|
|
141
|
+
if (inserted) {
|
|
142
|
+
next = inserted;
|
|
143
|
+
notes.push(`globalSetup = ${GLOBAL_SETUP}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
138
146
|
if (!next.includes(REPORTER)) {
|
|
139
147
|
const range = findArrayPropRange(next, 'reporters');
|
|
140
148
|
if (range) {
|
|
@@ -177,6 +185,10 @@ function injectIntoJsonConfig(filePath, dryRun) {
|
|
|
177
185
|
data.reporters = reporters;
|
|
178
186
|
notes.push(`reporters += ${REPORTER}`);
|
|
179
187
|
}
|
|
188
|
+
if (!data.globalSetup) {
|
|
189
|
+
data.globalSetup = GLOBAL_SETUP;
|
|
190
|
+
notes.push(`globalSetup = ${GLOBAL_SETUP}`);
|
|
191
|
+
}
|
|
180
192
|
if (!dryRun && notes.length) {
|
|
181
193
|
(0, fs_1.writeFileSync)(filePath, `${JSON.stringify(data, null, 2)}\n`);
|
|
182
194
|
}
|
|
@@ -184,7 +196,8 @@ function injectIntoJsonConfig(filePath, dryRun) {
|
|
|
184
196
|
}
|
|
185
197
|
/**
|
|
186
198
|
* Inject DAxTA as a Jest plugin (setup + reporter). Does not wrap the test process.
|
|
187
|
-
* Supports JSON and JS/CJS/MJS/TS config files.
|
|
199
|
+
* Supports JSON and JS/CJS/MJS/TS config files. Adds globalSetup only when missing
|
|
200
|
+
* (does not replace an existing user globalSetup).
|
|
188
201
|
*/
|
|
189
202
|
function injectJestHooks(jestConfigPath, dryRun = false) {
|
|
190
203
|
if (!(0, fs_1.existsSync)(jestConfigPath))
|
|
@@ -261,6 +274,11 @@ function removeFromJsSource(source) {
|
|
|
261
274
|
if (plain.removed)
|
|
262
275
|
notes.push(`reporters -= ${REPORTER}`);
|
|
263
276
|
}
|
|
277
|
+
const globalSetupRe = new RegExp(`\\s*globalSetup\\s*:\\s*['"]${GLOBAL_SETUP.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}['"]\\s*,?`);
|
|
278
|
+
if (globalSetupRe.test(next)) {
|
|
279
|
+
next = next.replace(globalSetupRe, '');
|
|
280
|
+
notes.push(`globalSetup -= ${GLOBAL_SETUP}`);
|
|
281
|
+
}
|
|
264
282
|
return { source: next, notes };
|
|
265
283
|
}
|
|
266
284
|
function removeFromJsonConfig(filePath, dryRun) {
|
|
@@ -288,6 +306,10 @@ function removeFromJsonConfig(filePath, dryRun) {
|
|
|
288
306
|
notes.push(`reporters -= ${REPORTER}`);
|
|
289
307
|
}
|
|
290
308
|
}
|
|
309
|
+
if (data.globalSetup === GLOBAL_SETUP) {
|
|
310
|
+
delete data.globalSetup;
|
|
311
|
+
notes.push(`globalSetup -= ${GLOBAL_SETUP}`);
|
|
312
|
+
}
|
|
291
313
|
if (!dryRun && notes.length) {
|
|
292
314
|
(0, fs_1.writeFileSync)(filePath, `${JSON.stringify(data, null, 2)}\n`);
|
|
293
315
|
}
|
package/dist/serve/spec-utils.js
CHANGED
|
@@ -132,6 +132,7 @@ function toTreeOrderedOpenApi(raw) {
|
|
|
132
132
|
const tagParts = segments.filter((part) => !part.startsWith('{'));
|
|
133
133
|
const tag = tagParts.length ? tagParts.join(' / ') : 'API';
|
|
134
134
|
cleaned.tags = [tag];
|
|
135
|
+
cleaned['x-tree-segments'] = segments;
|
|
135
136
|
tagNames.add(tag);
|
|
136
137
|
if (exportPath !== urlPath) {
|
|
137
138
|
cleaned['x-daxta-url-path'] = urlPath;
|