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