From f83cb3a5339b2973545a9bf4ee660c74a5b42cec Mon Sep 17 00:00:00 2001 From: Benny Powers Date: Mon, 1 Jun 2026 21:33:35 +0300 Subject: [PATCH 1/2] refactor(test-runner-junit-reporter): migrate tests to node:test Replace mocha globals and chai assertions with node:test and node:assert/strict. Rename `test` to `test:node`. - `import type { TestRunnerCoreConfig }` (type-only) - `../src/junitReporter.js` -> `../dist/junitReporter.js` - `__dirname` -> `import.meta.dirname` - `expect(actual).to.equal(expected)` -> `assert.equal(actual, expected)` - `function()` -> arrow functions - Add `--experimental-strip-types` for CI compat Assisted-By: Claude Opus 4.6 (1M context) --- .../test-runner-junit-reporter/package.json | 4 +- .../test/junitReporter.test.ts | 37 ++++++++++--------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/packages/test-runner-junit-reporter/package.json b/packages/test-runner-junit-reporter/package.json index 266337955e..1e59d64b24 100644 --- a/packages/test-runner-junit-reporter/package.json +++ b/packages/test-runner-junit-reporter/package.json @@ -26,8 +26,8 @@ }, "scripts": { "build": "tsc", - "test": "mocha test/**/*.test.ts --require ts-node/register --reporter dot", - "test:watch": "mocha test/**/*.test.ts --require ts-node/register --watch --watch-files src,test --reporter dot" + "test:node": "node --experimental-strip-types --test --test-force-exit test/**/*.test.ts", + "test:watch": "node --experimental-strip-types --test --test-force-exit --watch test/**/*.test.ts" }, "files": [ "*.d.ts", diff --git a/packages/test-runner-junit-reporter/test/junitReporter.test.ts b/packages/test-runner-junit-reporter/test/junitReporter.test.ts index 79e63fed3e..82afbfa493 100644 --- a/packages/test-runner-junit-reporter/test/junitReporter.test.ts +++ b/packages/test-runner-junit-reporter/test/junitReporter.test.ts @@ -1,18 +1,19 @@ -import { expect } from 'chai'; +import { describe, it, after } from 'node:test'; +import assert from 'node:assert/strict'; import { promises as fs } from 'fs'; import path from 'path'; import globby from 'globby'; import { chromeLauncher } from '@web/test-runner-chrome'; -import { TestRunnerCoreConfig } from '@web/test-runner-core'; +import type { TestRunnerCoreConfig } from '@web/test-runner-core'; import { runTests } from '@web/test-runner-core/test-helpers'; -import { junitReporter } from '../src/junitReporter.js'; +import { junitReporter } from '../dist/junitReporter.js'; const NON_ZERO_TIME_VALUE_REGEX = /time="((\d\.\d+)|(\d))"/g; const USER_AGENT_STRING_REGEX = /"Mozilla\/5\.0 (.*)"/g; -const rootDir = path.join(__dirname, '..', '..', '..'); +const rootDir = path.join(import.meta.dirname, '..', '..', '..'); const normalizeOutput = (cwd: string, output: string) => output @@ -64,35 +65,35 @@ async function run(cwd: string): Promise<{ actual: string; expected: string }> { async function cleanupFixtures() { for (const file of await globby('fixtures/**/test-results.xml', { absolute: true, - cwd: __dirname, + cwd: import.meta.dirname, })) await fs.unlink(file); } -describe('junitReporter', function () { +describe('junitReporter', () => { after(cleanupFixtures); - describe('for a simple case', function () { - const fixtureDir = path.join(__dirname, 'fixtures/simple'); - it('produces expected results', async function () { + describe('for a simple case', () => { + const fixtureDir = path.join(import.meta.dirname, 'fixtures/simple'); + it('produces expected results', async () => { const { actual, expected } = await run(fixtureDir); - expect(actual).to.equal(expected); + assert.equal(actual, expected); }); }); - describe('for a nested suite', function () { - const fixtureDir = path.join(__dirname, 'fixtures/nested'); - it('produces expected results', async function () { + describe('for a nested suite', () => { + const fixtureDir = path.join(import.meta.dirname, 'fixtures/nested'); + it('produces expected results', async () => { const { actual, expected } = await run(fixtureDir); - expect(actual).to.equal(expected); + assert.equal(actual, expected); }); }); - describe('for multiple test files', function () { - const fixtureDir = path.join(__dirname, 'fixtures/multiple'); - it('produces expected results', async function () { + describe('for multiple test files', () => { + const fixtureDir = path.join(import.meta.dirname, 'fixtures/multiple'); + it('produces expected results', async () => { const { actual, expected } = await run(fixtureDir); - expect(actual).to.equal(expected); + assert.equal(actual, expected); }); }); }); From 79b93df39b6facf76fa25e9e512726bb7e238140 Mon Sep 17 00:00:00 2001 From: Benny Powers Date: Tue, 2 Jun 2026 09:55:21 +0300 Subject: [PATCH 2/2] fix(test-runner-junit-reporter): update XML snapshots for workspace cwd npm workspaces run test scripts from the package directory, not the repo root. The test runner computes file paths relative to cwd, so XML output paths are now relative to the package root (test/fixtures/...) instead of the repo root (packages/test-runner-junit-reporter/test/...). Updated expected XML snapshots to match. Assisted-By: Claude Opus 4.6 (1M context) --- .../test/fixtures/multiple/expected.xml | 22 +++++++++---------- .../test/fixtures/nested/expected.xml | 6 ++--- .../test/fixtures/simple/expected.xml | 22 +++++++++---------- .../test/junitReporter.test.ts | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/test-runner-junit-reporter/test/fixtures/multiple/expected.xml b/packages/test-runner-junit-reporter/test/fixtures/multiple/expected.xml index 13af3840be..560e5fc9df 100644 --- a/packages/test-runner-junit-reporter/test/fixtures/multiple/expected.xml +++ b/packages/test-runner-junit-reporter/test/fixtures/multiple/expected.xml @@ -1,28 +1,28 @@ - + - + - + - + - + - - - + + + > (packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js:15:29)]]> + at <> (test/fixtures/multiple/simple-test.js:15:29)]]> - + - + \ No newline at end of file diff --git a/packages/test-runner-junit-reporter/test/fixtures/nested/expected.xml b/packages/test-runner-junit-reporter/test/fixtures/nested/expected.xml index d1383961ef..fe103402e3 100644 --- a/packages/test-runner-junit-reporter/test/fixtures/nested/expected.xml +++ b/packages/test-runner-junit-reporter/test/fixtures/nested/expected.xml @@ -1,11 +1,11 @@ - + - + - + \ No newline at end of file diff --git a/packages/test-runner-junit-reporter/test/fixtures/simple/expected.xml b/packages/test-runner-junit-reporter/test/fixtures/simple/expected.xml index 93eb434893..4386a40677 100644 --- a/packages/test-runner-junit-reporter/test/fixtures/simple/expected.xml +++ b/packages/test-runner-junit-reporter/test/fixtures/simple/expected.xml @@ -1,25 +1,25 @@ - + - + - - - + + + > (packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js:17:29)]]> + at <> (test/fixtures/simple/simple-test.js:17:29)]]> - + - - + + > (packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js:33:17)]]> + at fail (test/fixtures/simple/simple-source.js:2:9) + at <> (test/fixtures/simple/simple-test.js:33:17)]]> \ No newline at end of file diff --git a/packages/test-runner-junit-reporter/test/junitReporter.test.ts b/packages/test-runner-junit-reporter/test/junitReporter.test.ts index 82afbfa493..7c04c05f4f 100644 --- a/packages/test-runner-junit-reporter/test/junitReporter.test.ts +++ b/packages/test-runner-junit-reporter/test/junitReporter.test.ts @@ -13,7 +13,7 @@ const NON_ZERO_TIME_VALUE_REGEX = /time="((\d\.\d+)|(\d))"/g; const USER_AGENT_STRING_REGEX = /"Mozilla\/5\.0 (.*)"/g; -const rootDir = path.join(import.meta.dirname, '..', '..', '..'); +const rootDir = path.resolve(import.meta.dirname, '..', '..', '..'); const normalizeOutput = (cwd: string, output: string) => output