@reporters/github 1.4.0 → 1.5.0

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 CHANGED
@@ -25,11 +25,19 @@ yarn add --dev @reporters/github
25
25
 
26
26
  ## Result
27
27
 
28
- when test failed, you can see the result as an annotation on the failed line.
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
- <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
+ #### Inline annotations
31
32
 
32
- additionally, this reporter will add a summary of the tests to the github action.
33
+ <img width="810" alt="Inline Annotation" src="https://user-images.githubusercontent.com/8221854/254798653-0c06278e-696b-42eb-8275-364b7eb3133b.png">
33
34
 
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">
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
@@ -13,8 +13,10 @@ const isFile = (name) => name?.startsWith(WORKSPACE);
13
13
  const getFilePath = (name) => (isFile(name) ? path.relative(WORKSPACE, require.resolve(name) ?? '') : null);
14
14
 
15
15
  const parseStack = (error, file) => {
16
- const stackLines = (error?.stack ?? '').split(/\r?\n/);
16
+ const err = error?.code === 'ERR_TEST_FAILURE' ? error?.cause : error;
17
+ const stackLines = (err?.stack ?? '').split(/\r?\n/);
17
18
  const line = stackLines.find((l) => l.includes(file)) ?? stackLines[0];
19
+
18
20
  return line ? stack.parseLine(line) : null;
19
21
  };
20
22
 
@@ -51,12 +53,14 @@ module.exports = async function githubReporter(source) {
51
53
  core.debug(`completed running ${event.data.name}`);
52
54
  break;
53
55
  case 'test:fail': {
54
- const error = util.inspect(
55
- event.data.details?.error,
56
- { colors: false, breakLength: Infinity },
57
- );
58
- const location = parseStack(event.data.details?.error, getFilePath(event.data.file));
59
- core.error(error, {
56
+ const error = event.data.details?.error;
57
+ if (error?.code === 'ERR_TEST_FAILURE' && error?.failureType === 'subtestsFailed') {
58
+ // this means the failed subtests are already reported
59
+ // no need to re-annotate the file itself
60
+ break;
61
+ }
62
+ const location = parseStack(error, getFilePath(event.data.file));
63
+ core.error(util.inspect(error, { colors: false, breakLength: Infinity }), {
60
64
  file: location?.file ?? getFilePath(event.data.file),
61
65
  startLine: location?.line,
62
66
  startColumn: location?.column,
@@ -75,7 +79,6 @@ module.exports = async function githubReporter(source) {
75
79
  break;
76
80
  }
77
81
  }
78
- core.startGroup(`Test results (${counter.pass} passed, ${counter.fail} failed)`);
79
82
  const formatedDiagnostics = diagnostics.map((d) => {
80
83
  const [key, ...rest] = d.split(' ');
81
84
  const value = rest.join(' ');
@@ -84,6 +87,7 @@ module.exports = async function githubReporter(source) {
84
87
  DIAGNOSTIC_VALUES[key] ? DIAGNOSTIC_VALUES[key](value) : value,
85
88
  ];
86
89
  });
90
+ core.startGroup(`Test results (${formatedDiagnostics.find(([key]) => key === DIAGNOSTIC_KEYS.pass)?.[1] ?? counter.pass} passed, ${formatedDiagnostics.find(([key]) => key === DIAGNOSTIC_KEYS.fail)?.[1] ?? counter.fail} failed)`);
87
91
  core.notice(formatedDiagnostics.map((d) => d.join(': ')).join(EOL));
88
92
  core.endGroup();
89
93
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reporters/github",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
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,76 +0,0 @@
1
- # Changelog
2
-
3
- ## [1.4.0](https://github.com/MoLow/reporters/compare/github-v1.3.0...github-v1.4.0) (2023-07-18)
4
-
5
-
6
- ### Features
7
-
8
- * support node 18 ([02c8957](https://github.com/MoLow/reporters/commit/02c8957ffca3cb8376f7ad5a94f4627c70b7f8e5))
9
-
10
- ## [1.3.0](https://github.com/MoLow/reporters/compare/github-v1.2.0...github-v1.3.0) (2023-07-05)
11
-
12
-
13
- ### Features
14
-
15
- * publish with provenance ([6ee1e46](https://github.com/MoLow/reporters/commit/6ee1e46040329edeb0f40f753093b6952984f001))
16
-
17
- ## [1.2.0](https://github.com/MoLow/reporters/compare/github-v1.1.3...github-v1.2.0) (2023-05-30)
18
-
19
-
20
- ### Features
21
-
22
- * report node 20 features ([c99a76c](https://github.com/MoLow/reporters/commit/c99a76c0f6bef75abb2c053c82c88448b0c82690))
23
-
24
- ## [1.1.3](https://github.com/MoLow/reporters/compare/github-v1.1.2...github-v1.1.3) (2023-04-03)
25
-
26
-
27
- ### Bug Fixes
28
-
29
- * allow multiple roots ([590df94](https://github.com/MoLow/reporters/commit/590df948f8a4626fc29e8ce185e08d2226a307ba))
30
-
31
- ## [1.1.2](https://github.com/MoLow/reporters/compare/github-v1.1.1...github-v1.1.2) (2023-02-28)
32
-
33
-
34
- ### Bug Fixes
35
-
36
- * **github:** remove redundant diagnostics ([b62df32](https://github.com/MoLow/reporters/commit/b62df3280b141af763386a68b0b4e386bef907e7))
37
-
38
- ## [1.1.1](https://github.com/MoLow/reporters/compare/github-v1.1.0...github-v1.1.1) (2023-02-28)
39
-
40
-
41
- ### Bug Fixes
42
-
43
- * **github:** silent if not running on github actions ([#33](https://github.com/MoLow/reporters/issues/33)) ([a480454](https://github.com/MoLow/reporters/commit/a480454ac7ca0471744ec00b69a6c67a1d3c8ada))
44
-
45
- ## [1.1.0](https://github.com/MoLow/reporters/compare/github-v1.0.2...github-v1.1.0) (2023-02-02)
46
-
47
-
48
- ### Features
49
-
50
- * use reported file ([#30](https://github.com/MoLow/reporters/issues/30)) ([4c70922](https://github.com/MoLow/reporters/commit/4c709222734de88af71c5a086622c3b022d51fd5))
51
-
52
- ## [1.0.2](https://github.com/MoLow/reporters/compare/github-v1.0.1...github-v1.0.2) (2022-12-25)
53
-
54
-
55
- ### Bug Fixes
56
-
57
- * fix package description ([cec07c7](https://github.com/MoLow/reporters/commit/cec07c70d37b3ed43947b17312a6bd58f095510f))
58
- * some package.json links ([c51a616](https://github.com/MoLow/reporters/commit/c51a61648e29f5baca539ded1b09c2af3f5e0a4a))
59
-
60
- ## [1.0.1](https://github.com/MoLow/reporters/compare/github-v1.0.0...github-v1.0.1) (2022-12-20)
61
-
62
-
63
- ### Bug Fixes
64
-
65
- * fix monorepos release ([8386ef0](https://github.com/MoLow/reporters/commit/8386ef0ea7bfe0c0325e171aa7122eeccb17bad3))
66
- * fix monorepos release ([3c5ee61](https://github.com/MoLow/reporters/commit/3c5ee6126fe961363b3feccf1ba6594a0849855b))
67
- * fix monorepos release ([7eebffb](https://github.com/MoLow/reporters/commit/7eebffb46ab627beaa2b10023a08dd3271f819e9))
68
- * fix monorepos release ([9c66f37](https://github.com/MoLow/reporters/commit/9c66f37b010f782e70c3cdf2bf827d30c4aa71c2))
69
- * fix monorepos release ([d844919](https://github.com/MoLow/reporters/commit/d844919c8684216155b8f1c0acc98d907b3a5cdb))
70
- * fix monorepos release ([d5610e2](https://github.com/MoLow/reporters/commit/d5610e29db730dc4ffa3f9721a85d5f3c7749b2c))
71
- * fix typo ([#22](https://github.com/MoLow/reporters/issues/22)) ([0308fac](https://github.com/MoLow/reporters/commit/0308fac968799a0fd877460deeaa5503bc53d09f))
72
- * reset changelogs ([1e114ce](https://github.com/MoLow/reporters/commit/1e114ced7201cf9897f2cf79b5a4fb46f1b085fb))
73
-
74
- ## 1.0.0 (2022-12-19)
75
-
76
- Initial release
@@ -1,31 +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
- // eslint-disable-next-line import/no-dynamic-require
10
- const output = require(`./output.${process.version.split('.')[0]}`);
11
-
12
- const GITHUB_STEP_SUMMARY = join(tmpdir(), 'github-actions-test-reporter');
13
- writeFileSync(GITHUB_STEP_SUMMARY, '');
14
-
15
- describe('github reporter', () => {
16
- const child = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example'], {
17
- env: { GITHUB_ACTIONS: true, GITHUB_STEP_SUMMARY, GITHUB_WORKSPACE: path.resolve(__dirname, '../../../') },
18
- });
19
-
20
- test('spwan with reporter', () => {
21
- assert.strictEqual(child.stderr?.toString(), '');
22
- compareLines(child.stdout?.toString(), output.stdout);
23
- compareLines(readFileSync(GITHUB_STEP_SUMMARY).toString(), output.summary);
24
- });
25
-
26
- test('should noop if not in github actions', () => {
27
- const silentChild = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example'], { env: { } });
28
- assert.strictEqual(silentChild.stderr?.toString(), '');
29
- assert.strictEqual(silentChild.stdout?.toString(), '');
30
- });
31
- });
@@ -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 \\(6 passed, 2 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
- };
@@ -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 \\(6 passed, 2 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
- };
@@ -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 \\(6 passed, 2 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
- };