@reporters/github 1.9.1 → 1.9.2

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 +20 -19
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -6,6 +6,7 @@ const util = require('node:util');
6
6
  const { EOL } = require('node:os');
7
7
  const core = require('@actions/core');
8
8
  const StackUtils = require('stack-utils');
9
+ const { Command, toCommandProperties } = require('./gh_core');
9
10
 
10
11
  const WORKSPACE = process.env.GITHUB_WORKSPACE ?? '';
11
12
 
@@ -72,15 +73,13 @@ function isTopLevelDiagnostic(data) {
72
73
  || (data.line === 1 && data.column === 1));
73
74
  }
74
75
 
75
- function handleEvent(event) {
76
+ function transformEvent(event) {
76
77
  switch (event.type) {
77
78
  case 'test:start':
78
- core.debug(`starting to run ${event.data.name}`);
79
- break;
79
+ return new Command('debug', {}, `starting to run ${event.data.name}`).toString();
80
80
  case 'test:pass':
81
81
  counter.pass += 1;
82
- core.debug(`completed running ${event.data.name}`);
83
- break;
82
+ return new Command('debug', {}, `completed running ${event.data.name}`).toString();
84
83
  case 'test:fail': {
85
84
  const error = event.data.details?.error;
86
85
  if (error?.code === 'ERR_TEST_FAILURE' && error?.failureType === 'subtestsFailed') {
@@ -88,25 +87,25 @@ function handleEvent(event) {
88
87
  // no need to re-annotate the file itself
89
88
  break;
90
89
  }
91
- core.error(util.inspect(error, { colors: false, breakLength: Infinity }), {
90
+ counter.fail += 1;
91
+ return new Command('error', toCommandProperties({
92
92
  ...extractLocation(event.data),
93
93
  title: event.data.name,
94
- });
95
- counter.fail += 1;
96
- break;
94
+ }), util.inspect(error, { colors: false, breakLength: Infinity })).toString();
97
95
  } case 'test:diagnostic':
98
96
  if (isTopLevelDiagnostic(event.data)) {
99
97
  diagnostics.push(event.data.message);
100
98
  } else if (process.env.GITHUB_ACTIONS_REPORTER_VERBOSE) {
101
- core.notice(event.data.message, extractLocation(event.data));
99
+ return new Command('notice', toCommandProperties(extractLocation(event.data)), `${event.data.message}`).toString();
102
100
  }
103
101
  break;
104
102
  default:
105
103
  break;
106
104
  }
105
+ return '';
107
106
  }
108
107
 
109
- async function emitSummary() {
108
+ async function getSummary() {
110
109
  const formattedDiagnostics = diagnostics.map((d) => {
111
110
  const [key, ...rest] = d.split(' ');
112
111
  const value = rest.join(' ');
@@ -115,9 +114,10 @@ async function emitSummary() {
115
114
  DIAGNOSTIC_VALUES[key] ? DIAGNOSTIC_VALUES[key](value) : value,
116
115
  ];
117
116
  });
118
- core.startGroup(`Test results (${formattedDiagnostics.find(([key]) => key === DIAGNOSTIC_KEYS.pass)?.[1] ?? counter.pass} passed, ${formattedDiagnostics.find(([key]) => key === DIAGNOSTIC_KEYS.fail)?.[1] ?? counter.fail} failed)`);
119
- core.notice(formattedDiagnostics.map((d) => d.join(': ')).join(EOL));
120
- core.endGroup();
117
+ let res = '';
118
+ res += new Command('group', {}, `Test results (${formattedDiagnostics.find(([key]) => key === DIAGNOSTIC_KEYS.pass)?.[1] ?? counter.pass} passed, ${formattedDiagnostics.find(([key]) => key === DIAGNOSTIC_KEYS.fail)?.[1] ?? counter.fail} failed)`).toString();
119
+ res += new Command('notice', {}, formattedDiagnostics.map((d) => d.join(': ')).join(EOL)).toString();
120
+ res += new Command('endgroup').toString();
121
121
 
122
122
  if (process.env.GITHUB_STEP_SUMMARY) {
123
123
  await core.summary
@@ -125,20 +125,21 @@ async function emitSummary() {
125
125
  .addTable(formattedDiagnostics)
126
126
  .write();
127
127
  }
128
+ return res;
128
129
  }
129
130
 
130
- module.exports = async function githubReporter(source) {
131
+ module.exports = async function* githubReporter(source) {
131
132
  if (!process.env.GITHUB_ACTIONS) {
132
133
  // eslint-disable-next-line no-unused-vars
133
134
  for await (const _ of source);
134
135
  return;
135
136
  }
136
137
  for await (const event of source) {
137
- handleEvent(event);
138
+ yield transformEvent(event);
138
139
  }
139
- await emitSummary();
140
+ yield await getSummary();
140
141
  };
141
142
 
142
- module.exports.handleEvent = handleEvent;
143
- module.exports.emitSummary = emitSummary;
143
+ module.exports.transformEvent = transformEvent;
144
+ module.exports.getSummary = getSummary;
144
145
  module.exports.isTopLevelDiagnostic = isTopLevelDiagnostic;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reporters/github",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
4
4
  "description": "A github actions reporter for `node:test`",
5
5
  "type": "commonjs",
6
6
  "keywords": [