@reporters/github 1.0.0 → 1.0.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.
- package/CHANGELOG.md +22 -0
- package/README.md +17 -8
- package/index.js +34 -30
- package/package.json +10 -2
- package/tests/index.test.js +18 -0
- package/tests/output.js +15 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.0.2](https://github.com/MoLow/reporters/compare/github-v1.0.1...github-v1.0.2) (2022-12-25)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* fix package description ([cec07c7](https://github.com/MoLow/reporters/commit/cec07c70d37b3ed43947b17312a6bd58f095510f))
|
|
9
|
+
* some package.json links ([c51a616](https://github.com/MoLow/reporters/commit/c51a61648e29f5baca539ded1b09c2af3f5e0a4a))
|
|
10
|
+
|
|
11
|
+
## [1.0.1](https://github.com/MoLow/reporters/compare/github-v1.0.0...github-v1.0.1) (2022-12-20)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* fix monorepos release ([8386ef0](https://github.com/MoLow/reporters/commit/8386ef0ea7bfe0c0325e171aa7122eeccb17bad3))
|
|
17
|
+
* fix monorepos release ([3c5ee61](https://github.com/MoLow/reporters/commit/3c5ee6126fe961363b3feccf1ba6594a0849855b))
|
|
18
|
+
* fix monorepos release ([7eebffb](https://github.com/MoLow/reporters/commit/7eebffb46ab627beaa2b10023a08dd3271f819e9))
|
|
19
|
+
* fix monorepos release ([9c66f37](https://github.com/MoLow/reporters/commit/9c66f37b010f782e70c3cdf2bf827d30c4aa71c2))
|
|
20
|
+
* fix monorepos release ([d844919](https://github.com/MoLow/reporters/commit/d844919c8684216155b8f1c0acc98d907b3a5cdb))
|
|
21
|
+
* fix monorepos release ([d5610e2](https://github.com/MoLow/reporters/commit/d5610e29db730dc4ffa3f9721a85d5f3c7749b2c))
|
|
22
|
+
* fix typo ([#22](https://github.com/MoLow/reporters/issues/22)) ([0308fac](https://github.com/MoLow/reporters/commit/0308fac968799a0fd877460deeaa5503bc53d09f))
|
|
23
|
+
* reset changelogs ([1e114ce](https://github.com/MoLow/reporters/commit/1e114ced7201cf9897f2cf79b5a4fb46f1b085fb))
|
|
24
|
+
|
|
3
25
|
## 1.0.0 (2022-12-19)
|
|
4
26
|
|
|
5
27
|
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reporters/github",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "A github actions reporter for `node:test`",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github actions",
|
|
7
7
|
"node:test",
|
|
@@ -10,9 +10,17 @@
|
|
|
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": "../../prebuilt --test"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/MoLow/reporters/issues"
|
|
21
|
+
},
|
|
15
22
|
"main": "index.js",
|
|
23
|
+
"homepage": "https://github.com/MoLow/reporters/tree/main/packages/github",
|
|
16
24
|
"repository": "https://github.com/MoLow/reporters.git",
|
|
17
25
|
"author": "Moshe Atlow",
|
|
18
26
|
"license": "MIT"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const { spawnSync } = require('child_process');
|
|
2
|
+
const { tmpdir } = require('os');
|
|
3
|
+
const { join } = require('path');
|
|
4
|
+
const assert = require('assert');
|
|
5
|
+
const { readFileSync, writeFileSync } = require('fs');
|
|
6
|
+
const { compareLines } = require('../../../tests/utils');
|
|
7
|
+
const output = require('./output');
|
|
8
|
+
|
|
9
|
+
const GITHUB_STEP_SUMMARY = join(tmpdir(), 'github-actions-test-reporter');
|
|
10
|
+
writeFileSync(GITHUB_STEP_SUMMARY, '');
|
|
11
|
+
|
|
12
|
+
const child = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example'], {
|
|
13
|
+
env: { GITHUB_STEP_SUMMARY },
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
assert.strictEqual(child.stderr?.toString(), '');
|
|
17
|
+
compareLines(child.stdout?.toString(), output.stdout);
|
|
18
|
+
compareLines(readFileSync(GITHUB_STEP_SUMMARY).toString(), output.summary);
|
package/tests/output.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
stdout: `::debug::starting to run tests
|
|
3
|
+
::debug::starting to run is ok
|
|
4
|
+
::debug::completed running is ok
|
|
5
|
+
::debug::starting to run fails
|
|
6
|
+
::error title=fails,file=fails::\\[Error \\[ERR_TEST_FAILURE\\]: this is an error\\] {%0A failureType: 'testCodeFailure',%0A cause: Error: this is an error%0A at Object.<anonymous> (.*/example.js:6:11).*
|
|
7
|
+
::error title=tests::\\[Error \\[ERR_TEST_FAILURE\\]: 1 subtest failed\\] { failureType: 'subtestsFailed', cause: '1 subtest failed', code: 'ERR_TEST_FAILURE' }
|
|
8
|
+
::group::Test results \\(1 passed, 2 failed\\)
|
|
9
|
+
::notice::Total Tests: 1%0APassed ✅: 0%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration: .*ms
|
|
10
|
+
::endgroup::
|
|
11
|
+
`,
|
|
12
|
+
summary: `<h1>Test Results</h1>
|
|
13
|
+
<table><tr><td>Total Tests</td><td>1</td></tr><tr><td>Passed ✅</td><td>0</td></tr><tr><td>Failed ❌</td><td>1</td></tr><tr><td>Canceled 🚫</td><td>0</td></tr><tr><td>Skipped ⏭️</td><td>0</td></tr><tr><td>Todo 📝</td><td>0</td></tr><tr><td>Duration</td><td>.*ms</td></tr></table>
|
|
14
|
+
`,
|
|
15
|
+
};
|