@t0.labs/daxta 0.3.1 → 0.3.2
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/dist/cli/test.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Run project tests with recording → build → print docs URL.
|
|
3
|
+
* Quiet: jest output only, then Docs ready + Next.
|
|
3
4
|
*/
|
|
4
5
|
export declare function runDaxtaTest(options?: {
|
|
5
6
|
cwd?: string;
|
package/dist/cli/test.js
CHANGED
|
@@ -118,7 +118,6 @@ function parseTestArgs(argv) {
|
|
|
118
118
|
continue;
|
|
119
119
|
}
|
|
120
120
|
if (token === '--no-serve') {
|
|
121
|
-
// legacy alias — default is already no standalone serve
|
|
122
121
|
standaloneServe = false;
|
|
123
122
|
continue;
|
|
124
123
|
}
|
|
@@ -162,13 +161,6 @@ function resolveJestBin(cwd) {
|
|
|
162
161
|
function readPkg(cwd) {
|
|
163
162
|
return JSON.parse((0, fs_1.readFileSync)(path.join(cwd, 'package.json'), 'utf8'));
|
|
164
163
|
}
|
|
165
|
-
function detectPackageManager(cwd, pkg) {
|
|
166
|
-
if ((0, fs_1.existsSync)(path.join(cwd, 'pnpm-lock.yaml')) || pkg.packageManager?.startsWith('pnpm'))
|
|
167
|
-
return 'pnpm';
|
|
168
|
-
if ((0, fs_1.existsSync)(path.join(cwd, 'yarn.lock')))
|
|
169
|
-
return 'yarn';
|
|
170
|
-
return 'npm';
|
|
171
|
-
}
|
|
172
164
|
function resolveBaseConfigPath(cwd, options) {
|
|
173
165
|
if (options.configFromFlag) {
|
|
174
166
|
return path.isAbsolute(options.configFromFlag)
|
|
@@ -191,17 +183,39 @@ function resolveBaseConfigPath(cwd, options) {
|
|
|
191
183
|
}
|
|
192
184
|
return preferred;
|
|
193
185
|
}
|
|
186
|
+
function jestExtrasFromCommand(command) {
|
|
187
|
+
if (!command)
|
|
188
|
+
return [];
|
|
189
|
+
const extra = [];
|
|
190
|
+
const tokens = command.split(/\s+/).filter(Boolean);
|
|
191
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
192
|
+
const t = tokens[i];
|
|
193
|
+
if (t === 'jest' || t.endsWith('/jest') || t === 'cross-env')
|
|
194
|
+
continue;
|
|
195
|
+
if (t === 'daxta' || t === 'test' || t === '--yes' || t === '-y')
|
|
196
|
+
continue;
|
|
197
|
+
if (t.startsWith('NODE_OPTIONS=') || (t.includes('=') && !t.startsWith('-')))
|
|
198
|
+
continue;
|
|
199
|
+
if (t === '--config' || t === '-c') {
|
|
200
|
+
i += 1;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (t.startsWith('--config='))
|
|
204
|
+
continue;
|
|
205
|
+
extra.push(t);
|
|
206
|
+
}
|
|
207
|
+
return extra;
|
|
208
|
+
}
|
|
194
209
|
/**
|
|
195
|
-
*
|
|
210
|
+
* Run project tests with recording → build → print docs URL.
|
|
211
|
+
* Quiet: jest output only, then Docs ready + Next.
|
|
196
212
|
*/
|
|
197
213
|
async function runDaxtaTest(options = {}) {
|
|
198
214
|
const cwd = options.cwd ?? process.cwd();
|
|
199
215
|
const parsed = parseTestArgs(options.argv ?? []);
|
|
200
216
|
const pkg = readPkg(cwd);
|
|
201
|
-
const pm = detectPackageManager(cwd, pkg);
|
|
202
217
|
(0, config_1.resetConfig)();
|
|
203
218
|
let config = (0, config_1.getConfig)(true);
|
|
204
|
-
(0, ui_1.banner)('DAxTA test', pkg.name || path.basename(cwd));
|
|
205
219
|
const scriptName = await (0, discover_test_1.resolveTestScript)({
|
|
206
220
|
cwd,
|
|
207
221
|
scripts: pkg.scripts,
|
|
@@ -209,26 +223,21 @@ async function runDaxtaTest(options = {}) {
|
|
|
209
223
|
yes: parsed.yes,
|
|
210
224
|
flag: parsed.scriptFromFlag,
|
|
211
225
|
});
|
|
212
|
-
// Prefer saved original command — package.json may already be wrapped as `daxta test --yes`
|
|
213
226
|
let scriptCommand = config.testCommand ||
|
|
214
227
|
(scriptName && pkg.scripts?.[scriptName] && !(0, discover_test_1.isDaxtaWrappedScript)(pkg.scripts[scriptName])
|
|
215
228
|
? pkg.scripts[scriptName]
|
|
216
229
|
: undefined);
|
|
217
230
|
if (scriptName && (!config.testScript || !config.testCommand) && scriptCommand) {
|
|
218
|
-
|
|
231
|
+
(0, discover_test_1.upsertTestWiringInConfig)(cwd, { testScript: scriptName, testCommand: scriptCommand });
|
|
219
232
|
(0, config_1.resetConfig)();
|
|
220
233
|
config = (0, config_1.getConfig)(true);
|
|
221
234
|
scriptCommand = config.testCommand || scriptCommand;
|
|
222
235
|
}
|
|
223
|
-
if (scriptName) {
|
|
224
|
-
await (0, ui_1.step)('Test entry', () => (config.testCommand ? `${scriptName} · ${config.testCommand}` : `${pm} / ${scriptName}`), { paceMs: 600 });
|
|
225
|
-
}
|
|
226
236
|
const baseConfigPath = resolveBaseConfigPath(cwd, {
|
|
227
237
|
configFromFlag: parsed.configFromFlag,
|
|
228
238
|
jestConfig: config.jestConfig,
|
|
229
239
|
scriptCommand: scriptCommand || config.testCommand,
|
|
230
240
|
});
|
|
231
|
-
await (0, ui_1.step)('Jest config', () => path.relative(cwd, baseConfigPath), { paceMs: 600 });
|
|
232
241
|
let base;
|
|
233
242
|
try {
|
|
234
243
|
base = loadJestJson(baseConfigPath);
|
|
@@ -240,96 +249,46 @@ async function runDaxtaTest(options = {}) {
|
|
|
240
249
|
const configDir = path.dirname(baseConfigPath);
|
|
241
250
|
const tmpDir = path.join(cwd, 'daxta', 'out');
|
|
242
251
|
(0, fs_1.mkdirSync)(tmpDir, { recursive: true });
|
|
243
|
-
|
|
252
|
+
(0, fs_1.writeFileSync)(path.join(tmpDir, 'jest.daxta.runtime.json'), `${JSON.stringify({ ...merged, _source: path.relative(tmpDir, baseConfigPath) }, null, 2)}\n`);
|
|
244
253
|
const siblingTmp = path.join(configDir, '.jest.daxta.runtime.json');
|
|
245
254
|
(0, fs_1.writeFileSync)(siblingTmp, `${JSON.stringify(merged, null, 2)}\n`);
|
|
246
|
-
(0, fs_1.writeFileSync)(tmpConfig, `${JSON.stringify({ ...merged, _source: path.relative(tmpDir, baseConfigPath) }, null, 2)}\n`);
|
|
247
255
|
(0, recorder_1.clearWorkerHits)();
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const t = tokens[i];
|
|
259
|
-
if (t === 'jest' || t.endsWith('/jest') || t === 'cross-env')
|
|
260
|
-
continue;
|
|
261
|
-
if (t === 'daxta' || t === 'test' || t === '--yes' || t === '-y')
|
|
262
|
-
continue;
|
|
263
|
-
if (t.startsWith('NODE_OPTIONS=') || (t.includes('=') && !t.startsWith('-')))
|
|
264
|
-
continue;
|
|
265
|
-
if (t === '--config' || t === '-c') {
|
|
266
|
-
i += 1;
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
if (t.startsWith('--config='))
|
|
270
|
-
continue;
|
|
271
|
-
extraFromScript.push(t);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
const result = (0, child_process_1.spawnSync)(jestBin, ['--config', siblingTmp, ...extraFromScript, ...parsed.passthrough], {
|
|
275
|
-
cwd,
|
|
276
|
-
stdio: 'inherit',
|
|
277
|
-
shell: process.platform === 'win32',
|
|
278
|
-
env: process.env,
|
|
279
|
-
});
|
|
280
|
-
testStatus = result.status ?? 1;
|
|
281
|
-
if (result.error)
|
|
282
|
-
throw result.error;
|
|
283
|
-
return testStatus === 0 ? 'passed' : `exit ${testStatus}`;
|
|
284
|
-
}, { paceMs: 400, spinner: false });
|
|
256
|
+
const jestBin = resolveJestBin(cwd);
|
|
257
|
+
const result = (0, child_process_1.spawnSync)(jestBin, ['--config', siblingTmp, ...jestExtrasFromCommand(scriptCommand || config.testCommand), ...parsed.passthrough], {
|
|
258
|
+
cwd,
|
|
259
|
+
stdio: 'inherit',
|
|
260
|
+
shell: process.platform === 'win32',
|
|
261
|
+
env: { ...process.env, DAXTA_QUIET: '1' },
|
|
262
|
+
});
|
|
263
|
+
const testStatus = result.status ?? 1;
|
|
264
|
+
if (result.error)
|
|
265
|
+
throw result.error;
|
|
285
266
|
try {
|
|
286
267
|
(0, fs_1.unlinkSync)(siblingTmp);
|
|
287
268
|
}
|
|
288
269
|
catch {
|
|
289
270
|
// ignore
|
|
290
271
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
(0, incremental_1.clearPartialMarker)();
|
|
295
|
-
if (build.skipped) {
|
|
296
|
-
buildSummary = 'no hits yet';
|
|
297
|
-
return buildSummary;
|
|
298
|
-
}
|
|
299
|
-
buildSummary = `${build.hits} hits · ${build.operations} ops`;
|
|
300
|
-
return {
|
|
301
|
-
summary: build.changed ? 'updated' : 'ready',
|
|
302
|
-
details: [
|
|
303
|
-
`${build.hits} recorded hits`,
|
|
304
|
-
`${build.operations} operations`,
|
|
305
|
-
`out · ${path.relative(cwd, config.outDir)}`,
|
|
306
|
-
],
|
|
307
|
-
};
|
|
308
|
-
}, { paceMs: 800 });
|
|
272
|
+
const build = (0, build_spec_1.buildDaxtaSpec)({ silent: true, html: true });
|
|
273
|
+
(0, incremental_1.clearPartialMarker)();
|
|
274
|
+
const buildSummary = build.skipped ? 'no hits yet' : `${build.hits} hits · ${build.operations} ops`;
|
|
309
275
|
const docsBase = (0, paths_1.getDocsBasePath)();
|
|
310
276
|
const appDocsUrl = `${config.baseUrl.replace(/\/$/, '')}${docsBase}`;
|
|
311
|
-
// Primary path: apiDocs(app) exposes /docs on the Nest app port.
|
|
312
|
-
// Optional --serve spins a standalone viewer (no app required).
|
|
313
277
|
if (parsed.standaloneServe) {
|
|
314
278
|
const port = parsed.port ?? config.port;
|
|
315
|
-
(0, ui_1.box)('
|
|
316
|
-
`${ui_1.c.green('✔')} ${ui_1.c.bold(`http://127.0.0.1:${port}${docsBase}`)}`,
|
|
317
|
-
`${ui_1.c.dim('openapi')} http://127.0.0.1:${port}${docsBase}/openapi.json`,
|
|
279
|
+
(0, ui_1.box)('Docs ready', [
|
|
280
|
+
`${ui_1.c.green('✔')} ${ui_1.c.bold(`http://127.0.0.1:${port}${docsBase}`)} ${ui_1.c.dim(`(${buildSummary})`)}`,
|
|
318
281
|
testStatus !== 0 ? `${ui_1.c.yellow('!')} tests exited ${testStatus}` : `${ui_1.c.dim('ctrl+c')} to stop`,
|
|
319
|
-
]);
|
|
282
|
+
].filter(Boolean));
|
|
320
283
|
(0, serve_1.serveApiDocs)({ port });
|
|
321
284
|
return;
|
|
322
285
|
}
|
|
323
286
|
(0, ui_1.box)('Docs ready', [
|
|
324
|
-
`${ui_1.c.green('✔')}
|
|
325
|
-
`${ui_1.c.
|
|
326
|
-
`${ui_1.c.dim('via')} apiDocs(app) · set ${ui_1.c.cyan('DAXTA_DOCS=true')}`,
|
|
287
|
+
`${ui_1.c.green('✔')} ${ui_1.c.cyan(appDocsUrl)} ${ui_1.c.dim(`(${buildSummary})`)}`,
|
|
288
|
+
`${ui_1.c.dim('DAXTA_DOCS=true')} required on app start`,
|
|
327
289
|
testStatus !== 0 ? `${ui_1.c.yellow('!')} tests exited ${testStatus}` : '',
|
|
328
290
|
].filter(Boolean));
|
|
329
|
-
(0, ui_1.nextSteps)([
|
|
330
|
-
{ cmd: 'DAXTA_DOCS=true pnpm start:dev', why: `open ${appDocsUrl}` },
|
|
331
|
-
{ cmd: 'daxta test --serve', why: 'standalone viewer without starting the app' },
|
|
332
|
-
]);
|
|
291
|
+
(0, ui_1.nextSteps)([{ cmd: 'DAXTA_DOCS=true pnpm start:dev', why: `open ${appDocsUrl}` }]);
|
|
333
292
|
if (testStatus !== 0)
|
|
334
293
|
process.exit(testStatus);
|
|
335
294
|
}
|
|
@@ -3,18 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = daxtaGlobalTeardown;
|
|
4
4
|
const incremental_1 = require("../build/incremental");
|
|
5
5
|
const build_spec_1 = require("../build/build-spec");
|
|
6
|
+
/** Optional jest globalTeardown — silent; `daxta test` prints the final Docs ready. */
|
|
6
7
|
async function daxtaGlobalTeardown() {
|
|
7
8
|
try {
|
|
8
|
-
|
|
9
|
-
if (result.changed) {
|
|
10
|
-
console.log(`DAxTA docs updated (${result.hits} hits, ${result.operations} operations — ${result.updated} updated, ${result.unchanged} unchanged)`);
|
|
11
|
-
}
|
|
12
|
-
else if (!result.skipped) {
|
|
13
|
-
console.log(`DAxTA docs ready (${result.hits} hits, ${result.operations} operations)`);
|
|
14
|
-
}
|
|
9
|
+
(0, build_spec_1.buildDaxtaSpec)({ silent: true });
|
|
15
10
|
(0, incremental_1.clearPartialMarker)();
|
|
16
11
|
}
|
|
17
|
-
catch
|
|
18
|
-
|
|
12
|
+
catch {
|
|
13
|
+
// never fail teardown
|
|
19
14
|
}
|
|
20
15
|
}
|
package/dist/jest/reporter.js
CHANGED
|
@@ -5,24 +5,22 @@ class DaxtaJestReporter {
|
|
|
5
5
|
}
|
|
6
6
|
onTestResult() {
|
|
7
7
|
this.suitesDone += 1;
|
|
8
|
-
this.rebuild(
|
|
8
|
+
this.rebuild({ html: this.suitesDone % 5 === 0 });
|
|
9
9
|
}
|
|
10
10
|
onRunComplete() {
|
|
11
|
-
this.rebuild(
|
|
11
|
+
this.rebuild({ html: true });
|
|
12
12
|
}
|
|
13
|
-
rebuild(
|
|
13
|
+
rebuild(options) {
|
|
14
14
|
try {
|
|
15
15
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
16
16
|
require('reflect-metadata');
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
18
18
|
const { rebuildFromDisk } = require('../build/incremental');
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
console.log(`DAxTA ${result.changed ? 'updated' : 'checked'} after ${label}: ${result.hits} hits, ${result.operations} ops${options.html ? '' : ' (json only)'}`);
|
|
22
|
-
}
|
|
19
|
+
rebuildFromDisk({ silent: true, force: true, html: options.html });
|
|
20
|
+
// Keep jest output clean — final summary comes from `daxta test` (Docs ready).
|
|
23
21
|
}
|
|
24
|
-
catch
|
|
25
|
-
|
|
22
|
+
catch {
|
|
23
|
+
// incremental rebuild must never fail the test run
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
26
|
}
|