@reporters/github 1.0.0 → 1.0.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.
- package/CHANGELOG.md +14 -0
- package/README.md +17 -8
- package/index.js +34 -30
- package/package.json +5 -1
- package/tests/events.js +170 -0
- package/tests/index.test.js +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.0.1](https://github.com/MoLow/reporters/compare/github-v1.0.0...github-v1.0.1) (2022-12-20)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* fix monorepos release ([8386ef0](https://github.com/MoLow/reporters/commit/8386ef0ea7bfe0c0325e171aa7122eeccb17bad3))
|
|
9
|
+
* fix monorepos release ([3c5ee61](https://github.com/MoLow/reporters/commit/3c5ee6126fe961363b3feccf1ba6594a0849855b))
|
|
10
|
+
* fix monorepos release ([7eebffb](https://github.com/MoLow/reporters/commit/7eebffb46ab627beaa2b10023a08dd3271f819e9))
|
|
11
|
+
* fix monorepos release ([9c66f37](https://github.com/MoLow/reporters/commit/9c66f37b010f782e70c3cdf2bf827d30c4aa71c2))
|
|
12
|
+
* fix monorepos release ([d844919](https://github.com/MoLow/reporters/commit/d844919c8684216155b8f1c0acc98d907b3a5cdb))
|
|
13
|
+
* fix monorepos release ([d5610e2](https://github.com/MoLow/reporters/commit/d5610e29db730dc4ffa3f9721a85d5f3c7749b2c))
|
|
14
|
+
* fix typo ([#22](https://github.com/MoLow/reporters/issues/22)) ([0308fac](https://github.com/MoLow/reporters/commit/0308fac968799a0fd877460deeaa5503bc53d09f))
|
|
15
|
+
* reset changelogs ([1e114ce](https://github.com/MoLow/reporters/commit/1e114ced7201cf9897f2cf79b5a4fb46f1b085fb))
|
|
16
|
+
|
|
3
17
|
## 1.0.0 (2022-12-19)
|
|
4
18
|
|
|
5
19
|
Initial release
|
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@reporters/github) 
|
|
2
|
+
|
|
1
3
|
# Github Actions Reporter
|
|
2
4
|
A Github actions reporter for `node:test`
|
|
3
|
-
|
|
5
|
+
|
|
4
6
|
## Installation
|
|
5
7
|
|
|
6
8
|
```bash
|
|
@@ -13,15 +15,22 @@ yarn add --dev @reporters/github
|
|
|
13
15
|
|
|
14
16
|
## Usage
|
|
15
17
|
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
--test
|
|
18
|
+
```yaml
|
|
19
|
+
# .github/workflows/test.yml
|
|
20
|
+
- name: Run tests
|
|
21
|
+
run: node --test \
|
|
22
|
+
--test-reporter=@reporters/github --test-reporter-destination=stdout \
|
|
23
|
+
--test-reporter=spec --test-reporter-destination=stdout
|
|
20
24
|
```
|
|
21
25
|
|
|
22
|
-
##
|
|
26
|
+
## Result
|
|
27
|
+
|
|
28
|
+
when test failed, you can see the result as an annotation on the failed line.
|
|
29
|
+
|
|
30
|
+
<img width="810" alt="Screen Shot 2022-12-20 at 3 40 36" src="https://user-images.githubusercontent.com/8221854/208561892-28b821b1-1771-4063-baa2-6e14186ae3bf.png">
|
|
31
|
+
|
|
32
|
+
additionally, this reporter will add a summary of the tests to the github action.
|
|
23
33
|
|
|
24
|
-
|
|
34
|
+
<img width="815" alt="Screen Shot 2022-12-20 at 3 43 47" src="https://user-images.githubusercontent.com/8221854/208561887-c3eccbd8-7506-4a8f-a18c-2892605f3243.png">
|
|
25
35
|
|
|
26
|
-
### summary
|
|
27
36
|
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const path = require('node:path');
|
|
2
2
|
const util = require('node:util');
|
|
3
3
|
const { EOL } = require('node:os');
|
|
4
|
+
const core = require('@actions/core');
|
|
4
5
|
const StackUtils = require('stack-utils');
|
|
5
6
|
|
|
6
7
|
const WORKSPACE = process.env.GITHUB_WORKSPACE ?? '';
|
|
@@ -17,29 +18,19 @@ const parseStack = (error, file) => {
|
|
|
17
18
|
return line ? stack.parseLine(line) : null;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const propsToString = (props = {}) => {
|
|
30
|
-
const entries = Object.entries(props);
|
|
31
|
-
if (entries.length === 0) {
|
|
32
|
-
return '';
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const result = entries
|
|
36
|
-
.filter(([, value]) => Boolean(value))
|
|
37
|
-
.map(([key, value]) => `${key}=${escapeProperty(String(value))}`).join(',');
|
|
38
|
-
|
|
39
|
-
return ` ${result}`;
|
|
21
|
+
const DIAGNOSTIC_KEYS = {
|
|
22
|
+
tests: 'Total Tests',
|
|
23
|
+
pass: 'Passed ✅',
|
|
24
|
+
fail: 'Failed ❌',
|
|
25
|
+
cancelled: 'Canceled 🚫',
|
|
26
|
+
skipped: 'Skipped ⏭️',
|
|
27
|
+
todo: 'Todo 📝',
|
|
28
|
+
duration_ms: 'Duration',
|
|
40
29
|
};
|
|
41
30
|
|
|
42
|
-
const
|
|
31
|
+
const DIAGNOSTIC_VALUES = {
|
|
32
|
+
duration_ms: (value) => `${Number(value).toFixed(3)}ms`,
|
|
33
|
+
};
|
|
43
34
|
|
|
44
35
|
module.exports = async function githubReporter(source) {
|
|
45
36
|
const counter = { pass: 0, fail: 0 };
|
|
@@ -49,11 +40,11 @@ module.exports = async function githubReporter(source) {
|
|
|
49
40
|
switch (event.type) {
|
|
50
41
|
case 'test:start':
|
|
51
42
|
currentFile = getCurrentFile(event.data.name) || currentFile;
|
|
52
|
-
|
|
43
|
+
core.debug(`starting to run ${event.data.name}`);
|
|
53
44
|
break;
|
|
54
45
|
case 'test:pass':
|
|
55
46
|
counter.pass += 1;
|
|
56
|
-
|
|
47
|
+
core.debug(`completed running ${event.data.name}`);
|
|
57
48
|
currentFile = isFile(event.data.name) ? null : currentFile;
|
|
58
49
|
break;
|
|
59
50
|
case 'test:fail': {
|
|
@@ -62,10 +53,10 @@ module.exports = async function githubReporter(source) {
|
|
|
62
53
|
{ colors: false, breakLength: Infinity },
|
|
63
54
|
);
|
|
64
55
|
const location = parseStack(event.data.details?.error, currentFile);
|
|
65
|
-
|
|
56
|
+
core.error(error, {
|
|
66
57
|
file: location?.file ?? currentFile,
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
startLine: location?.line,
|
|
59
|
+
startColumn: location?.column,
|
|
69
60
|
title: event.data.name,
|
|
70
61
|
});
|
|
71
62
|
counter.fail += 1;
|
|
@@ -73,7 +64,7 @@ module.exports = async function githubReporter(source) {
|
|
|
73
64
|
break;
|
|
74
65
|
} case 'test:diagnostic':
|
|
75
66
|
if (currentFile) {
|
|
76
|
-
|
|
67
|
+
core.notice(event.data.message, { file: currentFile });
|
|
77
68
|
} else {
|
|
78
69
|
diagnostics.push(event.data.message);
|
|
79
70
|
}
|
|
@@ -82,7 +73,20 @@ module.exports = async function githubReporter(source) {
|
|
|
82
73
|
break;
|
|
83
74
|
}
|
|
84
75
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
76
|
+
core.startGroup(`Test results (${counter.pass} passed, ${counter.fail} failed)`);
|
|
77
|
+
const formatedDiagnostics = diagnostics.map((d) => {
|
|
78
|
+
const [key, ...rest] = d.split(' ');
|
|
79
|
+
const value = rest.join(' ');
|
|
80
|
+
return [
|
|
81
|
+
DIAGNOSTIC_KEYS[key] ?? key,
|
|
82
|
+
DIAGNOSTIC_VALUES[key] ? DIAGNOSTIC_VALUES[key](value) : value,
|
|
83
|
+
];
|
|
84
|
+
});
|
|
85
|
+
core.notice(formatedDiagnostics.map((d) => d.join(': ')).join(EOL));
|
|
86
|
+
core.endGroup();
|
|
87
|
+
|
|
88
|
+
await core.summary
|
|
89
|
+
.addHeading('Test Results')
|
|
90
|
+
.addTable(formatedDiagnostics)
|
|
91
|
+
.write();
|
|
88
92
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reporters/github",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A junit reporter for `node:test`",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github actions",
|
|
@@ -10,8 +10,12 @@
|
|
|
10
10
|
"reporters"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
+
"@actions/core": "^1.10.0",
|
|
13
14
|
"stack-utils": "^2.0.6"
|
|
14
15
|
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "node tests/index.test.js"
|
|
18
|
+
},
|
|
15
19
|
"main": "index.js",
|
|
16
20
|
"repository": "https://github.com/MoLow/reporters.git",
|
|
17
21
|
"author": "Moshe Atlow",
|
package/tests/events.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
const WORKSPACE = process.env.GITHUB_WORKSPACE ?? '';
|
|
2
|
+
|
|
3
|
+
module.exports = [
|
|
4
|
+
{
|
|
5
|
+
type: 'test:start',
|
|
6
|
+
data: {
|
|
7
|
+
nesting: 0,
|
|
8
|
+
name: `${WORKSPACE}/tests/fixtures/example.js`,
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
type: 'test:start',
|
|
13
|
+
data: {
|
|
14
|
+
nesting: 1,
|
|
15
|
+
name: 'tests',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
type: 'test:start',
|
|
20
|
+
data: {
|
|
21
|
+
nesting: 2,
|
|
22
|
+
name: 'is ok',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
type: 'test:pass',
|
|
27
|
+
data: {
|
|
28
|
+
name: 'is ok',
|
|
29
|
+
nesting: 2,
|
|
30
|
+
testNumber: '1',
|
|
31
|
+
details: {
|
|
32
|
+
duration_ms: 0.139292,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'test:start',
|
|
38
|
+
data: {
|
|
39
|
+
nesting: 2,
|
|
40
|
+
name: 'fails',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: 'test:fail',
|
|
45
|
+
data: {
|
|
46
|
+
name: 'fails',
|
|
47
|
+
nesting: 2,
|
|
48
|
+
testNumber: '2',
|
|
49
|
+
details: {
|
|
50
|
+
duration_ms: 0.275709,
|
|
51
|
+
error: Object.assign(new Error(''), {
|
|
52
|
+
failureType: 'testCodeFailure',
|
|
53
|
+
cause: {
|
|
54
|
+
code: 'ERR_TEST_FAILURE',
|
|
55
|
+
},
|
|
56
|
+
code: 'ERR_TEST_FAILURE',
|
|
57
|
+
stack: ` at Object.<anonymous> (${WORKSPACE}/tests/fixtures/example.js:6:11)\n at ItTest.runInAsyncScope (node:async_hooks:204:9)\n ... 5 lines matching cause stack trace ...\n at async Suite.run (node:internal/test_runner/test:798:7) {\n failureType: 'testCodeFailure',\n cause: at Object.<anonymous> (${WORKSPACE}/tests/fixtures/example.js:6:11)\n at ItTest.runInAsyncScope (node:async_hooks:204:9)\n at ItTest.run (node:internal/test_runner/test:547:25)\n at Suite.processPendingSubtests (node:internal/test_runner/test:302:27)\n at ItTest.postRun (node:internal/test_runner/test:632:19)\n at ItTest.run (node:internal/test_runner/test:575:10)\n at async Promise.all (index 0)\n at async Suite.run (node:internal/test_runner/test:798:7)`,
|
|
58
|
+
}),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: 'test:plan',
|
|
64
|
+
data: {
|
|
65
|
+
nesting: 2,
|
|
66
|
+
count: 2,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: 'test:fail',
|
|
71
|
+
data: {
|
|
72
|
+
name: 'tests',
|
|
73
|
+
nesting: 1,
|
|
74
|
+
testNumber: '1',
|
|
75
|
+
details: {
|
|
76
|
+
duration_ms: 2.925542,
|
|
77
|
+
error: Object.assign(new Error('1 subtest failed'), {
|
|
78
|
+
failureType: 'subtestsFailed',
|
|
79
|
+
cause: {
|
|
80
|
+
code: 'ERR_TEST_FAILURE',
|
|
81
|
+
},
|
|
82
|
+
code: 'ERR_TEST_FAILURE',
|
|
83
|
+
stack: '',
|
|
84
|
+
}),
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
type: 'test:plan',
|
|
90
|
+
data: {
|
|
91
|
+
nesting: 1,
|
|
92
|
+
count: 1,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
type: 'test:fail',
|
|
97
|
+
data: {
|
|
98
|
+
name: `${WORKSPACE}/tests/fixtures/example.js`,
|
|
99
|
+
nesting: 0,
|
|
100
|
+
testNumber: 1,
|
|
101
|
+
details: {
|
|
102
|
+
duration_ms: 86.369584,
|
|
103
|
+
error: Object.assign(new Error('test failed'), {
|
|
104
|
+
failureType: 'subtestsFailed',
|
|
105
|
+
cause: 'test failed',
|
|
106
|
+
code: 'ERR_TEST_FAILURE',
|
|
107
|
+
exitCode: 1,
|
|
108
|
+
signal: null,
|
|
109
|
+
stack: '',
|
|
110
|
+
}),
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
type: 'test:plan',
|
|
116
|
+
data: {
|
|
117
|
+
nesting: 0,
|
|
118
|
+
count: 1,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
type: 'test:diagnostic',
|
|
123
|
+
data: {
|
|
124
|
+
nesting: 0,
|
|
125
|
+
message: 'tests 1',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
type: 'test:diagnostic',
|
|
130
|
+
data: {
|
|
131
|
+
nesting: 0,
|
|
132
|
+
message: 'pass 0',
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
type: 'test:diagnostic',
|
|
137
|
+
data: {
|
|
138
|
+
nesting: 0,
|
|
139
|
+
message: 'fail 1',
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
type: 'test:diagnostic',
|
|
144
|
+
data: {
|
|
145
|
+
nesting: 0,
|
|
146
|
+
message: 'cancelled 0',
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
type: 'test:diagnostic',
|
|
151
|
+
data: {
|
|
152
|
+
nesting: 0,
|
|
153
|
+
message: 'skipped 0',
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
type: 'test:diagnostic',
|
|
158
|
+
data: {
|
|
159
|
+
nesting: 0,
|
|
160
|
+
message: 'todo 0',
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
type: 'test:diagnostic',
|
|
165
|
+
data: {
|
|
166
|
+
nesting: 0,
|
|
167
|
+
message: 'duration_ms 87.068833',
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
];
|