11// @vitest -environment jsdom
22
3+ import { readdirSync } from "node:fs" ;
34import { createRequire } from "node:module" ;
5+ import { join } from "node:path" ;
46import { fireEvent , screen } from "@testing-library/dom" ;
57import type ReactTypes from "react" ;
68import { 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) ;
1113const 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" ) ;
1636const { act } = React ;
0 commit comments