@reporters/gh 1.0.1 → 1.0.3

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 +26 -24
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -8,21 +8,21 @@ const { Transform } = require('node:stream');
8
8
  const { relative } = require('node:path');
9
9
  // eslint-disable-next-line import/no-unresolved
10
10
  const { spec: Spec } = require('node:test/reporters');
11
- const { emitSummary, handleEvent, isTopLevelDiagnostic } = require('@reporters/github');
11
+ const { getSummary, transformEvent, isTopLevelDiagnostic } = require('@reporters/github');
12
+ const { Command } = require('@reporters/github/gh_core');
12
13
 
13
14
  const reporterColorMap = {
14
15
  'test:fail': 'red',
15
16
  'test:pass': 'green',
16
- 'test:diagnostic': 'blue',
17
+ 'test:diagnostic': 'white',
17
18
  warn: 'yellow',
18
19
  error: 'red',
19
- info: 'blue',
20
+ info: 'white',
20
21
  };
21
22
 
22
23
  const reporterUnicodeSymbolMap = {
23
24
  'test:fail': '\u2716 ',
24
25
  'test:pass': '\u2714 ',
25
- 'test:diagnostic': '\u2139 ',
26
26
  'test:coverage': '\u2139 ',
27
27
  'arrow:right': '\u25B6 ',
28
28
  'hyphen:minus': '\uFE63 ',
@@ -82,6 +82,8 @@ const formatDuration = (m) => {
82
82
  .join(', ');
83
83
  };
84
84
 
85
+ const endGroup = new Command('endgroup').toString();
86
+
85
87
  class SpecReporter extends Transform {
86
88
  #isGitHubActions = Boolean(process.env.GITHUB_ACTIONS);
87
89
 
@@ -128,22 +130,19 @@ class SpecReporter extends Transform {
128
130
  symbol = reporterUnicodeSymbolMap['hyphen:minus'];
129
131
  }
130
132
 
131
- let ghGroup = '';
132
- let p = prefix;
133
+ const header = `${indentation}${styleText(color, `${symbol}${title}`, { validateStream: !this.#isGitHubActions })}`;
133
134
  if (this.#isGitHubActions) {
134
- ghGroup = '::group::';
135
- if (this.#reportedGroup) {
136
- p = `::endgroup::\n${prefix}`;
137
- }
135
+ const eg = this.#reportedGroup ? endGroup : '';
138
136
  this.#reportedGroup = true;
137
+ return `${eg}${prefix}${new Command('group', {}, header, { EOL: '' }).toString()}${err}`;
139
138
  }
140
- return `${p}${ghGroup}${indentation}${styleText(color, `${symbol}${title}`, { validateStream: !this.#isGitHubActions })}${err}`;
139
+ return `${prefix}${header}${err}`;
141
140
  }
142
141
 
143
142
  #formatFailedTestResults() {
144
143
  if (this.#failedTests.length === 0) {
145
144
  /* c8 ignore next 2 */
146
- return this.#reportedGroup ? '::endgroup::\n' : '';
145
+ return this.#reportedGroup ? endGroup : '';
147
146
  }
148
147
 
149
148
  const results = [
@@ -151,7 +150,7 @@ class SpecReporter extends Transform {
151
150
  ];
152
151
 
153
152
  if (this.#reportedGroup) {
154
- results.unshift('::endgroup::\n');
153
+ results.unshift(endGroup);
155
154
  this.#reportedGroup = false; // Reset the group state for the next run
156
155
  }
157
156
 
@@ -169,7 +168,7 @@ class SpecReporter extends Transform {
169
168
  }
170
169
 
171
170
  if (this.#reportedGroup) {
172
- results.push('::endgroup::\n');
171
+ results.push(endGroup);
173
172
  }
174
173
 
175
174
  this.#failedTests = []; // Clean up the failed tests
@@ -207,26 +206,27 @@ class SpecReporter extends Transform {
207
206
  }
208
207
 
209
208
  #handleEvent({ type, data }) {
209
+ let res = '';
210
210
  if (this.#isGitHubActions) {
211
- handleEvent({ type, data });
211
+ res = transformEvent({ type, data });
212
212
  }
213
213
  switch (type) {
214
214
  case 'test:fail':
215
215
  if (data.details?.error?.failureType !== 'subtestsFailed') {
216
216
  this.#failedTests.push(data);
217
217
  }
218
- return this.#handleTestReportEvent(type, data);
218
+ return this.#handleTestReportEvent(type, data) + res;
219
219
  case 'test:pass':
220
- return this.#handleTestReportEvent(type, data);
220
+ return this.#handleTestReportEvent(type, data) + res;
221
221
  case 'test:start':
222
222
  this.#stack.unshift({ __proto__: null, data, type });
223
- break;
223
+ return res;
224
224
  case 'test:diagnostic': {
225
225
  if (isTopLevelDiagnostic(data)) {
226
- return '';
226
+ return res;
227
227
  }
228
228
  const diagnosticColor = reporterColorMap[data.level] || reporterColorMap.info;
229
- return `${indent(data.nesting)}${styleText(diagnosticColor, `${reporterUnicodeSymbolMap[type]}${data.message}`, { validateStream: !this.#isGitHubActions })}\n`;
229
+ return `${res}${indent(data.nesting)}${styleText(diagnosticColor, `${reporterUnicodeSymbolMap[type] ?? ''}${data.message}`, { validateStream: !this.#isGitHubActions })}\n`;
230
230
  }
231
231
  case 'test:summary':
232
232
  // We report only the root test summary
@@ -250,10 +250,12 @@ class SpecReporter extends Transform {
250
250
  }
251
251
 
252
252
  _flush(callback) {
253
- callback(null, this.#formatFailedTestResults());
254
- if (this.#isGitHubActions) {
255
- emitSummary();
256
- }
253
+ Promise.resolve(this.#isGitHubActions ? getSummary() : '').then((summary) => {
254
+ callback(null, this.#formatFailedTestResults() + summary);
255
+ }).catch((err) => {
256
+ /* c8 ignore next 2 */
257
+ callback(err);
258
+ });
257
259
  }
258
260
  }
259
261
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reporters/gh",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A github actions reporter for `node:test`",
5
5
  "type": "commonjs",
6
6
  "keywords": [