Skip to content

Commit 8b9450d

Browse files
authored
Merge pull request #3091 from modernweb-dev/migrate/test-runner-junit-reporter-node-test
refactor(test-runner-junit-reporter): migrate tests to node:test
2 parents 8d0c4d7 + 79d1cd6 commit 8b9450d

5 files changed

Lines changed: 46 additions & 45 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",
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<testsuites>
3-
<testsuite name="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/nested-test.js" id="0" tests="1" skipped="0" errors="0" failures="0" time="<<computed>>">
3+
<testsuite name="Chrome_puppeteer_/test/fixtures/multiple/nested-test.js" id="0" tests="1" skipped="0" errors="0" failures="0" time="<<computed>>">
44
<properties>
5-
<property name="test.fileName" value="packages/test-runner-junit-reporter/test/fixtures/multiple/nested-test.js"/>
5+
<property name="test.fileName" value="test/fixtures/multiple/nested-test.js"/>
66
<property name="browser.name" value="Chrome"/>
77
<property name="browser.launcher" value="puppeteer"/>
88
</properties>
9-
<testcase name="is equivalent to map (f.g) f a" time="<<computed>>" classname="given a functor f and a function a -&gt; b map f map g f a" file="packages/test-runner-junit-reporter/test/fixtures/multiple/nested-test.js"/>
9+
<testcase name="is equivalent to map (f.g) f a" time="<<computed>>" classname="given a functor f and a function a -&gt; b map f map g f a" file="test/fixtures/multiple/nested-test.js"/>
1010
</testsuite>
11-
<testsuite name="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js" id="0" tests="5" skipped="1" errors="1" failures="1" time="<<computed>>">
11+
<testsuite name="Chrome_puppeteer_/test/fixtures/multiple/simple-test.js" id="0" tests="5" skipped="1" errors="1" failures="1" time="<<computed>>">
1212
<properties>
13-
<property name="test.fileName" value="packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js"/>
13+
<property name="test.fileName" value="test/fixtures/multiple/simple-test.js"/>
1414
<property name="browser.name" value="Chrome"/>
1515
<property name="browser.launcher" value="puppeteer"/>
1616
</properties>
17-
<testcase name="under addition" time="<<computed>>" classname="real numbers forming a monoid" file="packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js"/>
18-
<testcase name="null hypothesis" time="<<computed>>" classname="off-by-one boolean logic errors" file="packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js"/>
19-
<testcase name="asserts error" time="<<computed>>" classname="off-by-one boolean logic errors" file="packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js" line="15">
17+
<testcase name="under addition" time="<<computed>>" classname="real numbers forming a monoid" file="test/fixtures/multiple/simple-test.js"/>
18+
<testcase name="null hypothesis" time="<<computed>>" classname="off-by-one boolean logic errors" file="test/fixtures/multiple/simple-test.js"/>
19+
<testcase name="asserts error" time="<<computed>>" classname="off-by-one boolean logic errors" file="test/fixtures/multiple/simple-test.js" line="15">
2020
<failure message="expected false to be true" type="AssertionError"><![CDATA[AssertionError: expected false to be true
21-
at <<anonymous>> (packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js:15:29)]]></failure>
21+
at <<anonymous>> (test/fixtures/multiple/simple-test.js:15:29)]]></failure>
2222
</testcase>
23-
<testcase name="tbd: confirm true positive" time="<<computed>>" classname="off-by-one boolean logic errors" file="packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js">
23+
<testcase name="tbd: confirm true positive" time="<<computed>>" classname="off-by-one boolean logic errors" file="test/fixtures/multiple/simple-test.js">
2424
<skipped/>
2525
</testcase>
26-
<testcase name="reports logs to JUnit" time="<<computed>>" classname="logging during a test" file="packages/test-runner-junit-reporter/test/fixtures/multiple/simple-test.js"/>
26+
<testcase name="reports logs to JUnit" time="<<computed>>" classname="logging during a test" file="test/fixtures/multiple/simple-test.js"/>
2727
</testsuite>
2828
</testsuites>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<testsuites>
3-
<testsuite name="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/nested/nested-test.js" id="0" tests="1" skipped="0" errors="0" failures="0" time="<<computed>>">
3+
<testsuite name="Chrome_puppeteer_/test/fixtures/nested/nested-test.js" id="0" tests="1" skipped="0" errors="0" failures="0" time="<<computed>>">
44
<properties>
5-
<property name="test.fileName" value="packages/test-runner-junit-reporter/test/fixtures/nested/nested-test.js"/>
5+
<property name="test.fileName" value="test/fixtures/nested/nested-test.js"/>
66
<property name="browser.name" value="Chrome"/>
77
<property name="browser.launcher" value="puppeteer"/>
88
</properties>
9-
<testcase name="is equivalent to map (f.g) f a" time="<<computed>>" classname="given a functor f and a function a -&gt; b map f map g f a" file="packages/test-runner-junit-reporter/test/fixtures/nested/nested-test.js"/>
9+
<testcase name="is equivalent to map (f.g) f a" time="<<computed>>" classname="given a functor f and a function a -&gt; b map f map g f a" file="test/fixtures/nested/nested-test.js"/>
1010
</testsuite>
1111
</testsuites>
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<testsuites>
3-
<testsuite name="Chrome_puppeteer_/packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js" id="0" tests="6" skipped="1" errors="2" failures="2" time="<<computed>>">
3+
<testsuite name="Chrome_puppeteer_/test/fixtures/simple/simple-test.js" id="0" tests="6" skipped="1" errors="2" failures="2" time="<<computed>>">
44
<properties>
5-
<property name="test.fileName" value="packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js"/>
5+
<property name="test.fileName" value="test/fixtures/simple/simple-test.js"/>
66
<property name="browser.name" value="Chrome"/>
77
<property name="browser.launcher" value="puppeteer"/>
88
</properties>
9-
<testcase name="under addition" time="<<computed>>" classname="real numbers forming a monoid" file="packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js"/>
10-
<testcase name="null hypothesis" time="<<computed>>" classname="off-by-one boolean logic errors" file="packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js"/>
11-
<testcase name="asserts error" time="<<computed>>" classname="off-by-one boolean logic errors" file="packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js" line="17">
9+
<testcase name="under addition" time="<<computed>>" classname="real numbers forming a monoid" file="test/fixtures/simple/simple-test.js"/>
10+
<testcase name="null hypothesis" time="<<computed>>" classname="off-by-one boolean logic errors" file="test/fixtures/simple/simple-test.js"/>
11+
<testcase name="asserts error" time="<<computed>>" classname="off-by-one boolean logic errors" file="test/fixtures/simple/simple-test.js" line="17">
1212
<failure message="expected false to be true" type="AssertionError"><![CDATA[AssertionError: expected false to be true
13-
at <<anonymous>> (packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js:17:29)]]></failure>
13+
at <<anonymous>> (test/fixtures/simple/simple-test.js:17:29)]]></failure>
1414
</testcase>
15-
<testcase name="tbd: confirm true positive" time="<<computed>>" classname="off-by-one boolean logic errors" file="packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js">
15+
<testcase name="tbd: confirm true positive" time="<<computed>>" classname="off-by-one boolean logic errors" file="test/fixtures/simple/simple-test.js">
1616
<skipped/>
1717
</testcase>
18-
<testcase name="reports logs to JUnit" time="<<computed>>" classname="logging during a test" file="packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js"/>
19-
<testcase name="fails with source trace" time="<<computed>>" classname="logging during a test" file="packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js" line="2">
18+
<testcase name="reports logs to JUnit" time="<<computed>>" classname="logging during a test" file="test/fixtures/simple/simple-test.js"/>
19+
<testcase name="fails with source trace" time="<<computed>>" classname="logging during a test" file="test/fixtures/simple/simple-test.js" line="2">
2020
<failure message="failed" type="Error"><![CDATA[Error: failed
21-
at fail (packages/test-runner-junit-reporter/test/fixtures/simple/simple-source.js:2:9)
22-
at <<anonymous>> (packages/test-runner-junit-reporter/test/fixtures/simple/simple-test.js:33:17)]]></failure>
21+
at fail (test/fixtures/simple/simple-source.js:2:9)
22+
at <<anonymous>> (test/fixtures/simple/simple-test.js:33:17)]]></failure>
2323
</testcase>
2424
</testsuite>
2525
</testsuites>

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.resolve(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)