@reporters/gh 1.2.2 → 1.4.0

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.
Files changed (2) hide show
  1. package/index.js +47 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -28,6 +28,7 @@ const reporterUnicodeSymbolMap = {
28
28
  'test:coverage': '\u2139 ',
29
29
  'arrow:right': '\u25B6 ',
30
30
  'hyphen:minus': '\uFE63 ',
31
+ 'warning:alert': '\u26A0 ',
31
32
  };
32
33
 
33
34
  const indentMemo = new Map();
@@ -112,14 +113,25 @@ class SpecReporter extends Transform {
112
113
  #formatTestReport(type, data, prefix = '', indentation = '', hasChildren = false, showErrorDetails = true) {
113
114
  let color = reporterColorMap[type] ?? 'white';
114
115
  let symbol = reporterUnicodeSymbolMap[type] ?? ' ';
115
- const { skip, todo } = data;
116
+ const { skip, todo, expectFailure } = data;
116
117
  const durationMs = data.details?.duration_ms ? styleText(['gray', 'italic'], ` (${formatDuration(data.details.duration_ms)})`, { validateStream: !this.#isGitHubActions }) : '';
117
118
  let title = `${data.name}${durationMs}`;
118
119
 
119
120
  if (skip !== undefined) {
120
121
  title += ` # ${typeof skip === 'string' && skip.length ? skip : 'SKIP'}`;
122
+ color = 'gray';
123
+ symbol = reporterUnicodeSymbolMap['hyphen:minus'];
121
124
  } else if (todo !== undefined) {
122
125
  title += ` # ${typeof todo === 'string' && todo.length ? todo : 'TODO'}`;
126
+ if (type === 'test:fail') {
127
+ color = 'yellow';
128
+ symbol = reporterUnicodeSymbolMap['warning:alert'];
129
+ }
130
+ } else if (expectFailure !== undefined) {
131
+ /* c8 ignore next 3 */ // Not yest supported in current node
132
+ title += ' # EXPECTED FAILURE';
133
+ color = 'yellow';
134
+ symbol = reporterUnicodeSymbolMap['warning:alert'];
123
135
  }
124
136
 
125
137
  const error = showErrorDetails ? formatError(data.details?.error, indentation) : '';
@@ -128,11 +140,6 @@ class SpecReporter extends Transform {
128
140
  err = !error || data.details?.error?.failureType === 'subtestsFailed' ? '' : `\n${error}`;
129
141
  }
130
142
 
131
- if (skip !== undefined) {
132
- color = 'gray';
133
- symbol = reporterUnicodeSymbolMap['hyphen:minus'];
134
- }
135
-
136
143
  const header = `${indentation}${styleText(color, `${symbol}${title}`, { validateStream: !this.#isGitHubActions })}`;
137
144
  if (this.#isGitHubActions) {
138
145
  const eg = this.#reportedGroup ? endGroup : '';
@@ -238,11 +245,45 @@ class SpecReporter extends Transform {
238
245
  return this.#formatFailedTestResults();
239
246
  }
240
247
  break;
248
+ /* c8 ignore next 2 */
249
+ case 'test:interrupted':
250
+ return this.#formatInterruptedTests(data.tests) + res;
241
251
  default:
242
252
  }
243
253
  return ''; // No output for other event types
244
254
  }
245
255
 
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
+
246
287
  _transform({ type, data }, encoding, callback) {
247
288
  if (type === 'test:coverage' || type === 'test:stderr' || type === 'test:stdout') {
248
289
  /* c8 ignore next 3 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reporters/gh",
3
- "version": "1.2.2",
3
+ "version": "1.4.0",
4
4
  "description": "A github actions reporter for `node:test`",
5
5
  "type": "commonjs",
6
6
  "keywords": [