Skip to content

Commit e2ee7ff

Browse files
MoLowclaude
andcommitted
feat: handle test:interrupted event
Align with nodejs/node#61676 which adds a `test:interrupted` event emitted on SIGINT. This shows which tests were running when the process was interrupted. - gh: display yellow "Interrupted while running:" section with test names and locations, closing any open GitHub Actions group - github: emit `::warning::` annotations for each interrupted test Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 889b64f commit e2ee7ff

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎packages/gh/index.js‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,42 @@ class SpecReporter extends Transform {
245245
return this.#formatFailedTestResults();
246246
}
247247
break;
248+
case 'test:interrupted':
249+
return this.#formatInterruptedTests(data.tests) + res;
248250
default:
249251
}
250252
return ''; // No output for other event types
251253
}
252254

255+
#formatInterruptedTests(tests) {
256+
if (tests.length === 0) {
257+
return '';
258+
}
259+
260+
const results = [];
261+
262+
if (this.#reportedGroup) {
263+
results.push(endGroup);
264+
this.#reportedGroup = false;
265+
}
266+
267+
results.push(
268+
`\n${styleText('yellow', 'Interrupted while running:', { validateStream: !this.#isGitHubActions })}\n`,
269+
);
270+
271+
for (let i = 0; i < tests.length; i += 1) {
272+
const test = tests[i];
273+
let msg = `${indent(test.nesting)}${reporterUnicodeSymbolMap['warning:alert']}${test.name}`;
274+
if (test.file) {
275+
const relPath = relative(this.#cwd, test.file);
276+
msg += ` ${styleText('gray', `(${relPath}:${test.line}:${test.column})`, { validateStream: !this.#isGitHubActions })}`;
277+
}
278+
results.push(msg);
279+
}
280+
281+
return `${results.join('\n')}\n`;
282+
}
283+
253284
_transform({ type, data }, encoding, callback) {
254285
if (type === 'test:coverage' || type === 'test:stderr' || type === 'test:stdout') {
255286
/* c8 ignore next 3 */

‎packages/github/index.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ function transformEvent(event) {
100100
return new Command('notice', toCommandProperties(extractLocation(event.data)), `${event.data.message}`).toString();
101101
}
102102
break;
103+
case 'test:interrupted': {
104+
const { tests } = event.data;
105+
let res = '';
106+
for (let i = 0; i < tests.length; i += 1) {
107+
const test = tests[i];
108+
const file = test.file ? getFilePath(test.file) : undefined;
109+
let msg = `Interrupted while running: ${test.name}`;
110+
if (file) {
111+
msg += ` at ${file}:${test.line}:${test.column}`;
112+
}
113+
res += new Command('warning', toCommandProperties({
114+
file,
115+
startLine: test.line,
116+
startColumn: test.column,
117+
title: `Interrupted: ${test.name}`,
118+
}), msg).toString();
119+
}
120+
return res;
121+
}
103122
default:
104123
break;
105124
}

0 commit comments

Comments
 (0)