Skip to content

Commit 05bd6ef

Browse files
author
Shaw
committed
test(agent): align game TUI React renderer
1 parent 1232db7 commit 05bd6ef

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

packages/agent/src/__tests__/game-tui-mounted-surfaces.test.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// @vitest-environment jsdom
22

3+
import { readdirSync } from "node:fs";
34
import { createRequire } from "node:module";
5+
import { join } from "node:path";
46
import { fireEvent, screen } from "@testing-library/dom";
57
import type ReactTypes from "react";
68
import { afterEach, describe, expect, it, vi } from "vitest";
@@ -9,8 +11,26 @@ const pluginRequire = createRequire(
911
`${process.cwd()}/plugins/plugin-clawville/src/ui/ClawvilleOperatorSurface.tsx`,
1012
);
1113
const React = pluginRequire("react") as typeof ReactTypes;
12-
const { flushSync } = pluginRequire("react-dom") as typeof import("react-dom");
13-
const { createRoot } = pluginRequire(
14+
const bunModulesDir = join(process.cwd(), "node_modules", ".bun");
15+
const reactDomPackageDir = readdirSync(bunModulesDir).find((entry) =>
16+
entry.startsWith(`react-dom@${React.version}+`),
17+
);
18+
if (!reactDomPackageDir) {
19+
throw new Error(`Unable to locate react-dom ${React.version} package`);
20+
}
21+
const reactDomRequire = createRequire(
22+
join(
23+
bunModulesDir,
24+
reactDomPackageDir,
25+
"node_modules",
26+
"react-dom",
27+
"package.json",
28+
),
29+
);
30+
const { flushSync } = reactDomRequire(
31+
"react-dom",
32+
) as typeof import("react-dom");
33+
const { createRoot } = reactDomRequire(
1434
"react-dom/client",
1535
) as typeof import("react-dom/client");
1636
const { act } = React;

0 commit comments

Comments
 (0)