From d8b037c559cbed2ea540f97f19208a3106ad8ea2 Mon Sep 17 00:00:00 2001 From: sand4rt Date: Thu, 20 Oct 2022 04:39:50 +0200 Subject: [PATCH] feat(ct): solid update (#18074) closes: https://github.com/microsoft/playwright/issues/15057 closes: https://github.com/microsoft/playwright/issues/15919 Signed-off-by: sand4rt --- packages/playwright-ct-solid/index.d.ts | 1 + .../playwright-ct-solid/registerSource.mjs | 5 ++ .../ct-solid/src/components/Counter.tsx | 19 +++++++ tests/components/ct-solid/src/tests.spec.tsx | 50 ++++++++++++++++++- 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tests/components/ct-solid/src/components/Counter.tsx diff --git a/packages/playwright-ct-solid/index.d.ts b/packages/playwright-ct-solid/index.d.ts index 2b21976334..8f06efc53e 100644 --- a/packages/playwright-ct-solid/index.d.ts +++ b/packages/playwright-ct-solid/index.d.ts @@ -45,6 +45,7 @@ export interface MountOptions { interface MountResult extends Locator { unmount(): Promise; + update(component: JSX.Element): Promise; } export interface ComponentFixtures { diff --git a/packages/playwright-ct-solid/registerSource.mjs b/packages/playwright-ct-solid/registerSource.mjs index 0e9741830a..4b9c44869f 100644 --- a/packages/playwright-ct-solid/registerSource.mjs +++ b/packages/playwright-ct-solid/registerSource.mjs @@ -95,3 +95,8 @@ window.playwrightUnmount = async rootElement => { unmount(); }; + +window.playwrightUpdate = async (rootElement, component) => { + window.playwrightUnmount(rootElement); + window.playwrightMount(component, rootElement, {}); +}; diff --git a/tests/components/ct-solid/src/components/Counter.tsx b/tests/components/ct-solid/src/components/Counter.tsx new file mode 100644 index 0000000000..6b35eddcec --- /dev/null +++ b/tests/components/ct-solid/src/components/Counter.tsx @@ -0,0 +1,19 @@ +import { createSignal } from "solid-js"; + + type CounterProps = { + count?: number; + onClick?(props: string): void; + children?: any; + } + + let _remountCount = 1; + + export default function Counter(props: CounterProps) { + const [remountCount, setRemountCount] = createSignal(_remountCount++); + return
props.onClick?.('hello')}> +
{ props.count }
+
{ remountCount }
+ { props.children } +
+ } + \ No newline at end of file diff --git a/tests/components/ct-solid/src/tests.spec.tsx b/tests/components/ct-solid/src/tests.spec.tsx index fda162d46b..a939580e31 100644 --- a/tests/components/ct-solid/src/tests.spec.tsx +++ b/tests/components/ct-solid/src/tests.spec.tsx @@ -1,5 +1,6 @@ import { test, expect } from '@playwright/experimental-ct-solid'; import Button from './components/Button'; +import Counter from './components/Counter'; import DefaultChildren from './components/DefaultChildren'; import MultipleChildren from './components/MultipleChildren'; import MultiRoot from './components/MultiRoot'; @@ -16,7 +17,54 @@ test('render props', async ({ mount }) => { test('render attributes', async ({ mount }) => { const component = await mount(