@reporters/github 1.5.0 → 1.5.2

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.
Files changed (2) hide show
  1. package/index.js +15 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ 'use strict';
2
+
1
3
  const path = require('node:path');
2
4
  const util = require('node:util');
3
5
  const { EOL } = require('node:os');
@@ -10,13 +12,19 @@ const stack = new StackUtils({ cwd: WORKSPACE, internals: StackUtils.nodeInterna
10
12
 
11
13
  const isFile = (name) => name?.startsWith(WORKSPACE);
12
14
 
13
- const getFilePath = (name) => (isFile(name) ? path.relative(WORKSPACE, require.resolve(name) ?? '') : null);
15
+ const getRelativeFilePath = (name) => (isFile(name) ? path.relative(WORKSPACE, require.resolve(name) ?? '') : null);
16
+
17
+ function getFilePath(fileName) {
18
+ if (fileName.startsWith('file://')) {
19
+ return getRelativeFilePath(new URL(fileName).pathname);
20
+ }
21
+ return getRelativeFilePath(fileName);
22
+ }
14
23
 
15
24
  const parseStack = (error, file) => {
16
25
  const err = error?.code === 'ERR_TEST_FAILURE' ? error?.cause : error;
17
26
  const stackLines = (err?.stack ?? '').split(/\r?\n/);
18
27
  const line = stackLines.find((l) => l.includes(file)) ?? stackLines[0];
19
-
20
28
  return line ? stack.parseLine(line) : null;
21
29
  };
22
30
 
@@ -55,13 +63,15 @@ module.exports = async function githubReporter(source) {
55
63
  case 'test:fail': {
56
64
  const error = event.data.details?.error;
57
65
  if (error?.code === 'ERR_TEST_FAILURE' && error?.failureType === 'subtestsFailed') {
58
- // this means the failed subtests are already reported
66
+ // This means the failed subtests are already reported
59
67
  // no need to re-annotate the file itself
60
68
  break;
61
69
  }
62
- const location = parseStack(error, getFilePath(event.data.file));
70
+ let filePath = getFilePath(event.data.file);
71
+ const location = parseStack(error, filePath);
72
+ filePath = getFilePath(location?.file ?? filePath) ?? filePath;
63
73
  core.error(util.inspect(error, { colors: false, breakLength: Infinity }), {
64
- file: location?.file ?? getFilePath(event.data.file),
74
+ file: filePath,
65
75
  startLine: location?.line,
66
76
  startColumn: location?.column,
67
77
  title: event.data.name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reporters/github",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "A github actions reporter for `node:test`",
5
5
  "keywords": [
6
6
  "github actions",