@reporters/github 1.0.2 → 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,12 @@
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
+
3
10
  ## [1.0.2](https://github.com/MoLow/reporters/compare/github-v1.0.1...github-v1.0.2) (2022-12-25)
4
11
 
5
12
 
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@reporters/github",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
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"
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_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::