Skip to content

Commit 79f71f4

Browse files
MoLowclaude
andauthored
feat: handle test:interrupted event (#172)
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 79f71f4

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

packages/gh/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,45 @@ class SpecReporter extends Transform {
245245
return this.#formatFailedTestResults();
246246
}
247247
break;
248+
/* c8 ignore next 2 */
249+
case 'test:interrupted':
250+
return this.#formatInterruptedTests(data.tests) + res;
248251
default:
249252
}
250253
return ''; // No output for other event types
251254
}
252255

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

packages/github/index.js

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

0 commit comments

Comments
 (0)