Skip to content

Commit bd59352

Browse files
committed
Use the Node.js test runner API and remove the dev dependency test-director.
1 parent f557977 commit bd59352

33 files changed

+2538
-2841
lines changed

Cache.test.mjs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
// @ts-check
22

3+
import "./test/polyfillCustomEvent.mjs";
4+
35
import { deepStrictEqual, strictEqual, throws } from "node:assert";
6+
import { describe, it } from "node:test";
47

58
import Cache from "./Cache.mjs";
69
import assertBundleSize from "./test/assertBundleSize.mjs";
710
import assertInstanceOf from "./test/assertInstanceOf.mjs";
811

9-
/**
10-
* Adds `Cache` tests.
11-
* @param {import("test-director").default} tests Test director.
12-
*/
13-
export default (tests) => {
14-
tests.add("`Cache` bundle size.", async () => {
12+
describe("Class `Cache`.", { concurrency: true }, () => {
13+
it("Bundle size.", async () => {
1514
await assertBundleSize(new URL("./Cache.mjs", import.meta.url), 200);
1615
});
1716

18-
tests.add("`Cache` constructor argument 1 `store`, not an object.", () => {
17+
it("Constructor argument 1 `store` not an object.", () => {
1918
throws(() => {
2019
new Cache(
2120
// @ts-expect-error Testing invalid.
@@ -24,13 +23,13 @@ export default (tests) => {
2423
}, new TypeError("Constructor argument 1 `store` must be an object."));
2524
});
2625

27-
tests.add("`Cache` constructor argument 1 `store`, missing", () => {
26+
it("Constructor argument 1 `store` missing", () => {
2827
const cache = new Cache();
2928

3029
deepStrictEqual(cache.store, {});
3130
});
3231

33-
tests.add("`Cache` constructor argument 1 `store`, object.", () => {
32+
it("Constructor argument 1 `store` an object.", () => {
3433
const initialStore = {
3534
a: 1,
3635
b: 2,
@@ -40,7 +39,7 @@ export default (tests) => {
4039
deepStrictEqual(cache.store, initialStore);
4140
});
4241

43-
tests.add("`Cache` events.", () => {
42+
it("Events.", () => {
4443
const cache = new Cache();
4544

4645
assertInstanceOf(cache, EventTarget);
@@ -68,4 +67,4 @@ export default (tests) => {
6867

6968
strictEqual(listenedEvent, null);
7069
});
71-
};
70+
});

CacheContext.test.mjs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
// @ts-check
22

33
import { strictEqual } from "node:assert";
4+
import { describe, it } from "node:test";
45
import React from "react";
56

67
import Cache from "./Cache.mjs";
78
import CacheContext from "./CacheContext.mjs";
89
import assertBundleSize from "./test/assertBundleSize.mjs";
910
import createReactTestRenderer from "./test/createReactTestRenderer.mjs";
1011

11-
/**
12-
* Adds `CacheContext` tests.
13-
* @param {import("test-director").default} tests Test director.
14-
*/
15-
export default (tests) => {
16-
tests.add("`CacheContext` bundle size.", async () => {
12+
describe("React context `CacheContext`.", { concurrency: true }, () => {
13+
it("Bundle size.", async () => {
1714
await assertBundleSize(new URL("./CacheContext.mjs", import.meta.url), 120);
1815
});
1916

20-
tests.add("`CacheContext` used as a React context.", () => {
17+
it("Used as a React context.", () => {
2118
let contextValue;
2219

2320
function TestComponent() {
@@ -37,4 +34,4 @@ export default (tests) => {
3734

3835
strictEqual(contextValue, value);
3936
});
40-
};
37+
});

HYDRATION_TIME_MS.test.mjs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
// @ts-check
22

33
import { strictEqual } from "node:assert";
4+
import { describe, it } from "node:test";
45

56
import HYDRATION_TIME_MS from "./HYDRATION_TIME_MS.mjs";
67
import assertBundleSize from "./test/assertBundleSize.mjs";
78

8-
/**
9-
* Adds `HYDRATION_TIME_MS` tests.
10-
* @param {import("test-director").default} tests Test director.
11-
*/
12-
export default (tests) => {
13-
tests.add("`HYDRATION_TIME_MS` bundle size.", async () => {
9+
describe("Constant `HYDRATION_TIME_MS`.", { concurrency: true }, () => {
10+
it("Bundle size.", async () => {
1411
await assertBundleSize(
1512
new URL("./HYDRATION_TIME_MS.mjs", import.meta.url),
1613
65
1714
);
1815
});
1916

20-
tests.add("`HYDRATION_TIME_MS` value.", () => {
17+
it("Value.", () => {
2118
strictEqual(HYDRATION_TIME_MS, 1000);
2219
});
23-
};
20+
});

HydrationTimeStampContext.test.mjs

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
11
// @ts-check
22

33
import { strictEqual } from "node:assert";
4+
import { describe, it } from "node:test";
45
import React from "react";
56

67
import HydrationTimeStampContext from "./HydrationTimeStampContext.mjs";
78
import assertBundleSize from "./test/assertBundleSize.mjs";
89
import createReactTestRenderer from "./test/createReactTestRenderer.mjs";
910

10-
/**
11-
* Adds `HydrationTimeStampContext` tests.
12-
* @param {import("test-director").default} tests Test director.
13-
*/
14-
export default (tests) => {
15-
tests.add("`HydrationTimeStampContext` bundle size.", async () => {
16-
await assertBundleSize(
17-
new URL("./HydrationTimeStampContext.mjs", import.meta.url),
18-
150
19-
);
20-
});
21-
22-
tests.add("`HydrationTimeStampContext` used as a React context.", () => {
23-
let contextValue;
24-
25-
function TestComponent() {
26-
contextValue = React.useContext(HydrationTimeStampContext);
27-
return null;
28-
}
29-
30-
const value = 1;
31-
32-
createReactTestRenderer(
33-
React.createElement(
34-
HydrationTimeStampContext.Provider,
35-
{ value },
36-
React.createElement(TestComponent)
37-
)
38-
);
39-
40-
strictEqual(contextValue, value);
41-
});
42-
};
11+
describe(
12+
"React context `HydrationTimeStampContext`.",
13+
{ concurrency: true },
14+
() => {
15+
it("Bundle size.", async () => {
16+
await assertBundleSize(
17+
new URL("./HydrationTimeStampContext.mjs", import.meta.url),
18+
150
19+
);
20+
});
21+
22+
it("Used as a React context.", () => {
23+
let contextValue;
24+
25+
function TestComponent() {
26+
contextValue = React.useContext(HydrationTimeStampContext);
27+
return null;
28+
}
29+
30+
const value = 1;
31+
32+
createReactTestRenderer(
33+
React.createElement(
34+
HydrationTimeStampContext.Provider,
35+
{ value },
36+
React.createElement(TestComponent)
37+
)
38+
);
39+
40+
strictEqual(contextValue, value);
41+
});
42+
}
43+
);

Loading.test.mjs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
// @ts-check
22

3+
import "./test/polyfillCustomEvent.mjs";
4+
35
import { deepStrictEqual, strictEqual } from "node:assert";
6+
import { describe, it } from "node:test";
47

58
import Loading from "./Loading.mjs";
69
import assertBundleSize from "./test/assertBundleSize.mjs";
710
import assertInstanceOf from "./test/assertInstanceOf.mjs";
811

9-
/**
10-
* Adds `Loading` tests.
11-
* @param {import("test-director").default} tests Test director.
12-
*/
13-
export default (tests) => {
14-
tests.add("`Loading` bundle size.", async () => {
12+
describe("Class `Loading`.", { concurrency: true }, () => {
13+
it("Bundle size.", async () => {
1514
await assertBundleSize(new URL("./Loading.mjs", import.meta.url), 120);
1615
});
1716

18-
tests.add("`Loading` constructor.", () => {
17+
it("Constructor.", () => {
1918
const loading = new Loading();
2019

2120
deepStrictEqual(loading.store, {});
2221
});
2322

24-
tests.add("`Loading` events.", () => {
23+
it("Events.", () => {
2524
const loading = new Loading();
2625

2726
assertInstanceOf(loading, EventTarget);
@@ -49,4 +48,4 @@ export default (tests) => {
4948

5049
strictEqual(listenedEvent, null);
5150
});
52-
};
51+
});

0 commit comments

Comments
 (0)