@reporters/github 1.13.1 → 2.0.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.
Files changed (3) hide show
  1. package/gh_core.js +27 -13
  2. package/index.js +14 -23
  3. package/package.json +7 -3
package/gh_core.js CHANGED
@@ -1,18 +1,37 @@
1
- 'use strict';
1
+ import { EOL } from 'node:os';
2
2
 
3
- // From Github Core SDK code
4
- // eslint-disable-next-line import/no-unresolved
5
- const coreUtils = require('@actions/core/lib/utils');
6
- const { EOL } = require('node:os');
3
+ function toCommandValue(input) {
4
+ if (input === null || input === undefined) {
5
+ return '';
6
+ }
7
+ if (typeof input === 'string' || input instanceof String) {
8
+ return input;
9
+ }
10
+ return JSON.stringify(input);
11
+ }
12
+
13
+ export function toCommandProperties(annotationProperties) {
14
+ if (!Object.keys(annotationProperties).length) {
15
+ return {};
16
+ }
17
+ return {
18
+ title: annotationProperties.title,
19
+ file: annotationProperties.file,
20
+ line: annotationProperties.startLine,
21
+ endLine: annotationProperties.endLine,
22
+ col: annotationProperties.startColumn,
23
+ endColumn: annotationProperties.endColumn,
24
+ };
25
+ }
7
26
 
8
27
  function escapeData(s) {
9
- return coreUtils.toCommandValue(s)
28
+ return toCommandValue(s)
10
29
  .replace(/%/g, '%25')
11
30
  .replace(/\r/g, '%0D')
12
31
  .replace(/\n/g, '%0A');
13
32
  }
14
33
  function escapeProperty(s) {
15
- return coreUtils.toCommandValue(s)
34
+ return toCommandValue(s)
16
35
  .replace(/%/g, '%25')
17
36
  .replace(/\r/g, '%0D')
18
37
  .replace(/\n/g, '%0A')
@@ -21,7 +40,7 @@ function escapeProperty(s) {
21
40
  }
22
41
 
23
42
  const CMD_STRING = '::';
24
- class Command {
43
+ export class Command {
25
44
  constructor(command, properties, message, options = { EOL }) {
26
45
  this.command = command ?? 'missing.command';
27
46
  this.properties = properties;
@@ -54,8 +73,3 @@ class Command {
54
73
  return cmdStr;
55
74
  }
56
75
  }
57
-
58
- module.exports = {
59
- toCommandProperties: coreUtils.toCommandProperties,
60
- Command,
61
- };
package/index.js CHANGED
@@ -1,12 +1,10 @@
1
- 'use strict';
2
-
3
- const path = require('node:path');
4
- const { fileURLToPath } = require('node:url');
5
- const util = require('node:util');
6
- const { EOL } = require('node:os');
7
- const core = require('@actions/core');
8
- const StackUtils = require('stack-utils');
9
- const { Command, toCommandProperties } = require('./gh_core');
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import util from 'node:util';
4
+ import { EOL } from 'node:os';
5
+ import { summary } from '@actions/core';
6
+ import StackUtils from 'stack-utils';
7
+ import { Command, toCommandProperties } from './gh_core.js';
10
8
 
11
9
  const WORKSPACE = process.env.GITHUB_WORKSPACE ?? '';
12
10
 
@@ -44,7 +42,7 @@ const DIAGNOSTIC_KEYS = {
44
42
  duration_ms: 'Duration 🕐',
45
43
  };
46
44
 
47
- const DIAGNOSTIC_VALUES = {
45
+ export const DIAGNOSTIC_VALUES = {
48
46
  duration_ms: (value) => `${Number(value).toFixed(3)}ms`,
49
47
  };
50
48
 
@@ -66,14 +64,14 @@ function extractLocation(data) {
66
64
  const counter = { pass: 0, fail: 0 };
67
65
  const diagnostics = [];
68
66
 
69
- function isTopLevelDiagnostic(data) {
67
+ export function isTopLevelDiagnostic(data) {
70
68
  return (data.file === undefined
71
69
  || data.line === undefined
72
70
  || data.column === undefined
73
71
  || (data.line === 1 && data.column === 1));
74
72
  }
75
73
 
76
- function transformEvent(event) {
74
+ export function transformEvent(event) {
77
75
  switch (event.type) {
78
76
  case 'test:start':
79
77
  return new Command('debug', {}, `starting to run ${event.data.name}`).toString();
@@ -83,8 +81,6 @@ function transformEvent(event) {
83
81
  case 'test:fail': {
84
82
  const error = event.data.details?.error;
85
83
  if (!error || (error.code === 'ERR_TEST_FAILURE' && error.failureType === 'subtestsFailed')) {
86
- // Either no error object on the event, or failed subtests are already
87
- // reported — no need to re-annotate the file itself.
88
84
  break;
89
85
  }
90
86
  const err = error.code === 'ERR_TEST_FAILURE' ? error.cause : error;
@@ -127,7 +123,7 @@ function transformEvent(event) {
127
123
  return '';
128
124
  }
129
125
 
130
- async function getSummary() {
126
+ export async function getSummary() {
131
127
  const formattedDiagnostics = diagnostics.map((d) => {
132
128
  const [key, ...rest] = d.split(' ');
133
129
  const value = rest.join(' ');
@@ -142,7 +138,7 @@ async function getSummary() {
142
138
  res += new Command('endgroup').toString();
143
139
 
144
140
  if (process.env.GITHUB_STEP_SUMMARY) {
145
- await core.summary
141
+ await summary
146
142
  .addHeading('Test Results')
147
143
  .addTable(formattedDiagnostics)
148
144
  .write();
@@ -150,7 +146,7 @@ async function getSummary() {
150
146
  return res;
151
147
  }
152
148
 
153
- module.exports = async function* githubReporter(source) {
149
+ export default async function* githubReporter(source) {
154
150
  if (!process.env.GITHUB_ACTIONS) {
155
151
  // eslint-disable-next-line no-unused-vars
156
152
  for await (const _ of source);
@@ -160,9 +156,4 @@ module.exports = async function* githubReporter(source) {
160
156
  yield transformEvent(event);
161
157
  }
162
158
  yield await getSummary();
163
- };
164
-
165
- module.exports.transformEvent = transformEvent;
166
- module.exports.getSummary = getSummary;
167
- module.exports.isTopLevelDiagnostic = isTopLevelDiagnostic;
168
- module.exports.DIAGNOSTIC_VALUES = DIAGNOSTIC_VALUES;
159
+ }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@reporters/github",
3
- "version": "1.13.1",
3
+ "version": "2.0.0",
4
4
  "description": "A github actions reporter for `node:test`",
5
- "type": "commonjs",
5
+ "type": "module",
6
6
  "keywords": [
7
7
  "github actions",
8
8
  "node:test",
@@ -11,7 +11,7 @@
11
11
  "reporters"
12
12
  ],
13
13
  "dependencies": {
14
- "@actions/core": "^2.0.3",
14
+ "@actions/core": "^3.0.1",
15
15
  "stack-utils": "^2.0.6"
16
16
  },
17
17
  "files": [
@@ -25,6 +25,10 @@
25
25
  "url": "https://github.com/MoLow/reporters/issues"
26
26
  },
27
27
  "main": "index.js",
28
+ "exports": {
29
+ ".": "./index.js",
30
+ "./gh_core": "./gh_core.js"
31
+ },
28
32
  "homepage": "https://github.com/MoLow/reporters/tree/main/packages/github",
29
33
  "repository": "https://github.com/MoLow/reporters.git",
30
34
  "author": "Moshe Atlow",