include stdout into the detail-float
All checks were successful
tests / test (push) Successful in 10s
All checks were successful
tests / test (push) Successful in 10s
This commit is contained in:
@@ -9,6 +9,8 @@ const {
|
||||
EVENT_RUN_BEGIN,
|
||||
EVENT_RUN_END,
|
||||
EVENT_SUITE_BEGIN,
|
||||
EVENT_TEST_BEGIN,
|
||||
EVENT_TEST_END,
|
||||
EVENT_TEST_PASS,
|
||||
EVENT_TEST_FAIL,
|
||||
EVENT_TEST_PENDING,
|
||||
@@ -32,11 +34,29 @@ function safeTitlePath(entity) {
|
||||
|
||||
class NdjsonReporter {
|
||||
constructor(runner /*, options */) {
|
||||
this.currentTest = null;
|
||||
this.stdoutByTest = new WeakMap();
|
||||
this.originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
||||
process.stdout.write = (...args) => {
|
||||
this.captureStdout(args[0]);
|
||||
return this.originalStdoutWrite(...args);
|
||||
};
|
||||
|
||||
runner
|
||||
.once(EVENT_RUN_BEGIN, () => {
|
||||
this.emit({ event: 'run-begin', total: runner.total });
|
||||
})
|
||||
|
||||
.on(EVENT_TEST_BEGIN, (test) => {
|
||||
this.currentTest = test;
|
||||
})
|
||||
|
||||
.on(EVENT_TEST_END, (test) => {
|
||||
if (this.currentTest === test) {
|
||||
this.currentTest = null;
|
||||
}
|
||||
})
|
||||
|
||||
// Optional suite-level event for describe.skip (helps jump to suite definition)
|
||||
.on(EVENT_SUITE_BEGIN, (suite) => {
|
||||
if (suite && suite.pending && suite.title) {
|
||||
@@ -78,10 +98,33 @@ class NdjsonReporter {
|
||||
})
|
||||
|
||||
.once(EVENT_RUN_END, () => {
|
||||
process.stdout.write = this.originalStdoutWrite;
|
||||
this.emit({ event: 'run-end', stats: runner.stats || null });
|
||||
});
|
||||
}
|
||||
|
||||
captureStdout(chunk) {
|
||||
if (!this.currentTest) return;
|
||||
const text = Buffer.isBuffer(chunk) ? chunk.toString() : String(chunk);
|
||||
if (!this.stdoutByTest.has(this.currentTest)) {
|
||||
this.stdoutByTest.set(this.currentTest, []);
|
||||
}
|
||||
this.stdoutByTest.get(this.currentTest).push(text);
|
||||
}
|
||||
|
||||
consumeStdoutLines(test) {
|
||||
const chunks = this.stdoutByTest.get(test);
|
||||
if (!chunks) return null;
|
||||
this.stdoutByTest.delete(test);
|
||||
const text = chunks.join('');
|
||||
if (!text) return null;
|
||||
const lines = text.split(/\r?\n/);
|
||||
if (lines.length > 0 && lines[lines.length - 1] === '') {
|
||||
lines.pop();
|
||||
}
|
||||
return lines.length > 0 ? lines : null;
|
||||
}
|
||||
|
||||
inferPendingType(test) {
|
||||
// Priority: explicit marker from UI wrappers
|
||||
if (test && test._akPendingType) return test._akPendingType;
|
||||
@@ -118,13 +161,16 @@ class NdjsonReporter {
|
||||
currentRetry: test && typeof test.currentRetry === 'function' ? test.currentRetry() : null,
|
||||
};
|
||||
|
||||
const output = this.consumeStdoutLines(test);
|
||||
if (output && output.length > 0) payload.output = output;
|
||||
|
||||
if (status === 'failed') payload.error = errorObj;
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
emit(obj) {
|
||||
process.stdout.write(JSON.stringify(obj) + '\n');
|
||||
this.originalStdoutWrite(JSON.stringify(obj) + '\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user