From ef1f9a4e602c81f93767bcf641b6db657dbc9433 Mon Sep 17 00:00:00 2001 From: Jozef Izso Date: Mon, 2 Mar 2026 14:28:52 +0100 Subject: [PATCH] Refactor `test-reporter` to module based package --- package.json | 1 + src/input-providers/artifact-provider.ts | 6 +-- src/input-providers/local-file-provider.ts | 4 +- src/main.ts | 44 +++++++++---------- src/parsers/dart-json/dart-json-parser.ts | 8 ++-- .../dotnet-nunit/dotnet-nunit-parser.ts | 10 ++--- src/parsers/dotnet-trx/dotnet-trx-parser.ts | 10 ++--- src/parsers/golang-json/golang-json-parser.ts | 10 ++--- src/parsers/java-junit/java-junit-parser.ts | 10 ++--- src/parsers/jest-junit/jest-junit-parser.ts | 10 ++--- src/parsers/mocha-json/mocha-json-parser.ts | 10 ++--- .../phpunit-junit/phpunit-junit-parser.ts | 8 ++-- .../python-xunit/python-xunit-parser.ts | 4 +- src/parsers/rspec-json/rspec-json-parser.ts | 6 +-- src/parsers/swift-xunit/swift-xunit-parser.ts | 4 +- .../tester-junit/tester-junit-parser.ts | 8 ++-- src/report/get-annotations.ts | 6 +-- src/report/get-report.ts | 10 ++--- src/test-parser.ts | 2 +- src/test-results.ts | 2 +- src/utils/github-utils.ts | 2 +- src/utils/node-utils.ts | 2 +- src/utils/slugger.ts | 2 +- 23 files changed, 90 insertions(+), 89 deletions(-) diff --git a/package.json b/package.json index 8c390b0..edbc634 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.5.0", "private": true, "description": "Presents test results from popular testing frameworks as Github check run", + "type": "module", "main": "lib/main.js", "scripts": { "build": "tsc", diff --git a/src/input-providers/artifact-provider.ts b/src/input-providers/artifact-provider.ts index feeb22a..f91a002 100644 --- a/src/input-providers/artifact-provider.ts +++ b/src/input-providers/artifact-provider.ts @@ -1,12 +1,12 @@ import * as core from '@actions/core' import * as github from '@actions/github' -import {GitHub} from '@actions/github/lib/utils' +import {GitHub} from '@actions/github/lib/utils.js' import Zip from 'adm-zip' import picomatch from 'picomatch' -import {FileContent, InputProvider, ReportInput} from './input-provider' -import {downloadArtifact, listFiles} from '../utils/github-utils' +import {FileContent, InputProvider, ReportInput} from './input-provider.js' +import {downloadArtifact, listFiles} from '../utils/github-utils.js' export class ArtifactProvider implements InputProvider { private readonly artifactNameMatch: (name: string) => boolean diff --git a/src/input-providers/local-file-provider.ts b/src/input-providers/local-file-provider.ts index e1afd8c..8529869 100644 --- a/src/input-providers/local-file-provider.ts +++ b/src/input-providers/local-file-provider.ts @@ -1,7 +1,7 @@ import * as fs from 'fs' import glob from 'fast-glob' -import {FileContent, InputProvider, ReportInput} from './input-provider' -import {listFiles} from '../utils/git' +import {FileContent, InputProvider, ReportInput} from './input-provider.js' +import {listFiles} from '../utils/git.js' export class LocalFileProvider implements InputProvider { constructor( diff --git a/src/main.ts b/src/main.ts index 9b24d38..2734ee8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,29 +1,29 @@ import * as core from '@actions/core' import * as github from '@actions/github' -import {GitHub} from '@actions/github/lib/utils' +import {GitHub} from '@actions/github/lib/utils.js' -import {ArtifactProvider} from './input-providers/artifact-provider' -import {LocalFileProvider} from './input-providers/local-file-provider' -import {FileContent} from './input-providers/input-provider' -import {ParseOptions, TestParser} from './test-parser' -import {TestRunResult} from './test-results' -import {getAnnotations} from './report/get-annotations' -import {getReport} from './report/get-report' +import {ArtifactProvider} from './input-providers/artifact-provider.js' +import {LocalFileProvider} from './input-providers/local-file-provider.js' +import {FileContent} from './input-providers/input-provider.js' +import {ParseOptions, TestParser} from './test-parser.js' +import {TestRunResult} from './test-results.js' +import {getAnnotations} from './report/get-annotations.js' +import {getReport} from './report/get-report.js' -import {DartJsonParser} from './parsers/dart-json/dart-json-parser' -import {DotnetNunitParser} from './parsers/dotnet-nunit/dotnet-nunit-parser' -import {DotnetTrxParser} from './parsers/dotnet-trx/dotnet-trx-parser' -import {GolangJsonParser} from './parsers/golang-json/golang-json-parser' -import {JavaJunitParser} from './parsers/java-junit/java-junit-parser' -import {JestJunitParser} from './parsers/jest-junit/jest-junit-parser' -import {MochaJsonParser} from './parsers/mocha-json/mocha-json-parser' -import {PhpunitJunitParser} from './parsers/phpunit-junit/phpunit-junit-parser' -import {PythonXunitParser} from './parsers/python-xunit/python-xunit-parser' -import {RspecJsonParser} from './parsers/rspec-json/rspec-json-parser' -import {SwiftXunitParser} from './parsers/swift-xunit/swift-xunit-parser' -import {NetteTesterJunitParser} from './parsers/tester-junit/tester-junit-parser' -import {normalizeDirPath, normalizeFilePath} from './utils/path-utils' -import {getCheckRunContext} from './utils/github-utils' +import {DartJsonParser} from './parsers/dart-json/dart-json-parser.js' +import {DotnetNunitParser} from './parsers/dotnet-nunit/dotnet-nunit-parser.js' +import {DotnetTrxParser} from './parsers/dotnet-trx/dotnet-trx-parser.js' +import {GolangJsonParser} from './parsers/golang-json/golang-json-parser.js' +import {JavaJunitParser} from './parsers/java-junit/java-junit-parser.js' +import {JestJunitParser} from './parsers/jest-junit/jest-junit-parser.js' +import {MochaJsonParser} from './parsers/mocha-json/mocha-json-parser.js' +import {PhpunitJunitParser} from './parsers/phpunit-junit/phpunit-junit-parser.js' +import {PythonXunitParser} from './parsers/python-xunit/python-xunit-parser.js' +import {RspecJsonParser} from './parsers/rspec-json/rspec-json-parser.js' +import {SwiftXunitParser} from './parsers/swift-xunit/swift-xunit-parser.js' +import {NetteTesterJunitParser} from './parsers/tester-junit/tester-junit-parser.js' +import {normalizeDirPath, normalizeFilePath} from './utils/path-utils.js' +import {getCheckRunContext} from './utils/github-utils.js' async function main(): Promise { try { diff --git a/src/parsers/dart-json/dart-json-parser.ts b/src/parsers/dart-json/dart-json-parser.ts index b035897..7e4b5cf 100644 --- a/src/parsers/dart-json/dart-json-parser.ts +++ b/src/parsers/dart-json/dart-json-parser.ts @@ -1,6 +1,6 @@ -import {ParseOptions, TestParser} from '../../test-parser' +import {ParseOptions, TestParser} from '../../test-parser.js' -import {getBasePath, normalizeFilePath} from '../../utils/path-utils' +import {getBasePath, normalizeFilePath} from '../../utils/path-utils.js' import { ReportEvent, @@ -17,7 +17,7 @@ import { isDoneEvent, isMessageEvent, MessageEvent -} from './dart-json-types' +} from './dart-json-types.js' import { TestExecutionResult, @@ -26,7 +26,7 @@ import { TestGroupResult, TestCaseResult, TestCaseError -} from '../../test-results' +} from '../../test-results.js' class TestRun { constructor( diff --git a/src/parsers/dotnet-nunit/dotnet-nunit-parser.ts b/src/parsers/dotnet-nunit/dotnet-nunit-parser.ts index 4f996ef..dfb8c99 100644 --- a/src/parsers/dotnet-nunit/dotnet-nunit-parser.ts +++ b/src/parsers/dotnet-nunit/dotnet-nunit-parser.ts @@ -1,9 +1,9 @@ -import {ParseOptions, TestParser} from '../../test-parser' +import {ParseOptions, TestParser} from '../../test-parser.js' import {parseStringPromise} from 'xml2js' -import {NunitReport, TestCase, TestSuite} from './dotnet-nunit-types' -import {getExceptionSource} from '../../utils/node-utils' -import {getBasePath, normalizeFilePath} from '../../utils/path-utils' +import {NunitReport, TestCase, TestSuite} from './dotnet-nunit-types.js' +import {getExceptionSource} from '../../utils/node-utils.js' +import {getBasePath, normalizeFilePath} from '../../utils/path-utils.js' import { TestExecutionResult, @@ -12,7 +12,7 @@ import { TestGroupResult, TestCaseResult, TestCaseError -} from '../../test-results' +} from '../../test-results.js' export class DotnetNunitParser implements TestParser { assumedWorkDir: string | undefined diff --git a/src/parsers/dotnet-trx/dotnet-trx-parser.ts b/src/parsers/dotnet-trx/dotnet-trx-parser.ts index 9288133..9ffdd40 100644 --- a/src/parsers/dotnet-trx/dotnet-trx-parser.ts +++ b/src/parsers/dotnet-trx/dotnet-trx-parser.ts @@ -1,10 +1,10 @@ import {parseStringPromise} from 'xml2js' -import {ErrorInfo, Outcome, TrxReport, UnitTest, UnitTestResult} from './dotnet-trx-types' -import {ParseOptions, TestParser} from '../../test-parser' +import {ErrorInfo, Outcome, TrxReport, UnitTest, UnitTestResult} from './dotnet-trx-types.js' +import {ParseOptions, TestParser} from '../../test-parser.js' -import {getBasePath, normalizeFilePath} from '../../utils/path-utils' -import {parseIsoDate, parseNetDuration} from '../../utils/parse-utils' +import {getBasePath, normalizeFilePath} from '../../utils/path-utils.js' +import {parseIsoDate, parseNetDuration} from '../../utils/parse-utils.js' import { TestExecutionResult, @@ -13,7 +13,7 @@ import { TestGroupResult, TestCaseResult, TestCaseError -} from '../../test-results' +} from '../../test-results.js' class TestClass { constructor(readonly name: string) {} diff --git a/src/parsers/golang-json/golang-json-parser.ts b/src/parsers/golang-json/golang-json-parser.ts index bc20821..afa8041 100644 --- a/src/parsers/golang-json/golang-json-parser.ts +++ b/src/parsers/golang-json/golang-json-parser.ts @@ -1,8 +1,8 @@ -import { ParseOptions, TestParser } from '../../test-parser' +import { ParseOptions, TestParser } from '../../test-parser.js' -import { GoTestEvent } from './golang-json-types' -import { getExceptionSource } from '../../utils/node-utils' -import { getBasePath, normalizeFilePath } from '../../utils/path-utils' +import { GoTestEvent } from './golang-json-types.js' +import { getExceptionSource } from '../../utils/node-utils.js' +import { getBasePath, normalizeFilePath } from '../../utils/path-utils.js' import { TestExecutionResult, @@ -11,7 +11,7 @@ import { TestGroupResult, TestCaseResult, TestCaseError -} from '../../test-results' +} from '../../test-results.js' export class GolangJsonParser implements TestParser { assumedWorkDir: string | undefined diff --git a/src/parsers/java-junit/java-junit-parser.ts b/src/parsers/java-junit/java-junit-parser.ts index 5163f46..da17cfa 100644 --- a/src/parsers/java-junit/java-junit-parser.ts +++ b/src/parsers/java-junit/java-junit-parser.ts @@ -1,10 +1,10 @@ import * as path from 'path' -import {ParseOptions, TestParser} from '../../test-parser' +import {ParseOptions, TestParser} from '../../test-parser.js' import {parseStringPromise} from 'xml2js' -import {JunitReport, SingleSuiteReport, TestCase, TestSuite} from './java-junit-types' -import {parseStackTraceElement} from './java-stack-trace-element-parser' -import {normalizeFilePath} from '../../utils/path-utils' +import {JunitReport, SingleSuiteReport, TestCase, TestSuite} from './java-junit-types.js' +import {parseStackTraceElement} from './java-stack-trace-element-parser.js' +import {normalizeFilePath} from '../../utils/path-utils.js' import { TestExecutionResult, @@ -13,7 +13,7 @@ import { TestGroupResult, TestCaseResult, TestCaseError -} from '../../test-results' +} from '../../test-results.js' export class JavaJunitParser implements TestParser { readonly trackedFiles: {[fileName: string]: string[]} diff --git a/src/parsers/jest-junit/jest-junit-parser.ts b/src/parsers/jest-junit/jest-junit-parser.ts index a281a78..764fa3a 100644 --- a/src/parsers/jest-junit/jest-junit-parser.ts +++ b/src/parsers/jest-junit/jest-junit-parser.ts @@ -1,9 +1,9 @@ -import {ParseOptions, TestParser} from '../../test-parser' +import {ParseOptions, TestParser} from '../../test-parser.js' import {parseStringPromise} from 'xml2js' -import {JunitReport, TestCase, TestSuite} from './jest-junit-types' -import {getExceptionSource} from '../../utils/node-utils' -import {getBasePath, normalizeFilePath} from '../../utils/path-utils' +import {JunitReport, TestCase, TestSuite} from './jest-junit-types.js' +import {getExceptionSource} from '../../utils/node-utils.js' +import {getBasePath, normalizeFilePath} from '../../utils/path-utils.js' import { TestExecutionResult, @@ -12,7 +12,7 @@ import { TestGroupResult, TestCaseResult, TestCaseError -} from '../../test-results' +} from '../../test-results.js' export class JestJunitParser implements TestParser { assumedWorkDir: string | undefined diff --git a/src/parsers/mocha-json/mocha-json-parser.ts b/src/parsers/mocha-json/mocha-json-parser.ts index 3efc2ad..741d6c8 100644 --- a/src/parsers/mocha-json/mocha-json-parser.ts +++ b/src/parsers/mocha-json/mocha-json-parser.ts @@ -1,4 +1,4 @@ -import {ParseOptions, TestParser} from '../../test-parser' +import {ParseOptions, TestParser} from '../../test-parser.js' import { TestCaseError, TestCaseResult, @@ -6,10 +6,10 @@ import { TestGroupResult, TestRunResult, TestSuiteResult -} from '../../test-results' -import {getExceptionSource} from '../../utils/node-utils' -import {getBasePath, normalizeFilePath} from '../../utils/path-utils' -import {MochaJson, MochaJsonTest} from './mocha-json-types' +} from '../../test-results.js' +import {getExceptionSource} from '../../utils/node-utils.js' +import {getBasePath, normalizeFilePath} from '../../utils/path-utils.js' +import {MochaJson, MochaJsonTest} from './mocha-json-types.js' export class MochaJsonParser implements TestParser { assumedWorkDir: string | undefined diff --git a/src/parsers/phpunit-junit/phpunit-junit-parser.ts b/src/parsers/phpunit-junit/phpunit-junit-parser.ts index 65cb591..63a8db5 100644 --- a/src/parsers/phpunit-junit/phpunit-junit-parser.ts +++ b/src/parsers/phpunit-junit/phpunit-junit-parser.ts @@ -1,8 +1,8 @@ -import {ParseOptions, TestParser} from '../../test-parser' +import {ParseOptions, TestParser} from '../../test-parser.js' import {parseStringPromise} from 'xml2js' -import {PhpunitReport, SingleSuiteReport, TestCase, TestSuite} from './phpunit-junit-types' -import {getBasePath, normalizeFilePath} from '../../utils/path-utils' +import {PhpunitReport, SingleSuiteReport, TestCase, TestSuite} from './phpunit-junit-types.js' +import {getBasePath, normalizeFilePath} from '../../utils/path-utils.js' import { TestExecutionResult, @@ -11,7 +11,7 @@ import { TestGroupResult, TestCaseResult, TestCaseError -} from '../../test-results' +} from '../../test-results.js' export class PhpunitJunitParser implements TestParser { readonly trackedFiles: Set diff --git a/src/parsers/python-xunit/python-xunit-parser.ts b/src/parsers/python-xunit/python-xunit-parser.ts index 6902d71..17c9aff 100644 --- a/src/parsers/python-xunit/python-xunit-parser.ts +++ b/src/parsers/python-xunit/python-xunit-parser.ts @@ -1,5 +1,5 @@ -import {ParseOptions} from '../../test-parser' -import {JavaJunitParser} from '../java-junit/java-junit-parser' +import {ParseOptions} from '../../test-parser.js' +import {JavaJunitParser} from '../java-junit/java-junit-parser.js' export class PythonXunitParser extends JavaJunitParser { constructor(readonly options: ParseOptions) { diff --git a/src/parsers/rspec-json/rspec-json-parser.ts b/src/parsers/rspec-json/rspec-json-parser.ts index 0bc2efe..81acfa5 100644 --- a/src/parsers/rspec-json/rspec-json-parser.ts +++ b/src/parsers/rspec-json/rspec-json-parser.ts @@ -1,4 +1,4 @@ -import {ParseOptions, TestParser} from '../../test-parser' +import {ParseOptions, TestParser} from '../../test-parser.js' import { TestCaseError, TestCaseResult, @@ -6,8 +6,8 @@ import { TestGroupResult, TestRunResult, TestSuiteResult -} from '../../test-results' -import {RspecJson, RspecExample} from './rspec-json-types' +} from '../../test-results.js' +import {RspecJson, RspecExample} from './rspec-json-types.js' export class RspecJsonParser implements TestParser { assumedWorkDir: string | undefined diff --git a/src/parsers/swift-xunit/swift-xunit-parser.ts b/src/parsers/swift-xunit/swift-xunit-parser.ts index 8a96b73..a5c1f69 100644 --- a/src/parsers/swift-xunit/swift-xunit-parser.ts +++ b/src/parsers/swift-xunit/swift-xunit-parser.ts @@ -1,5 +1,5 @@ -import {ParseOptions} from '../../test-parser' -import {JavaJunitParser} from '../java-junit/java-junit-parser' +import {ParseOptions} from '../../test-parser.js' +import {JavaJunitParser} from '../java-junit/java-junit-parser.js' export class SwiftXunitParser extends JavaJunitParser { constructor(readonly options: ParseOptions) { diff --git a/src/parsers/tester-junit/tester-junit-parser.ts b/src/parsers/tester-junit/tester-junit-parser.ts index 1ac94a0..b4b97e0 100644 --- a/src/parsers/tester-junit/tester-junit-parser.ts +++ b/src/parsers/tester-junit/tester-junit-parser.ts @@ -1,9 +1,9 @@ import * as path from 'path' -import {ParseOptions, TestParser} from '../../test-parser' +import {ParseOptions, TestParser} from '../../test-parser.js' import {parseStringPromise} from 'xml2js' -import {NetteTesterReport, SingleSuiteReport, TestCase, TestSuite} from './tester-junit-types' -import {normalizeFilePath} from '../../utils/path-utils' +import {NetteTesterReport, SingleSuiteReport, TestCase, TestSuite} from './tester-junit-types.js' +import {normalizeFilePath} from '../../utils/path-utils.js' import { TestExecutionResult, @@ -12,7 +12,7 @@ import { TestGroupResult, TestCaseResult, TestCaseError -} from '../../test-results' +} from '../../test-results.js' interface ParsedTestName { filePath: string diff --git a/src/report/get-annotations.ts b/src/report/get-annotations.ts index 1b3e8aa..b7e1ca6 100644 --- a/src/report/get-annotations.ts +++ b/src/report/get-annotations.ts @@ -1,6 +1,6 @@ -import {ellipsis, fixEol} from '../utils/markdown-utils' -import {TestRunResult} from '../test-results' -import {getFirstNonEmptyLine} from '../utils/parse-utils' +import {ellipsis, fixEol} from '../utils/markdown-utils.js' +import {TestRunResult} from '../test-results.js' +import {getFirstNonEmptyLine} from '../utils/parse-utils.js' type Annotation = { path: string diff --git a/src/report/get-report.ts b/src/report/get-report.ts index 02b9d49..63617b0 100644 --- a/src/report/get-report.ts +++ b/src/report/get-report.ts @@ -1,9 +1,9 @@ import * as core from '@actions/core' -import {TestExecutionResult, TestRunResult, TestSuiteResult} from '../test-results' -import {Align, formatTime, Icon, link, table} from '../utils/markdown-utils' -import {DEFAULT_LOCALE} from '../utils/node-utils' -import {getFirstNonEmptyLine} from '../utils/parse-utils' -import {slug} from '../utils/slugger' +import {TestExecutionResult, TestRunResult, TestSuiteResult} from '../test-results.js' +import {Align, formatTime, Icon, link, table} from '../utils/markdown-utils.js' +import {DEFAULT_LOCALE} from '../utils/node-utils.js' +import {getFirstNonEmptyLine} from '../utils/parse-utils.js' +import {slug} from '../utils/slugger.js' const MAX_REPORT_LENGTH = 65535 const MAX_ACTIONS_SUMMARY_LENGTH = 1048576 diff --git a/src/test-parser.ts b/src/test-parser.ts index f134561..e3af2c0 100644 --- a/src/test-parser.ts +++ b/src/test-parser.ts @@ -1,4 +1,4 @@ -import {TestRunResult} from './test-results' +import {TestRunResult} from './test-results.js' export interface ParseOptions { parseErrors: boolean diff --git a/src/test-results.ts b/src/test-results.ts index bca8c41..efeee78 100644 --- a/src/test-results.ts +++ b/src/test-results.ts @@ -1,4 +1,4 @@ -import {DEFAULT_LOCALE} from './utils/node-utils' +import {DEFAULT_LOCALE} from './utils/node-utils.js' export class TestRunResult { constructor( diff --git a/src/utils/github-utils.ts b/src/utils/github-utils.ts index d1539d9..74b2d51 100644 --- a/src/utils/github-utils.ts +++ b/src/utils/github-utils.ts @@ -3,7 +3,7 @@ import {pipeline} from 'stream/promises' import {Readable, Transform} from 'stream' import * as core from '@actions/core' import * as github from '@actions/github' -import {GitHub} from '@actions/github/lib/utils' +import {GitHub} from '@actions/github/lib/utils.js' import type {PullRequest, WorkflowRunEvent} from '@octokit/webhooks-types' export function getCheckRunContext(): {sha: string; runId: number} { diff --git a/src/utils/node-utils.ts b/src/utils/node-utils.ts index c3b33fc..071198b 100644 --- a/src/utils/node-utils.ts +++ b/src/utils/node-utils.ts @@ -1,4 +1,4 @@ -import {normalizeFilePath} from './path-utils' +import {normalizeFilePath} from './path-utils.js' export const DEFAULT_LOCALE = 'en-US' diff --git a/src/utils/slugger.ts b/src/utils/slugger.ts index 1f3c956..656a81b 100644 --- a/src/utils/slugger.ts +++ b/src/utils/slugger.ts @@ -1,7 +1,7 @@ // Returns HTML element id and href link usable as manual anchor links // This is needed because Github in check run summary doesn't automatically // create links out of headings as it normally does for other markdown content -import {ReportOptions} from '../report/get-report' +import {ReportOptions} from '../report/get-report.js' export function slug(name: string, options: ReportOptions): {id: string; link: string} { const slugId = name