From 4d6f6ca5f42f8dcde39e05ca12a0bba9f1b3f2ec Mon Sep 17 00:00:00 2001 From: Jozef Izso Date: Mon, 2 Mar 2026 14:29:31 +0100 Subject: [PATCH] Refactor tests to modedules based package --- __tests__/dart-json.test.ts | 13 +++++++++---- __tests__/dotnet-nunit.test.ts | 13 +++++++++---- __tests__/dotnet-trx.test.ts | 13 +++++++++---- __tests__/golang-json.test.ts | 13 +++++++++---- __tests__/java-junit.test.ts | 13 +++++++++---- __tests__/java-stack-trace-element-parser.test.ts | 2 +- __tests__/jest-junit.test.ts | 13 +++++++++---- __tests__/mocha-json.test.ts | 13 +++++++++---- __tests__/phpunit-junit.test.ts | 13 +++++++++---- __tests__/python-xunit.test.ts | 13 +++++++++---- __tests__/report/get-report.test.ts | 2 +- __tests__/rspec-json.test.ts | 13 +++++++++---- __tests__/swift-xunit.test.ts | 13 +++++++++---- __tests__/tester-junit.test.ts | 13 +++++++++---- __tests__/utils/parse-utils.test.ts | 2 +- jest.config.js => jest.config.cjs | 9 ++++++--- package.json | 2 +- tsconfig.json | 2 +- 18 files changed, 119 insertions(+), 56 deletions(-) rename jest.config.js => jest.config.cjs (54%) diff --git a/__tests__/dart-json.test.ts b/__tests__/dart-json.test.ts index 12b664b..c272cf4 100644 --- a/__tests__/dart-json.test.ts +++ b/__tests__/dart-json.test.ts @@ -1,10 +1,15 @@ import * as fs from 'fs' import * as path from 'path' -import {DartJsonParser} from '../src/parsers/dart-json/dart-json-parser' -import {ParseOptions} from '../src/test-parser' -import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report' -import {normalizeFilePath} from '../src/utils/path-utils' +import {DartJsonParser} from '../src/parsers/dart-json/dart-json-parser.js' +import {ParseOptions} from '../src/test-parser.js' +import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report.js' +import {normalizeFilePath} from '../src/utils/path-utils.js' + +import {fileURLToPath} from 'url' +import {dirname} from 'path' +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) describe('dart-json tests', () => { it('produces empty test run result when there are no test cases', async () => { diff --git a/__tests__/dotnet-nunit.test.ts b/__tests__/dotnet-nunit.test.ts index 6903c5a..ea170b5 100644 --- a/__tests__/dotnet-nunit.test.ts +++ b/__tests__/dotnet-nunit.test.ts @@ -1,10 +1,15 @@ import * as fs from 'fs' import * as path from 'path' -import {DotnetNunitParser} from '../src/parsers/dotnet-nunit/dotnet-nunit-parser' -import {ParseOptions} from '../src/test-parser' -import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report' -import {normalizeFilePath} from '../src/utils/path-utils' +import {DotnetNunitParser} from '../src/parsers/dotnet-nunit/dotnet-nunit-parser.js' +import {ParseOptions} from '../src/test-parser.js' +import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report.js' +import {normalizeFilePath} from '../src/utils/path-utils.js' + +import {fileURLToPath} from 'url' +import {dirname} from 'path' +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) describe('dotnet-nunit tests', () => { it('report from ./reports/dotnet test results matches snapshot', async () => { diff --git a/__tests__/dotnet-trx.test.ts b/__tests__/dotnet-trx.test.ts index a7aead6..08c5bfa 100644 --- a/__tests__/dotnet-trx.test.ts +++ b/__tests__/dotnet-trx.test.ts @@ -1,10 +1,15 @@ import * as fs from 'fs' import * as path from 'path' -import {DotnetTrxParser} from '../src/parsers/dotnet-trx/dotnet-trx-parser' -import {ParseOptions} from '../src/test-parser' -import {DEFAULT_OPTIONS, getReport, ReportOptions} from '../src/report/get-report' -import {normalizeFilePath} from '../src/utils/path-utils' +import {DotnetTrxParser} from '../src/parsers/dotnet-trx/dotnet-trx-parser.js' +import {ParseOptions} from '../src/test-parser.js' +import {DEFAULT_OPTIONS, getReport, ReportOptions} from '../src/report/get-report.js' +import {normalizeFilePath} from '../src/utils/path-utils.js' + +import {fileURLToPath} from 'url' +import {dirname} from 'path' +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) describe('dotnet-trx tests', () => { it('produces empty test run result when there are no test cases', async () => { diff --git a/__tests__/golang-json.test.ts b/__tests__/golang-json.test.ts index 0bfdd86..0672d03 100644 --- a/__tests__/golang-json.test.ts +++ b/__tests__/golang-json.test.ts @@ -1,10 +1,15 @@ import * as fs from 'fs' import * as path from 'path' -import {GolangJsonParser} from '../src/parsers/golang-json/golang-json-parser' -import {ParseOptions} from '../src/test-parser' -import {getReport} from '../src/report/get-report' -import {normalizeFilePath} from '../src/utils/path-utils' +import {GolangJsonParser} from '../src/parsers/golang-json/golang-json-parser.js' +import {ParseOptions} from '../src/test-parser.js' +import {getReport} from '../src/report/get-report.js' +import {normalizeFilePath} from '../src/utils/path-utils.js' + +import {fileURLToPath} from 'url' +import {dirname} from 'path' +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) describe('golang-json tests', () => { it('report from ./reports/dotnet test results matches snapshot', async () => { diff --git a/__tests__/java-junit.test.ts b/__tests__/java-junit.test.ts index 8f8c7ae..540e2b2 100644 --- a/__tests__/java-junit.test.ts +++ b/__tests__/java-junit.test.ts @@ -1,10 +1,15 @@ import * as fs from 'fs' import * as path from 'path' -import {JavaJunitParser} from '../src/parsers/java-junit/java-junit-parser' -import {ParseOptions} from '../src/test-parser' -import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report' -import {normalizeFilePath} from '../src/utils/path-utils' +import {JavaJunitParser} from '../src/parsers/java-junit/java-junit-parser.js' +import {ParseOptions} from '../src/test-parser.js' +import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report.js' +import {normalizeFilePath} from '../src/utils/path-utils.js' + +import {fileURLToPath} from 'url' +import {dirname} from 'path' +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) describe('java-junit tests', () => { it('produces empty test run result when there are no test cases', async () => { diff --git a/__tests__/java-stack-trace-element-parser.test.ts b/__tests__/java-stack-trace-element-parser.test.ts index 6fe1ac2..ff98a03 100644 --- a/__tests__/java-stack-trace-element-parser.test.ts +++ b/__tests__/java-stack-trace-element-parser.test.ts @@ -1,4 +1,4 @@ -import {parseStackTraceElement} from '../src/parsers/java-junit/java-stack-trace-element-parser' +import {parseStackTraceElement} from '../src/parsers/java-junit/java-stack-trace-element-parser.js' describe('parseStackTraceLine tests', () => { it('empty line is not parsed', async () => { diff --git a/__tests__/jest-junit.test.ts b/__tests__/jest-junit.test.ts index 912ebde..50f225d 100644 --- a/__tests__/jest-junit.test.ts +++ b/__tests__/jest-junit.test.ts @@ -1,10 +1,15 @@ import * as fs from 'fs' import * as path from 'path' -import {JestJunitParser} from '../src/parsers/jest-junit/jest-junit-parser' -import {ParseOptions} from '../src/test-parser' -import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report' -import {normalizeFilePath} from '../src/utils/path-utils' +import {JestJunitParser} from '../src/parsers/jest-junit/jest-junit-parser.js' +import {ParseOptions} from '../src/test-parser.js' +import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report.js' +import {normalizeFilePath} from '../src/utils/path-utils.js' + +import {fileURLToPath} from 'url' +import {dirname} from 'path' +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) describe('jest-junit tests', () => { it('produces empty test run result when there are no test cases in the testsuites element', async () => { diff --git a/__tests__/mocha-json.test.ts b/__tests__/mocha-json.test.ts index 1272962..b2379cb 100644 --- a/__tests__/mocha-json.test.ts +++ b/__tests__/mocha-json.test.ts @@ -1,10 +1,15 @@ import * as fs from 'fs' import * as path from 'path' -import {MochaJsonParser} from '../src/parsers/mocha-json/mocha-json-parser' -import {ParseOptions} from '../src/test-parser' -import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report' -import {normalizeFilePath} from '../src/utils/path-utils' +import {MochaJsonParser} from '../src/parsers/mocha-json/mocha-json-parser.js' +import {ParseOptions} from '../src/test-parser.js' +import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report.js' +import {normalizeFilePath} from '../src/utils/path-utils.js' + +import {fileURLToPath} from 'url' +import {dirname} from 'path' +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) describe('mocha-json tests', () => { it('produces empty test run result when there are no test cases', async () => { diff --git a/__tests__/phpunit-junit.test.ts b/__tests__/phpunit-junit.test.ts index 8075208..20986d6 100644 --- a/__tests__/phpunit-junit.test.ts +++ b/__tests__/phpunit-junit.test.ts @@ -1,10 +1,15 @@ import * as fs from 'fs' import * as path from 'path' -import {PhpunitJunitParser} from '../src/parsers/phpunit-junit/phpunit-junit-parser' -import {ParseOptions} from '../src/test-parser' -import {getReport} from '../src/report/get-report' -import {normalizeFilePath} from '../src/utils/path-utils' +import {PhpunitJunitParser} from '../src/parsers/phpunit-junit/phpunit-junit-parser.js' +import {ParseOptions} from '../src/test-parser.js' +import {getReport} from '../src/report/get-report.js' +import {normalizeFilePath} from '../src/utils/path-utils.js' + +import {fileURLToPath} from 'url' +import {dirname} from 'path' +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) describe('phpunit-junit tests', () => { it('produces empty test run result when there are no test cases', async () => { diff --git a/__tests__/python-xunit.test.ts b/__tests__/python-xunit.test.ts index c1550a4..4e8cef3 100644 --- a/__tests__/python-xunit.test.ts +++ b/__tests__/python-xunit.test.ts @@ -1,10 +1,15 @@ import * as fs from 'fs' import * as path from 'path' -import {PythonXunitParser} from '../src/parsers/python-xunit/python-xunit-parser' -import {ParseOptions} from '../src/test-parser' -import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report' -import {normalizeFilePath} from '../src/utils/path-utils' +import {PythonXunitParser} from '../src/parsers/python-xunit/python-xunit-parser.js' +import {ParseOptions} from '../src/test-parser.js' +import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report.js' +import {normalizeFilePath} from '../src/utils/path-utils.js' + +import {fileURLToPath} from 'url' +import {dirname} from 'path' +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) const defaultOpts: ParseOptions = { parseErrors: true, diff --git a/__tests__/report/get-report.test.ts b/__tests__/report/get-report.test.ts index 670b0ad..bc4a8b4 100644 --- a/__tests__/report/get-report.test.ts +++ b/__tests__/report/get-report.test.ts @@ -1,4 +1,4 @@ -import {getBadge, DEFAULT_OPTIONS, ReportOptions} from '../../src/report/get-report' +import {getBadge, DEFAULT_OPTIONS, ReportOptions} from '../../src/report/get-report.js' describe('getBadge', () => { describe('URI encoding with special characters', () => { diff --git a/__tests__/rspec-json.test.ts b/__tests__/rspec-json.test.ts index 787420b..e37ef09 100644 --- a/__tests__/rspec-json.test.ts +++ b/__tests__/rspec-json.test.ts @@ -1,10 +1,15 @@ import * as fs from 'fs' import * as path from 'path' -import {RspecJsonParser} from '../src/parsers/rspec-json/rspec-json-parser' -import {ParseOptions} from '../src/test-parser' -import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report' -import {normalizeFilePath} from '../src/utils/path-utils' +import {RspecJsonParser} from '../src/parsers/rspec-json/rspec-json-parser.js' +import {ParseOptions} from '../src/test-parser.js' +import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report.js' +import {normalizeFilePath} from '../src/utils/path-utils.js' + +import {fileURLToPath} from 'url' +import {dirname} from 'path' +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) describe('rspec-json tests', () => { it('produces empty test run result when there are no test cases', async () => { diff --git a/__tests__/swift-xunit.test.ts b/__tests__/swift-xunit.test.ts index 9f063ee..c46b695 100644 --- a/__tests__/swift-xunit.test.ts +++ b/__tests__/swift-xunit.test.ts @@ -1,10 +1,15 @@ import * as fs from 'fs' import * as path from 'path' -import {SwiftXunitParser} from '../src/parsers/swift-xunit/swift-xunit-parser' -import {ParseOptions} from '../src/test-parser' -import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report' -import {normalizeFilePath} from '../src/utils/path-utils' +import {SwiftXunitParser} from '../src/parsers/swift-xunit/swift-xunit-parser.js' +import {ParseOptions} from '../src/test-parser.js' +import {DEFAULT_OPTIONS, getReport} from '../src/report/get-report.js' +import {normalizeFilePath} from '../src/utils/path-utils.js' + +import {fileURLToPath} from 'url' +import {dirname} from 'path' +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) describe('swift-xunit tests', () => { it('report from swift test results matches snapshot', async () => { diff --git a/__tests__/tester-junit.test.ts b/__tests__/tester-junit.test.ts index 86f564d..2743365 100644 --- a/__tests__/tester-junit.test.ts +++ b/__tests__/tester-junit.test.ts @@ -1,10 +1,15 @@ import * as fs from 'fs' import * as path from 'path' -import {NetteTesterJunitParser} from '../src/parsers/tester-junit/tester-junit-parser' -import {ParseOptions} from '../src/test-parser' -import {getReport} from '../src/report/get-report' -import {normalizeFilePath} from '../src/utils/path-utils' +import {NetteTesterJunitParser} from '../src/parsers/tester-junit/tester-junit-parser.js' +import {ParseOptions} from '../src/test-parser.js' +import {getReport} from '../src/report/get-report.js' +import {normalizeFilePath} from '../src/utils/path-utils.js' + +import {fileURLToPath} from 'url' +import {dirname} from 'path' +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) describe('tester-junit tests', () => { it('produces empty test run result when there are no test cases', async () => { diff --git a/__tests__/utils/parse-utils.test.ts b/__tests__/utils/parse-utils.test.ts index 0f02867..dd21ee5 100644 --- a/__tests__/utils/parse-utils.test.ts +++ b/__tests__/utils/parse-utils.test.ts @@ -1,4 +1,4 @@ -import {parseNetDuration} from '../../src/utils/parse-utils' +import {parseNetDuration} from '../../src/utils/parse-utils.js' describe('parseNetDuration', () => { it('returns 0 for 00:00:00', () => { diff --git a/jest.config.js b/jest.config.cjs similarity index 54% rename from jest.config.js rename to jest.config.cjs index 563d4cc..2562c2c 100644 --- a/jest.config.js +++ b/jest.config.cjs @@ -3,9 +3,12 @@ module.exports = { moduleFileExtensions: ['js', 'ts'], testEnvironment: 'node', testMatch: ['**/*.test.ts'], - testRunner: 'jest-circus/runner', transform: { - '^.+\\.ts$': 'ts-jest' + '^.+\\.ts$': ['ts-jest', {useESM: true}] }, + moduleNameMapper: { + '^(\\.{1,2}/.*)\\.js$': '$1' + }, + extensionsToTreatAsEsm: ['.ts'], verbose: true -} \ No newline at end of file +} diff --git a/package.json b/package.json index edbc634..3e05e14 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "lint": "eslint src/**/*.ts", "package": "ncc build --license licenses.txt && eolConverter lf 'dist/*'", "version": "npm run build && npm run package && git add dist/*", - "test": "jest --ci --reporters=default --reporters=jest-junit", + "test": "NODE_OPTIONS='--experimental-vm-modules' jest --ci --reporters=default --reporters=jest-junit", "jest:updatesnapshot": "jest --updateSnapshot", "all": "npm run build && npm run format && npm run lint && npm run package && npm test", "dart-fixture": "cd \"reports/dart\" && dart test --file-reporter=\"json:../../__tests__/fixtures/dart-json.json\"", diff --git a/tsconfig.json b/tsconfig.json index 6e71576..5cb78aa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ "strict": true, "esModuleInterop": true, "skipLibCheck": true, - "moduleResolution": "node16", + "moduleResolution": "nodenext", "isolatedModules": true, "outDir": "./lib",