diff --git a/packages/playwright-ct-react/index.d.ts b/packages/playwright-ct-react/index.d.ts index c086d4bec54c3..121f563a48929 100644 --- a/packages/playwright-ct-react/index.d.ts +++ b/packages/playwright-ct-react/index.d.ts @@ -15,7 +15,7 @@ */ import type { Locator } from 'playwright/test'; -import type { TestType } from '@playwright/experimental-ct-core'; +import type { TestType as BaseTestType } from '@playwright/experimental-ct-core'; export interface MountOptions { hooksConfig?: HooksConfig; @@ -26,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 { defineConfig, PlaywrightTestConfig } from '@playwright/experimental-ct-core'; +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/index.d.ts b/packages/playwright-ct-react17/index.d.ts index c086d4bec54c3..121f563a48929 100644 --- a/packages/playwright-ct-react17/index.d.ts +++ b/packages/playwright-ct-react17/index.d.ts @@ -15,7 +15,7 @@ */ import type { Locator } from 'playwright/test'; -import type { TestType } from '@playwright/experimental-ct-core'; +import type { TestType as BaseTestType } from '@playwright/experimental-ct-core'; export interface MountOptions { hooksConfig?: HooksConfig; @@ -26,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 { defineConfig, PlaywrightTestConfig } from '@playwright/experimental-ct-core'; +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 fa0563dbcdf9d..a7e56d40029df 100644 --- a/tests/components/ct-react-vite/playwright/index.tsx +++ b/tests/components/ct-react-vite/playwright/index.tsx @@ -1,12 +1,15 @@ +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'; -export type HooksConfig = { - route?: string; +type HooksConfig = { routing?: boolean; } +export * from '@playwright/experimental-ct-react'; +export const test = baseTest as TestType; + beforeMount(async ({ hooksConfig, App }) => { console.log(`Before mount: ${JSON.stringify(hooksConfig)}`); diff --git a/tests/components/ct-react-vite/tests/callbacks.spec.tsx b/tests/components/ct-react-vite/tests/callbacks.spec.tsx index d9d15dac16a71..1938708f38148 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 03da7d2c55e65..f4c361a5f6668 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 939154e9d49e3..81e9a3b5d2133 100644 --- a/tests/components/ct-react-vite/tests/react-router.spec.tsx +++ b/tests/components/ct-react-vite/tests/react-router.spec.tsx @@ -1,9 +1,8 @@ -import { test, expect } from '@playwright/experimental-ct-react'; +import { test, expect } from '../playwright'; import App from '@/App'; -import type { HooksConfig } from '../playwright'; test('navigate to a page by clicking a link', async ({ page, mount }) => { - const component = await mount(, { + const component = await mount(, { hooksConfig: { routing: true }, }); await expect(component.getByRole('main')).toHaveText('Login'); @@ -13,8 +12,8 @@ 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 }) => { - const component = await mount(, { +test('update should not reset mount hooks', async ({ mount }) => { + const component = await mount(, { hooksConfig: { routing: true }, }); await expect(component.getByRole('heading')).toHaveText('before'); diff --git a/tests/components/ct-react-vite/tests/render.spec.tsx b/tests/components/ct-react-vite/tests/render.spec.tsx index 1d82d21b3aa98..7afa42f20a0ad 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 657b0a70073a9..3db60559f1fb4 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 4ce2d458899c3..751a57a5139ee 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 e492a4e4cbed9..95b5a1b0306f5 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'; diff --git a/tests/components/ct-react-vite/tsconfig.json b/tests/components/ct-react-vite/tsconfig.json index e706497adb7fe..5e7831dc7bded 100644 --- a/tests/components/ct-react-vite/tsconfig.json +++ b/tests/components/ct-react-vite/tsconfig.json @@ -21,6 +21,5 @@ "*": ["_"], } }, - "include": ["src", "tests"], "references": [{ "path": "./tsconfig.node.json" }] }