Skip to content

Commit f83cb3a

Browse files
committed
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) <noreply@anthropic.com>
1 parent 597fb32 commit f83cb3a

2 files changed

Lines changed: 21 additions & 20 deletions

File tree

packages/test-runner-junit-reporter/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
},
2727
"scripts": {
2828
"build": "tsc",
29-
"test": "mocha test/**/*.test.ts --require ts-node/register --reporter dot",
30-
"test:watch": "mocha test/**/*.test.ts --require ts-node/register --watch --watch-files src,test --reporter dot"
29+
"test:node": "node --experimental-strip-types --test --test-force-exit test/**/*.test.ts",
30+
"test:watch": "node --experimental-strip-types --test --test-force-exit --watch test/**/*.test.ts"
3131
},
3232
"files": [
3333
"*.d.ts",

packages/test-runner-junit-reporter/test/junitReporter.test.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import { expect } from 'chai';
1+
import { describe, it, after } from 'node:test';
2+
import assert from 'node:assert/strict';
23
import { promises as fs } from 'fs';
34
import path from 'path';
45
import globby from 'globby';
56

67
import { chromeLauncher } from '@web/test-runner-chrome';
7-
import { TestRunnerCoreConfig } from '@web/test-runner-core';
8+
import type { TestRunnerCoreConfig } from '@web/test-runner-core';
89
import { runTests } from '@web/test-runner-core/test-helpers';
9-
import { junitReporter } from '../src/junitReporter.js';
10+
import { junitReporter } from '../dist/junitReporter.js';
1011

1112
const NON_ZERO_TIME_VALUE_REGEX = /time="((\d\.\d+)|(\d))"/g;
1213

1314
const USER_AGENT_STRING_REGEX = /"Mozilla\/5\.0 (.*)"/g;
1415

15-
const rootDir = path.join(__dirname, '..', '..', '..');
16+
const rootDir = path.join(import.meta.dirname, '..', '..', '..');
1617

1718
const normalizeOutput = (cwd: string, output: string) =>
1819
output
@@ -64,35 +65,35 @@ async function run(cwd: string): Promise<{ actual: string; expected: string }> {
6465
async function cleanupFixtures() {
6566
for (const file of await globby('fixtures/**/test-results.xml', {
6667
absolute: true,
67-
cwd: __dirname,
68+
cwd: import.meta.dirname,
6869
}))
6970
await fs.unlink(file);
7071
}
7172

72-
describe('junitReporter', function () {
73+
describe('junitReporter', () => {
7374
after(cleanupFixtures);
7475

75-
describe('for a simple case', function () {
76-
const fixtureDir = path.join(__dirname, 'fixtures/simple');
77-
it('produces expected results', async function () {
76+
describe('for a simple case', () => {
77+
const fixtureDir = path.join(import.meta.dirname, 'fixtures/simple');
78+
it('produces expected results', async () => {
7879
const { actual, expected } = await run(fixtureDir);
79-
expect(actual).to.equal(expected);
80+
assert.equal(actual, expected);
8081
});
8182
});
8283

83-
describe('for a nested suite', function () {
84-
const fixtureDir = path.join(__dirname, 'fixtures/nested');
85-
it('produces expected results', async function () {
84+
describe('for a nested suite', () => {
85+
const fixtureDir = path.join(import.meta.dirname, 'fixtures/nested');
86+
it('produces expected results', async () => {
8687
const { actual, expected } = await run(fixtureDir);
87-
expect(actual).to.equal(expected);
88+
assert.equal(actual, expected);
8889
});
8990
});
9091

91-
describe('for multiple test files', function () {
92-
const fixtureDir = path.join(__dirname, 'fixtures/multiple');
93-
it('produces expected results', async function () {
92+
describe('for multiple test files', () => {
93+
const fixtureDir = path.join(import.meta.dirname, 'fixtures/multiple');
94+
it('produces expected results', async () => {
9495
const { actual, expected } = await run(fixtureDir);
95-
expect(actual).to.equal(expected);
96+
assert.equal(actual, expected);
9697
});
9798
});
9899
});

0 commit comments

Comments
 (0)