@reporters/github 1.0.2 → 1.1.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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.1](https://github.com/MoLow/reporters/compare/github-v1.1.0...github-v1.1.1) (2023-02-28)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **github:** silent if not running on github actions ([#33](https://github.com/MoLow/reporters/issues/33)) ([a480454](https://github.com/MoLow/reporters/commit/a480454ac7ca0471744ec00b69a6c67a1d3c8ada))
9
+
10
+ ## [1.1.0](https://github.com/MoLow/reporters/compare/github-v1.0.2...github-v1.1.0) (2023-02-02)
11
+
12
+
13
+ ### Features
14
+
15
+ * use reported file ([#30](https://github.com/MoLow/reporters/issues/30)) ([4c70922](https://github.com/MoLow/reporters/commit/4c709222734de88af71c5a086622c3b022d51fd5))
16
+
3
17
  ## [1.0.2](https://github.com/MoLow/reporters/compare/github-v1.0.1...github-v1.0.2) (2022-12-25)
4
18
 
5
19
 
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/);
@@ -33,39 +33,39 @@ const DIAGNOSTIC_VALUES = {
33
33
  };
34
34
 
35
35
  module.exports = async function githubReporter(source) {
36
+ if (!process.env.GITHUB_ACTIONS) {
37
+ // eslint-disable-next-line no-unused-vars
38
+ for await (const _ of source);
39
+ return;
40
+ }
36
41
  const counter = { pass: 0, fail: 0 };
37
42
  const diagnostics = [];
38
- let currentFile = null;
39
43
  for await (const event of source) {
40
44
  switch (event.type) {
41
45
  case 'test:start':
42
- currentFile = getCurrentFile(event.data.name) || currentFile;
43
46
  core.debug(`starting to run ${event.data.name}`);
44
47
  break;
45
48
  case 'test:pass':
46
49
  counter.pass += 1;
47
50
  core.debug(`completed running ${event.data.name}`);
48
- currentFile = isFile(event.data.name) ? null : currentFile;
49
51
  break;
50
52
  case 'test:fail': {
51
53
  const error = util.inspect(
52
54
  event.data.details?.error,
53
55
  { colors: false, breakLength: Infinity },
54
56
  );
55
- const location = parseStack(event.data.details?.error, currentFile);
57
+ const location = parseStack(event.data.details?.error, getFilePath(event.data.file));
56
58
  core.error(error, {
57
- file: location?.file ?? currentFile,
59
+ file: location?.file ?? getFilePath(event.data.file),
58
60
  startLine: location?.line,
59
61
  startColumn: location?.column,
60
62
  title: event.data.name,
61
63
  });
62
64
  counter.fail += 1;
63
- currentFile = isFile(event.data.name) ? null : currentFile;
64
65
  break;
65
66
  } case 'test:diagnostic':
66
- if (currentFile) {
67
- core.notice(event.data.message, { file: currentFile });
68
- } else {
67
+ core.notice(event.data.message, { file: getFilePath(event.data.file) });
68
+ if (event.data.nesting === 0) {
69
69
  diagnostics.push(event.data.message);
70
70
  }
71
71
  break;
@@ -85,8 +85,10 @@ module.exports = async function githubReporter(source) {
85
85
  core.notice(formatedDiagnostics.map((d) => d.join(': ')).join(EOL));
86
86
  core.endGroup();
87
87
 
88
- await core.summary
89
- .addHeading('Test Results')
90
- .addTable(formatedDiagnostics)
91
- .write();
88
+ if (process.env.GITHUB_STEP_SUMMARY) {
89
+ await core.summary
90
+ .addHeading('Test Results')
91
+ .addTable(formatedDiagnostics)
92
+ .write();
93
+ }
92
94
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reporters/github",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "description": "A github actions reporter for `node:test`",
5
5
  "keywords": [
6
6
  "github actions",
@@ -14,7 +14,7 @@
14
14
  "stack-utils": "^2.0.6"
15
15
  },
16
16
  "scripts": {
17
- "test": "../../prebuilt --test"
17
+ "test": "node --test-reporter=spec --test-reporter-destination=stdout --test-reporter=./index.js --test-reporter-destination=stdout --test"
18
18
  },
19
19
  "bugs": {
20
20
  "url": "https://github.com/MoLow/reporters/issues"
@@ -2,6 +2,7 @@ const { spawnSync } = require('child_process');
2
2
  const { tmpdir } = require('os');
3
3
  const { join } = require('path');
4
4
  const assert = require('assert');
5
+ const path = require('path');
5
6
  const { readFileSync, writeFileSync } = require('fs');
6
7
  const { compareLines } = require('../../../tests/utils');
7
8
  const output = require('./output');
@@ -10,7 +11,7 @@ const GITHUB_STEP_SUMMARY = join(tmpdir(), 'github-actions-test-reporter');
10
11
  writeFileSync(GITHUB_STEP_SUMMARY, '');
11
12
 
12
13
  const child = spawnSync(process.execPath, ['--test-reporter', './index.js', '../../tests/example'], {
13
- env: { GITHUB_STEP_SUMMARY },
14
+ env: { GITHUB_ACTIONS: true, GITHUB_STEP_SUMMARY, GITHUB_WORKSPACE: path.resolve(__dirname, '../../../') },
14
15
  });
15
16
 
16
17
  assert.strictEqual(child.stderr?.toString(), '');
package/tests/output.js CHANGED
@@ -3,8 +3,15 @@ module.exports = {
3
3
  ::debug::starting to run is ok
4
4
  ::debug::completed running is ok
5
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' }
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 .*
8
15
  ::group::Test results \\(1 passed, 2 failed\\)
9
16
  ::notice::Total Tests: 1%0APassed ✅: 0%0AFailed ❌: 1%0ACanceled 🚫: 0%0ASkipped ⏭️: 0%0ATodo 📝: 0%0ADuration: .*ms
10
17
  ::endgroup::