@reporters/github 1.8.0 → 1.9.1

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 +59 -42
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -62,50 +62,51 @@ function extractLocation(data) {
62
62
  return { file, startLine: line, startColumn: column };
63
63
  }
64
64
 
65
- module.exports = async function githubReporter(source) {
66
- if (!process.env.GITHUB_ACTIONS) {
67
- // eslint-disable-next-line no-unused-vars
68
- for await (const _ of source);
69
- return;
70
- }
71
- const counter = { pass: 0, fail: 0 };
72
- const diagnostics = [];
73
- for await (const event of source) {
74
- switch (event.type) {
75
- case 'test:start':
76
- core.debug(`starting to run ${event.data.name}`);
77
- break;
78
- case 'test:pass':
79
- counter.pass += 1;
80
- core.debug(`completed running ${event.data.name}`);
81
- break;
82
- case 'test:fail': {
83
- const error = event.data.details?.error;
84
- if (error?.code === 'ERR_TEST_FAILURE' && error?.failureType === 'subtestsFailed') {
85
- // This means the failed subtests are already reported
86
- // no need to re-annotate the file itself
87
- break;
88
- }
89
- core.error(util.inspect(error, { colors: false, breakLength: Infinity }), {
90
- ...extractLocation(event.data),
91
- title: event.data.name,
92
- });
93
- counter.fail += 1;
94
- break;
95
- } case 'test:diagnostic':
96
- if (event.data.file === undefined
97
- || event.data.line === undefined
98
- || event.data.column === undefined
99
- || (event.data.line === 1 && event.data.column === 1)) {
100
- diagnostics.push(event.data.message);
101
- } else if (process.env.GITHUB_ACTIONS_REPORTER_VERBOSE) {
102
- core.notice(event.data.message, extractLocation(event.data));
103
- }
104
- break;
105
- default:
65
+ const counter = { pass: 0, fail: 0 };
66
+ const diagnostics = [];
67
+
68
+ function isTopLevelDiagnostic(data) {
69
+ return (data.file === undefined
70
+ || data.line === undefined
71
+ || data.column === undefined
72
+ || (data.line === 1 && data.column === 1));
73
+ }
74
+
75
+ function handleEvent(event) {
76
+ switch (event.type) {
77
+ case 'test:start':
78
+ core.debug(`starting to run ${event.data.name}`);
79
+ break;
80
+ case 'test:pass':
81
+ counter.pass += 1;
82
+ core.debug(`completed running ${event.data.name}`);
83
+ break;
84
+ case 'test:fail': {
85
+ const error = event.data.details?.error;
86
+ if (error?.code === 'ERR_TEST_FAILURE' && error?.failureType === 'subtestsFailed') {
87
+ // This means the failed subtests are already reported
88
+ // no need to re-annotate the file itself
106
89
  break;
107
- }
90
+ }
91
+ core.error(util.inspect(error, { colors: false, breakLength: Infinity }), {
92
+ ...extractLocation(event.data),
93
+ title: event.data.name,
94
+ });
95
+ counter.fail += 1;
96
+ break;
97
+ } case 'test:diagnostic':
98
+ if (isTopLevelDiagnostic(event.data)) {
99
+ diagnostics.push(event.data.message);
100
+ } else if (process.env.GITHUB_ACTIONS_REPORTER_VERBOSE) {
101
+ core.notice(event.data.message, extractLocation(event.data));
102
+ }
103
+ break;
104
+ default:
105
+ break;
108
106
  }
107
+ }
108
+
109
+ async function emitSummary() {
109
110
  const formattedDiagnostics = diagnostics.map((d) => {
110
111
  const [key, ...rest] = d.split(' ');
111
112
  const value = rest.join(' ');
@@ -124,4 +125,20 @@ module.exports = async function githubReporter(source) {
124
125
  .addTable(formattedDiagnostics)
125
126
  .write();
126
127
  }
128
+ }
129
+
130
+ module.exports = async function githubReporter(source) {
131
+ if (!process.env.GITHUB_ACTIONS) {
132
+ // eslint-disable-next-line no-unused-vars
133
+ for await (const _ of source);
134
+ return;
135
+ }
136
+ for await (const event of source) {
137
+ handleEvent(event);
138
+ }
139
+ await emitSummary();
127
140
  };
141
+
142
+ module.exports.handleEvent = handleEvent;
143
+ module.exports.emitSummary = emitSummary;
144
+ module.exports.isTopLevelDiagnostic = isTopLevelDiagnostic;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reporters/github",
3
- "version": "1.8.0",
3
+ "version": "1.9.1",
4
4
  "description": "A github actions reporter for `node:test`",
5
5
  "type": "commonjs",
6
6
  "keywords": [
@@ -18,7 +18,7 @@
18
18
  "./index.js"
19
19
  ],
20
20
  "scripts": {
21
- "test": "node --test-reporter=spec --test-reporter-destination=stdout --test-reporter=./index.js --test-reporter-destination=stdout --test"
21
+ "test": "node --test-reporter=../gh/index.js --test"
22
22
  },
23
23
  "bugs": {
24
24
  "url": "https://github.com/MoLow/reporters/issues"