@reporters/github 1.0.1 → 1.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.0](https://github.com/MoLow/reporters/compare/github-v1.0.2...github-v1.1.0) (2023-02-02)
4
+
5
+
6
+ ### Features
7
+
8
+ * use reported file ([#30](https://github.com/MoLow/reporters/issues/30)) ([4c70922](https://github.com/MoLow/reporters/commit/4c709222734de88af71c5a086622c3b022d51fd5))
9
+
10
+ ## [1.0.2](https://github.com/MoLow/reporters/compare/github-v1.0.1...github-v1.0.2) (2022-12-25)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * fix package description ([cec07c7](https://github.com/MoLow/reporters/commit/cec07c70d37b3ed43947b17312a6bd58f095510f))
16
+ * some package.json links ([c51a616](https://github.com/MoLow/reporters/commit/c51a61648e29f5baca539ded1b09c2af3f5e0a4a))
17
+
3
18
  ## [1.0.1](https://github.com/MoLow/reporters/compare/github-v1.0.0...github-v1.0.1) (2022-12-20)
4
19
 
5
20
 
package/index.js CHANGED
@@ -10,7 +10,7 @@ const stack = new StackUtils({ cwd: WORKSPACE, internals: StackUtils.nodeInterna
10
10
 
11
11
  const isFile = (name) => name?.startsWith(WORKSPACE);
12
12
 
13
- const getCurrentFile = (name) => (isFile(name) ? path.relative(WORKSPACE, name) : null);
13
+ const getFilePath = (name) => (isFile(name) ? path.relative(WORKSPACE, require.resolve(name) ?? '') : null);
14
14
 
15
15
  const parseStack = (error, file) => {
16
16
  const stackLines = (error?.stack ?? '').split(/\r?\n/);
@@ -35,37 +35,32 @@ const DIAGNOSTIC_VALUES = {
35
35
  module.exports = async function githubReporter(source) {
36
36
  const counter = { pass: 0, fail: 0 };
37
37
  const diagnostics = [];
38
- let currentFile = null;
39
38
  for await (const event of source) {
40
39
  switch (event.type) {
41
40
  case 'test:start':
42
- currentFile = getCurrentFile(event.data.name) || currentFile;
43
41
  core.debug(`starting to run ${event.data.name}`);
44
42
  break;
45
43
  case 'test:pass':
46
44
  counter.pass += 1;
47
45
  core.debug(`completed running ${event.data.name}`);
48
- currentFile = isFile(event.data.name) ? null : currentFile;
49
46
  break;
50
47
  case 'test:fail': {
51
48
  const error = util.inspect(
52
49
  event.data.details?.error,
53
50
  { colors: false, breakLength: Infinity },
54
51
  );
55
- const location = parseStack(event.data.details?.error, currentFile);
52
+ const location = parseStack(event.data.details?.error, getFilePath(event.data.file));
56
53
  core.error(error, {
57
- file: location?.file ?? currentFile,
54
+ file: location?.file ?? getFilePath(event.data.file),
58
55
  startLine: location?.line,
59
56
  startColumn: location?.column,
60
57
  title: event.data.name,
61
58
  });
62
59
  counter.fail += 1;
63
- currentFile = isFile(event.data.name) ? null : currentFile;
64
60
  break;
65
61
  } case 'test:diagnostic':
66
- if (currentFile) {
67
- core.notice(event.data.message, { file: currentFile });
68
- } else {
62
+ core.notice(event.data.message, { file: getFilePath(event.data.file) });
63
+ if (event.data.nesting === 0) {
69
64
  diagnostics.push(event.data.message);
70
65
  }
71
66
  break;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reporters/github",
3
- "version": "1.0.1",
4
- "description": "A junit reporter for `node:test`",
3
+ "version": "1.1.0",
4
+ "description": "A github actions reporter for `node:test`",
5
5
  "keywords": [
6
6
  "github actions",
7
7
  "node:test",
@@ -14,9 +14,13 @@
14
14
  "stack-utils": "^2.0.6"
15
15
  },
16
16
  "scripts": {
17
- "test": "node tests/index.test.js"
17
+ "test": "node --test-reporter=spec --test"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/MoLow/reporters/issues"
18
21
  },
19
22
  "main": "index.js",
23
+ "homepage": "https://github.com/MoLow/reporters/tree/main/packages/github",
20
24
  "repository": "https://github.com/MoLow/reporters.git",
21
25
  "author": "Moshe Atlow",
22
26
  "license": "MIT"
@@ -1,6 +1,19 @@
1
- const events = require('./events');
2
- const reporter = require('../index');
1
+ const { spawnSync } = require('child_process');
2
+ const { tmpdir } = require('os');
3
+ const { join } = require('path');
4
+ const assert = require('assert');
5
+ const path = require('path');
6
+ const { readFileSync, writeFileSync } = require('fs');
7
+ const { compareLines } = require('../../../tests/utils');
8
+ const output = require('./output');
3
9
 
4
- // use the reporter manually until --test-reporter is released
5
- process.env.GITHUB_STEP_SUMMARY ??= '/dev/null';
6
- reporter(events);
10
+ const GITHUB_STEP_SUMMARY = join(tmpdir(), 'github-actions-test-reporter');
11
+ writeFileSync(GITHUB_STEP_SUMMARY, '');
12
+
13
+ const child = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example'], {
14
+ env: { GITHUB_STEP_SUMMARY, GITHUB_WORKSPACE: path.resolve(__dirname, '../../../') },
15
+ });
16
+
17
+ assert.strictEqual(child.stderr?.toString(), '');
18
+ compareLines(child.stdout?.toString(), output.stdout);
19
+ compareLines(readFileSync(GITHUB_STEP_SUMMARY).toString(), output.summary);
@@ -0,0 +1,22 @@
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 Object.<anonymous> (.*/example.js:6:11).*
7
+ ::error title=tests,file=tests/example.js::\\[Error \\[ERR_TEST_FAILURE\\]: 1 subtest failed\\] { failureType: 'subtestsFailed', cause: '1 subtest failed', code: 'ERR_TEST_FAILURE' }
8
+ ::notice file=tests/example.js::tests 1
9
+ ::notice file=tests/example.js::pass 0
10
+ ::notice file=tests/example.js::fail 1
11
+ ::notice file=tests/example.js::cancelled 0
12
+ ::notice file=tests/example.js::skipped 0
13
+ ::notice file=tests/example.js::todo 0
14
+ ::notice file=tests/example.js::duration_ms .*
15
+ ::group::Test results \\(1 passed, 2 failed\\)
16
+ ::notice::Total Tests: 1%0APassed ✅: 0%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration: .*ms
17
+ ::endgroup::
18
+ `,
19
+ summary: `<h1>Test Results</h1>
20
+ <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>
21
+ `,
22
+ };
package/tests/events.js DELETED
@@ -1,170 +0,0 @@
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
- ];