diff --git a/packages/playwright-ct-react/hooks.d.ts b/packages/playwright-ct-react/hooks.d.ts index 16015a4ad0..1093f1a3a3 100644 --- a/packages/playwright-ct-react/hooks.d.ts +++ b/packages/playwright-ct-react/hooks.d.ts @@ -14,11 +14,9 @@ * limitations under the License. */ -export interface RegisterHooksConfig {} - -export declare function beforeMount( +export declare function beforeMount( callback: (params: { hooksConfig?: HooksConfig; App: () => JSX.Element }) => Promise ): void; -export declare function afterMount( +export declare function afterMount( callback: (params: { hooksConfig?: HooksConfig }) => Promise ): void; diff --git a/packages/playwright-ct-react/index.d.ts b/packages/playwright-ct-react/index.d.ts index 753e3d4662..121f563a48 100644 --- a/packages/playwright-ct-react/index.d.ts +++ b/packages/playwright-ct-react/index.d.ts @@ -15,10 +15,9 @@ */ import type { Locator } from 'playwright/test'; -import type { TestType } from '@playwright/experimental-ct-core'; -import type { RegisterHooksConfig } from './hooks'; +import type { TestType as BaseTestType } from '@playwright/experimental-ct-core'; -export interface MountOptions { +export interface MountOptions { hooksConfig?: HooksConfig; } @@ -27,12 +26,14 @@ export interface MountResult extends Locator { update(component: JSX.Element): Promise; } -export const test: TestType<{ - mount( +export type TestType> = BaseTestType<{ + mount( component: JSX.Element, options?: MountOptions ): Promise; }>; +export const test: TestType; + export { defineConfig, type PlaywrightTestConfig } from '@playwright/experimental-ct-core'; export { expect, devices } from 'playwright/test'; diff --git a/packages/playwright-ct-react17/hooks.d.ts b/packages/playwright-ct-react17/hooks.d.ts index 16015a4ad0..1093f1a3a3 100644 --- a/packages/playwright-ct-react17/hooks.d.ts +++ b/packages/playwright-ct-react17/hooks.d.ts @@ -14,11 +14,9 @@ * limitations under the License. */ -export interface RegisterHooksConfig {} - -export declare function beforeMount( +export declare function beforeMount( callback: (params: { hooksConfig?: HooksConfig; App: () => JSX.Element }) => Promise ): void; -export declare function afterMount( +export declare function afterMount( callback: (params: { hooksConfig?: HooksConfig }) => Promise ): void; diff --git a/packages/playwright-ct-react17/index.d.ts b/packages/playwright-ct-react17/index.d.ts index 753e3d4662..121f563a48 100644 --- a/packages/playwright-ct-react17/index.d.ts +++ b/packages/playwright-ct-react17/index.d.ts @@ -15,10 +15,9 @@ */ import type { Locator } from 'playwright/test'; -import type { TestType } from '@playwright/experimental-ct-core'; -import type { RegisterHooksConfig } from './hooks'; +import type { TestType as BaseTestType } from '@playwright/experimental-ct-core'; -export interface MountOptions { +export interface MountOptions { hooksConfig?: HooksConfig; } @@ -27,12 +26,14 @@ export interface MountResult extends Locator { update(component: JSX.Element): Promise; } -export const test: TestType<{ - mount( +export type TestType> = BaseTestType<{ + mount( component: JSX.Element, options?: MountOptions ): Promise; }>; +export const test: TestType; + export { defineConfig, type PlaywrightTestConfig } from '@playwright/experimental-ct-core'; export { expect, devices } from 'playwright/test'; diff --git a/tests/components/ct-react-vite/playwright/index.tsx b/tests/components/ct-react-vite/playwright/index.tsx index 9054dedfd2..a7e56d4002 100644 --- a/tests/components/ct-react-vite/playwright/index.tsx +++ b/tests/components/ct-react-vite/playwright/index.tsx @@ -1,20 +1,22 @@ +import { test as baseTest, type TestType } from '@playwright/experimental-ct-react'; import { beforeMount, afterMount } from '@playwright/experimental-ct-react/hooks'; import { BrowserRouter } from 'react-router-dom'; import '../src/assets/index.css'; -declare module '@playwright/experimental-ct-react/hooks' { - interface RegisterHooksConfig { - routing?: boolean; - } +type HooksConfig = { + routing?: boolean; } -beforeMount(async ({ hooksConfig, App }) => { +export * from '@playwright/experimental-ct-react'; +export const test = baseTest as TestType; + +beforeMount(async ({ hooksConfig, App }) => { console.log(`Before mount: ${JSON.stringify(hooksConfig)}`); if (hooksConfig?.routing) return ; }); -afterMount(async () => { +afterMount(async () => { console.log(`After mount`); }); diff --git a/tests/components/ct-react-vite/tests/callbacks.spec.tsx b/tests/components/ct-react-vite/tests/callbacks.spec.tsx index d9d15dac16..1938708f38 100644 --- a/tests/components/ct-react-vite/tests/callbacks.spec.tsx +++ b/tests/components/ct-react-vite/tests/callbacks.spec.tsx @@ -1,4 +1,4 @@ -import { test, expect } from '@playwright/experimental-ct-react'; +import { test, expect } from '../playwright'; import Button from '@/components/Button'; import DefaultChildren from '@/components/DefaultChildren'; diff --git a/tests/components/ct-react-vite/tests/children.spec.tsx b/tests/components/ct-react-vite/tests/children.spec.tsx index 03da7d2c55..f4c361a5f6 100644 --- a/tests/components/ct-react-vite/tests/children.spec.tsx +++ b/tests/components/ct-react-vite/tests/children.spec.tsx @@ -1,4 +1,4 @@ -import { test, expect } from '@playwright/experimental-ct-react'; +import { test, expect } from '../playwright'; import Button from '@/components/Button'; import CheckChildrenProp from '@/components/CheckChildrenProp'; import DefaultChildren from '@/components/DefaultChildren'; diff --git a/tests/components/ct-react-vite/tests/react-router.spec.tsx b/tests/components/ct-react-vite/tests/react-router.spec.tsx index 101ad9d737..81e9a3b5d2 100644 --- a/tests/components/ct-react-vite/tests/react-router.spec.tsx +++ b/tests/components/ct-react-vite/tests/react-router.spec.tsx @@ -1,4 +1,4 @@ -import { test, expect } from '@playwright/experimental-ct-react'; +import { test, expect } from '../playwright'; import App from '@/App'; test('navigate to a page by clicking a link', async ({ page, mount }) => { @@ -12,7 +12,7 @@ test('navigate to a page by clicking a link', async ({ page, mount }) => { await expect(page).toHaveURL('/dashboard'); }); -test('update should not reset mount hooks', async ({ page, mount }) => { +test('update should not reset mount hooks', async ({ mount }) => { const component = await mount(, { hooksConfig: { routing: true }, }); diff --git a/tests/components/ct-react-vite/tests/render.spec.tsx b/tests/components/ct-react-vite/tests/render.spec.tsx index 1d82d21b3a..7afa42f20a 100644 --- a/tests/components/ct-react-vite/tests/render.spec.tsx +++ b/tests/components/ct-react-vite/tests/render.spec.tsx @@ -1,4 +1,4 @@ -import { test, expect } from '@playwright/experimental-ct-react'; +import { test, expect } from '../playwright'; import Button from '@/components/Button'; import EmptyFragment from '@/components/EmptyFragment'; import { ComponentAsProp } from '@/components/ComponentAsProp'; diff --git a/tests/components/ct-react-vite/tests/route.spec.tsx b/tests/components/ct-react-vite/tests/route.spec.tsx index 657b0a7007..3db60559f1 100644 --- a/tests/components/ct-react-vite/tests/route.spec.tsx +++ b/tests/components/ct-react-vite/tests/route.spec.tsx @@ -1,4 +1,4 @@ -import { test, expect } from '@playwright/experimental-ct-react'; +import { test, expect } from '../playwright'; import TitleWithFont from '@/components/TitleWithFont'; test('should load font without routes', async ({ mount, page }) => { diff --git a/tests/components/ct-react-vite/tests/unmount.spec.tsx b/tests/components/ct-react-vite/tests/unmount.spec.tsx index 4ce2d45889..751a57a513 100644 --- a/tests/components/ct-react-vite/tests/unmount.spec.tsx +++ b/tests/components/ct-react-vite/tests/unmount.spec.tsx @@ -1,4 +1,4 @@ -import { test, expect } from '@playwright/experimental-ct-react'; +import { test, expect } from '../playwright'; import Button from '@/components/Button'; import MultiRoot from '@/components/MultiRoot'; diff --git a/tests/components/ct-react-vite/tests/update.spec.tsx b/tests/components/ct-react-vite/tests/update.spec.tsx index e492a4e4cb..95b5a1b030 100644 --- a/tests/components/ct-react-vite/tests/update.spec.tsx +++ b/tests/components/ct-react-vite/tests/update.spec.tsx @@ -1,4 +1,4 @@ -import { test, expect } from '@playwright/experimental-ct-react'; +import { test, expect } from '../playwright'; import Counter from '@/components/Counter'; import DefaultChildren from '@/components/DefaultChildren';