11/* @vitest -environment jsdom */
22
3- import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
3+ import { afterEach , beforeEach , describe , expect , it , vi , type Mock } from "vitest" ;
44import { i18n } from "../../i18n/index.ts" ;
55import type { TerminalGatewayClient } from "./terminal-connection.ts" ;
66
@@ -11,7 +11,19 @@ type CreateOptions = {
1111 onResize ?: ( size : { columns : number ; rows : number } ) => void ;
1212} ;
1313
14- const createGhosttyTerminalMock = vi . hoisted ( ( ) => vi . fn ( ) ) ;
14+ type CreateGhosttyTerminalMock = Mock <
15+ ( options : CreateOptions ) => Promise < ReturnType < typeof createTerminalController > >
16+ > ;
17+
18+ // Vitest resets this test module but can retain terminal-panel.ts. Reuse one
19+ // mock so retained imports and the current test graph share the same identity.
20+ const createGhosttyTerminalMock = vi . hoisted ( ( ) => {
21+ const scope = globalThis as typeof globalThis & {
22+ openclawTestCreateGhosttyTerminalMock ?: CreateGhosttyTerminalMock ;
23+ } ;
24+ return ( scope . openclawTestCreateGhosttyTerminalMock ??=
25+ vi . fn < ( options : CreateOptions ) => Promise < ReturnType < typeof createTerminalController > > > ( ) ) ;
26+ } ) ;
1527
1628function createTerminalController ( dispose : ( ) => void = vi . fn ( ) ) {
1729 return {
@@ -52,15 +64,13 @@ vi.mock("./terminal-runtime.ts", () => {
5264
5365import { OpenClawTerminalPanel } from "./terminal-panel.ts" ;
5466
55- const TERMINAL_PANEL_ELEMENT_NAME = " test-openclaw-terminal-panel" ;
67+ const TERMINAL_PANEL_ELEMENT_NAME = ` test-openclaw-terminal-panel- ${ crypto . randomUUID ( ) } ` ;
5668
5769// Keep the mounted panel and i18n manager in the current module graph when
5870// the non-isolated runner has retained an earlier production registration.
5971class TestTerminalPanel extends OpenClawTerminalPanel { }
6072
61- if ( ! customElements . get ( TERMINAL_PANEL_ELEMENT_NAME ) ) {
62- customElements . define ( TERMINAL_PANEL_ELEMENT_NAME , TestTerminalPanel ) ;
63- }
73+ customElements . define ( TERMINAL_PANEL_ELEMENT_NAME , TestTerminalPanel ) ;
6474
6575describe ( "OpenClawTerminalPanel" , ( ) => {
6676 beforeEach ( async ( ) => {
0 commit comments