qwen-code/packages/web-shell/client/test/reactHarness.tsx
ermin.zem 5c82857fea
Some checks are pending
E2E Tests / E2E Test (Linux) - sandbox:docker (push) Waiting to run
E2E Tests / E2E Test (Linux) - sandbox:none (push) Waiting to run
E2E Tests / E2E Test - macOS (push) Waiting to run
E2E Tests / web-shell Browser Regression (push) Waiting to run
Add harness infrastructure for web-shell package (#6517)
* test(web-shell): add browser and lint harness

* test(web-shell): harden browser smoke harness

* fix(web-shell): guard mock daemon model state

* test(web-shell): remove unused scenario harness

* fix(web-shell): remove stale lint disables

* test(web-shell): make matchMedia stub writable

* fix(web-shell): exclude tests from package typecheck

* test(web-shell): tighten mock daemon route contract

* Update packages/web-shell/client/e2e/utils/mockDaemon.ts

Co-authored-by: qwen-code-ci-bot <qwen-code-ci@service.alibaba.com>

* test(web-shell): clear stale SSE connections

* ci(web-shell): gate smoke on full CI profile

---------

Co-authored-by: ermin.zem <ermin.zem@alibaba-inc.com>
Co-authored-by: qwen-code-ci-bot <qwen-code-ci@service.alibaba.com>
Co-authored-by: Shaojin Wen <shaojin.wensj@alibaba-inc.com>
Co-authored-by: 易良 <1204183885@qq.com>
2026-07-09 08:11:58 +00:00

40 lines
997 B
TypeScript

import { act, type ReactNode } from 'react';
import { createRoot, type Root } from 'react-dom/client';
const mounted: Array<{ root: Root; container: HTMLElement }> = [];
export function mountReact(node: ReactNode): HTMLElement {
const container = document.createElement('div');
document.body.appendChild(container);
const root = createRoot(container);
act(() => {
root.render(node);
});
mounted.push({ root, container });
return container;
}
export function cleanupReact(): void {
for (const { root, container } of mounted.splice(0)) {
act(() => {
root.unmount();
});
container.remove();
}
}
export async function flushReact(): Promise<void> {
await act(async () => {
await Promise.resolve();
await Promise.resolve();
});
}
export function immediateClipboardWrite(): Promise<void> {
return {
then(onFulfilled?: (value: void) => unknown) {
onFulfilled?.(undefined);
return Promise.resolve();
},
} as Promise<void>;
}