@reporters/github 1.4.1 → 1.5.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/README.md +12 -4
- package/index.js +21 -9
- package/package.json +4 -1
- package/CHANGELOG.md +0 -83
- package/tests/index.test.js +0 -30
- package/tests/output.js +0 -26
package/README.md
CHANGED
|
@@ -25,11 +25,19 @@ yarn add --dev @reporters/github
|
|
|
25
25
|
|
|
26
26
|
## Result
|
|
27
27
|
|
|
28
|
-
when test failed,
|
|
28
|
+
when test failed, annotations will be added inside the github UI, with corresponding errors and diagnostics.
|
|
29
|
+
see [example run](https://github.com/MoLow/reporters/actions/runs/5607828636):
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
#### Inline annotations
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
<img width="810" alt="Inline Annotation" src="https://user-images.githubusercontent.com/8221854/254798653-0c06278e-696b-42eb-8275-364b7eb3133b.png">
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
additionally, Annotations and summary will be added to the summary of the test run.
|
|
36
|
+
|
|
37
|
+
#### Annotations
|
|
38
|
+
|
|
39
|
+
<img width="810" alt="Annotation" src="https://user-images.githubusercontent.com/8221854/254798495-38c2a8ea-c9e0-4e87-a13e-677826b72192.png">
|
|
40
|
+
|
|
41
|
+
#### Summary
|
|
42
|
+
<img width="815" alt="Summary" src="https://github.com/MoLow/reporters/assets/8221854/8934f5bb-3342-430c-9ae0-3c608a40c9f0">
|
|
35
43
|
|
package/index.js
CHANGED
|
@@ -10,10 +10,18 @@ const stack = new StackUtils({ cwd: WORKSPACE, internals: StackUtils.nodeInterna
|
|
|
10
10
|
|
|
11
11
|
const isFile = (name) => name?.startsWith(WORKSPACE);
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const getRelativeFilePath = (name) => (isFile(name) ? path.relative(WORKSPACE, require.resolve(name) ?? '') : null);
|
|
14
|
+
|
|
15
|
+
function getFilePath(fileName) {
|
|
16
|
+
if (fileName.startsWith('file://')) {
|
|
17
|
+
return getRelativeFilePath(new URL(fileName).pathname);
|
|
18
|
+
}
|
|
19
|
+
return getRelativeFilePath(fileName);
|
|
20
|
+
}
|
|
14
21
|
|
|
15
22
|
const parseStack = (error, file) => {
|
|
16
|
-
const
|
|
23
|
+
const err = error?.code === 'ERR_TEST_FAILURE' ? error?.cause : error;
|
|
24
|
+
const stackLines = (err?.stack ?? '').split(/\r?\n/);
|
|
17
25
|
const line = stackLines.find((l) => l.includes(file)) ?? stackLines[0];
|
|
18
26
|
return line ? stack.parseLine(line) : null;
|
|
19
27
|
};
|
|
@@ -51,13 +59,17 @@ module.exports = async function githubReporter(source) {
|
|
|
51
59
|
core.debug(`completed running ${event.data.name}`);
|
|
52
60
|
break;
|
|
53
61
|
case 'test:fail': {
|
|
54
|
-
const error =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
const error = event.data.details?.error;
|
|
63
|
+
if (error?.code === 'ERR_TEST_FAILURE' && error?.failureType === 'subtestsFailed') {
|
|
64
|
+
// this means the failed subtests are already reported
|
|
65
|
+
// no need to re-annotate the file itself
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
let filePath = getFilePath(event.data.file);
|
|
69
|
+
const location = parseStack(error, filePath);
|
|
70
|
+
filePath = getFilePath(location?.file ?? filePath) ?? filePath;
|
|
71
|
+
core.error(util.inspect(error, { colors: false, breakLength: Infinity }), {
|
|
72
|
+
file: filePath,
|
|
61
73
|
startLine: location?.line,
|
|
62
74
|
startColumn: location?.column,
|
|
63
75
|
title: event.data.name,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reporters/github",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "A github actions reporter for `node:test`",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github actions",
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"@actions/core": "^1.10.0",
|
|
14
14
|
"stack-utils": "^2.0.6"
|
|
15
15
|
},
|
|
16
|
+
"files": [
|
|
17
|
+
"./index.js"
|
|
18
|
+
],
|
|
16
19
|
"scripts": {
|
|
17
20
|
"test": "node --test-reporter=spec --test-reporter-destination=stdout --test-reporter=./index.js --test-reporter-destination=stdout --test"
|
|
18
21
|
},
|
package/CHANGELOG.md
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## [1.4.1](https://github.com/MoLow/reporters/compare/github-v1.4.0...github-v1.4.1) (2023-07-19)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
### Bug Fixes
|
|
7
|
-
|
|
8
|
-
* more accurate counting ([1949140](https://github.com/MoLow/reporters/commit/19491406b769f03555b3ae352ed9838e2154c855))
|
|
9
|
-
|
|
10
|
-
## [1.4.0](https://github.com/MoLow/reporters/compare/github-v1.3.0...github-v1.4.0) (2023-07-18)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
### Features
|
|
14
|
-
|
|
15
|
-
* support node 18 ([02c8957](https://github.com/MoLow/reporters/commit/02c8957ffca3cb8376f7ad5a94f4627c70b7f8e5))
|
|
16
|
-
|
|
17
|
-
## [1.3.0](https://github.com/MoLow/reporters/compare/github-v1.2.0...github-v1.3.0) (2023-07-05)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
### Features
|
|
21
|
-
|
|
22
|
-
* publish with provenance ([6ee1e46](https://github.com/MoLow/reporters/commit/6ee1e46040329edeb0f40f753093b6952984f001))
|
|
23
|
-
|
|
24
|
-
## [1.2.0](https://github.com/MoLow/reporters/compare/github-v1.1.3...github-v1.2.0) (2023-05-30)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
### Features
|
|
28
|
-
|
|
29
|
-
* report node 20 features ([c99a76c](https://github.com/MoLow/reporters/commit/c99a76c0f6bef75abb2c053c82c88448b0c82690))
|
|
30
|
-
|
|
31
|
-
## [1.1.3](https://github.com/MoLow/reporters/compare/github-v1.1.2...github-v1.1.3) (2023-04-03)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
### Bug Fixes
|
|
35
|
-
|
|
36
|
-
* allow multiple roots ([590df94](https://github.com/MoLow/reporters/commit/590df948f8a4626fc29e8ce185e08d2226a307ba))
|
|
37
|
-
|
|
38
|
-
## [1.1.2](https://github.com/MoLow/reporters/compare/github-v1.1.1...github-v1.1.2) (2023-02-28)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
### Bug Fixes
|
|
42
|
-
|
|
43
|
-
* **github:** remove redundant diagnostics ([b62df32](https://github.com/MoLow/reporters/commit/b62df3280b141af763386a68b0b4e386bef907e7))
|
|
44
|
-
|
|
45
|
-
## [1.1.1](https://github.com/MoLow/reporters/compare/github-v1.1.0...github-v1.1.1) (2023-02-28)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
### Bug Fixes
|
|
49
|
-
|
|
50
|
-
* **github:** silent if not running on github actions ([#33](https://github.com/MoLow/reporters/issues/33)) ([a480454](https://github.com/MoLow/reporters/commit/a480454ac7ca0471744ec00b69a6c67a1d3c8ada))
|
|
51
|
-
|
|
52
|
-
## [1.1.0](https://github.com/MoLow/reporters/compare/github-v1.0.2...github-v1.1.0) (2023-02-02)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
### Features
|
|
56
|
-
|
|
57
|
-
* use reported file ([#30](https://github.com/MoLow/reporters/issues/30)) ([4c70922](https://github.com/MoLow/reporters/commit/4c709222734de88af71c5a086622c3b022d51fd5))
|
|
58
|
-
|
|
59
|
-
## [1.0.2](https://github.com/MoLow/reporters/compare/github-v1.0.1...github-v1.0.2) (2022-12-25)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
### Bug Fixes
|
|
63
|
-
|
|
64
|
-
* fix package description ([cec07c7](https://github.com/MoLow/reporters/commit/cec07c70d37b3ed43947b17312a6bd58f095510f))
|
|
65
|
-
* some package.json links ([c51a616](https://github.com/MoLow/reporters/commit/c51a61648e29f5baca539ded1b09c2af3f5e0a4a))
|
|
66
|
-
|
|
67
|
-
## [1.0.1](https://github.com/MoLow/reporters/compare/github-v1.0.0...github-v1.0.1) (2022-12-20)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
### Bug Fixes
|
|
71
|
-
|
|
72
|
-
* fix monorepos release ([8386ef0](https://github.com/MoLow/reporters/commit/8386ef0ea7bfe0c0325e171aa7122eeccb17bad3))
|
|
73
|
-
* fix monorepos release ([3c5ee61](https://github.com/MoLow/reporters/commit/3c5ee6126fe961363b3feccf1ba6594a0849855b))
|
|
74
|
-
* fix monorepos release ([7eebffb](https://github.com/MoLow/reporters/commit/7eebffb46ab627beaa2b10023a08dd3271f819e9))
|
|
75
|
-
* fix monorepos release ([9c66f37](https://github.com/MoLow/reporters/commit/9c66f37b010f782e70c3cdf2bf827d30c4aa71c2))
|
|
76
|
-
* fix monorepos release ([d844919](https://github.com/MoLow/reporters/commit/d844919c8684216155b8f1c0acc98d907b3a5cdb))
|
|
77
|
-
* fix monorepos release ([d5610e2](https://github.com/MoLow/reporters/commit/d5610e29db730dc4ffa3f9721a85d5f3c7749b2c))
|
|
78
|
-
* fix typo ([#22](https://github.com/MoLow/reporters/issues/22)) ([0308fac](https://github.com/MoLow/reporters/commit/0308fac968799a0fd877460deeaa5503bc53d09f))
|
|
79
|
-
* reset changelogs ([1e114ce](https://github.com/MoLow/reporters/commit/1e114ced7201cf9897f2cf79b5a4fb46f1b085fb))
|
|
80
|
-
|
|
81
|
-
## 1.0.0 (2022-12-19)
|
|
82
|
-
|
|
83
|
-
Initial release
|
package/tests/index.test.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const { test, describe } = require('node:test');
|
|
2
|
-
const { spawnSync } = require('child_process');
|
|
3
|
-
const { tmpdir } = require('os');
|
|
4
|
-
const { join } = require('path');
|
|
5
|
-
const assert = require('assert');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const { readFileSync, writeFileSync } = require('fs');
|
|
8
|
-
const { compareLines } = require('../../../tests/utils');
|
|
9
|
-
const output = require('./output');
|
|
10
|
-
|
|
11
|
-
const GITHUB_STEP_SUMMARY = join(tmpdir(), 'github-actions-test-reporter');
|
|
12
|
-
writeFileSync(GITHUB_STEP_SUMMARY, '');
|
|
13
|
-
|
|
14
|
-
describe('github reporter', () => {
|
|
15
|
-
const child = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example'], {
|
|
16
|
-
env: { GITHUB_ACTIONS: true, GITHUB_STEP_SUMMARY, GITHUB_WORKSPACE: path.resolve(__dirname, '../../../') },
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('spwan with reporter', () => {
|
|
20
|
-
assert.strictEqual(child.stderr?.toString(), '');
|
|
21
|
-
compareLines(child.stdout?.toString(), output.stdout);
|
|
22
|
-
compareLines(readFileSync(GITHUB_STEP_SUMMARY).toString(), output.summary);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('should noop if not in github actions', () => {
|
|
26
|
-
const silentChild = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example'], { env: { } });
|
|
27
|
-
assert.strictEqual(silentChild.stderr?.toString(), '');
|
|
28
|
-
assert.strictEqual(silentChild.stdout?.toString(), '');
|
|
29
|
-
});
|
|
30
|
-
});
|
package/tests/output.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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=tests/example.js::\\[Error \\[ERR_TEST_FAILURE\\]: this is an error\\] {%0A failureType: 'testCodeFailure',%0A cause: Error: this is an error%0A at .*.<anonymous> (.*/example.js:6:11).*
|
|
7
|
-
::debug::starting to run is a diagnostic
|
|
8
|
-
::debug::completed running is a diagnostic
|
|
9
|
-
::notice file=tests/example.js::this is a diagnostic
|
|
10
|
-
::error title=tests,file=tests/example.js::\\[Error \\[ERR_TEST_FAILURE\\]: 1 subtest failed\\] { failureType: 'subtestsFailed', cause: '1 subtest failed', code: 'ERR_TEST_FAILURE' }
|
|
11
|
-
::debug::starting to run more tests
|
|
12
|
-
::debug::starting to run is ok
|
|
13
|
-
::debug::completed running is ok
|
|
14
|
-
::debug::completed running more tests
|
|
15
|
-
::debug::starting to run is skipped
|
|
16
|
-
::debug::completed running is skipped
|
|
17
|
-
::debug::starting to run is a todo
|
|
18
|
-
::debug::completed running is a todo
|
|
19
|
-
::group::Test results \\(3 passed, 1 failed\\)
|
|
20
|
-
::notice::Total Tests: 6%0ASuites 📂: 2%0APassed ✅: 3%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 1%0ATodo 📝: 1%0ADuration 🕐: .*ms
|
|
21
|
-
::endgroup::
|
|
22
|
-
`,
|
|
23
|
-
summary: `<h1>Test Results</h1>
|
|
24
|
-
<table><tr><td>Total Tests</td><td>6</td></tr><tr><td>Suites 📂</td><td>2</td></tr><tr><td>Passed ✅</td><td>3</td></tr><tr><td>Failed ❌</td><td>1</td></tr><tr><td>Canceled 🚫</td><td>0</td></tr><tr><td>Skipped ⏭️</td><td>1</td></tr><tr><td>Todo 📝</td><td>1</td></tr><tr><td>Duration 🕐</td><td>.*ms</td></tr></table>
|
|
25
|
-
`,
|
|
26
|
-
};
|