@reporters/github 1.9.1 → 1.9.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.
- package/gh_core.js +61 -0
- package/index.js +20 -19
- package/package.json +3 -2
package/gh_core.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// From Github Core SDK code
|
|
4
|
+
// eslint-disable-next-line import/no-unresolved
|
|
5
|
+
const coreUtils = require('@actions/core/lib/utils');
|
|
6
|
+
const { EOL } = require('node:os');
|
|
7
|
+
|
|
8
|
+
function escapeData(s) {
|
|
9
|
+
return coreUtils.toCommandValue(s)
|
|
10
|
+
.replace(/%/g, '%25')
|
|
11
|
+
.replace(/\r/g, '%0D')
|
|
12
|
+
.replace(/\n/g, '%0A');
|
|
13
|
+
}
|
|
14
|
+
function escapeProperty(s) {
|
|
15
|
+
return coreUtils.toCommandValue(s)
|
|
16
|
+
.replace(/%/g, '%25')
|
|
17
|
+
.replace(/\r/g, '%0D')
|
|
18
|
+
.replace(/\n/g, '%0A')
|
|
19
|
+
.replace(/:/g, '%3A')
|
|
20
|
+
.replace(/,/g, '%2C');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const CMD_STRING = '::';
|
|
24
|
+
class Command {
|
|
25
|
+
constructor(command, properties, message, options = { EOL }) {
|
|
26
|
+
this.command = command ?? 'missing.command';
|
|
27
|
+
this.properties = properties;
|
|
28
|
+
this.message = message;
|
|
29
|
+
this.options = options;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
toString() {
|
|
33
|
+
let cmdStr = CMD_STRING + this.command;
|
|
34
|
+
if (this.properties && Object.keys(this.properties).length > 0) {
|
|
35
|
+
cmdStr += ' ';
|
|
36
|
+
let first = true;
|
|
37
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
38
|
+
for (const key in this.properties) {
|
|
39
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
40
|
+
if (this.properties.hasOwnProperty(key)) {
|
|
41
|
+
const val = this.properties[key];
|
|
42
|
+
if (val) {
|
|
43
|
+
if (first) {
|
|
44
|
+
first = false;
|
|
45
|
+
} else {
|
|
46
|
+
cmdStr += ',';
|
|
47
|
+
}
|
|
48
|
+
cmdStr += `${key}=${escapeProperty(val)}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
cmdStr += `${CMD_STRING}${escapeData(this.message)}${this.options.EOL}`;
|
|
54
|
+
return cmdStr;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = {
|
|
59
|
+
toCommandProperties: coreUtils.toCommandProperties,
|
|
60
|
+
Command,
|
|
61
|
+
};
|
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
|
|
76
|
+
function transformEvent(event) {
|
|
76
77
|
switch (event.type) {
|
|
77
78
|
case 'test:start':
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
138
|
+
yield transformEvent(event);
|
|
138
139
|
}
|
|
139
|
-
await
|
|
140
|
+
yield await getSummary();
|
|
140
141
|
};
|
|
141
142
|
|
|
142
|
-
module.exports.
|
|
143
|
-
module.exports.
|
|
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.
|
|
3
|
+
"version": "1.9.3",
|
|
4
4
|
"description": "A github actions reporter for `node:test`",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"keywords": [
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"stack-utils": "^2.0.6"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
|
-
"./index.js"
|
|
18
|
+
"./index.js",
|
|
19
|
+
"./gh_core.js"
|
|
19
20
|
],
|
|
20
21
|
"scripts": {
|
|
21
22
|
"test": "node --test-reporter=../gh/index.js --test"
|