Skip to content

Commit

Permalink
feat(ct): vue type safe mount props
Browse files Browse the repository at this point in the history
  • Loading branch information
sand4rt committed Jul 29, 2023
1 parent f453a17 commit 5e1720d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
16 changes: 14 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 18 additions & 24 deletions packages/playwright-ct-vue/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type {
} from '@playwright/test';
import type { JsonObject } from '@playwright/experimental-ct-core/types/component';
import type { InlineConfig } from 'vite';
import type { ComponentProps } from 'vue-component-type-helpers';

export type PlaywrightTestConfig<T = {}, W = {}> = Omit<BasePlaywrightTestConfig<T, W>, 'use'> & {
use?: BasePlaywrightTestConfig<T, W>['use'] & {
Expand All @@ -35,21 +36,24 @@ export type PlaywrightTestConfig<T = {}, W = {}> = Omit<BasePlaywrightTestConfig
};
};

type Slot = string | string[];
type ComponentSlot = string | string[];
type ComponentSlots = Record<string, ComponentSlot> & { default?: ComponentSlot };
type ComponentEvents = Record<string, Function>;

export interface MountOptions<
HooksConfig extends JsonObject,
Props extends Record<string, unknown>
> {
props?: Props;
slots?: Record<string, Slot> & { default?: Slot };
on?: Record<string, Function>;
export interface MountOptions< HooksConfig extends JsonObject, Component> {
props?: ComponentProps<Component>;
slots?: ComponentSlots;
on?: ComponentEvents;
hooksConfig?: HooksConfig;
}

interface MountResult<Props extends Record<string, unknown>> extends Locator {
interface MountResult<Component> extends Locator {
unmount(): Promise<void>;
update(options: Omit<MountOptions<never, Props>, 'hooksConfig'>): Promise<void>;
update(options: {
props?: Partial<ComponentProps<Component>>;
slots?: Partial<ComponentSlots>;
on?: Partial<ComponentEvents>;
}): Promise<void>;
}

interface MountResultJsx extends Locator {
Expand All @@ -59,27 +63,17 @@ interface MountResultJsx extends Locator {

export interface ComponentFixtures {
mount(component: JSX.Element): Promise<MountResultJsx>;
mount<HooksConfig extends JsonObject>(
component: any,
options?: MountOptions<HooksConfig, Record<string, unknown>>
): Promise<MountResult<Record<string, unknown>>>;
mount<
HooksConfig extends JsonObject,
Props extends Record<string, unknown> = Record<string, unknown>
>(
component: any,
options: MountOptions<HooksConfig, never> & { props: Props }
): Promise<MountResult<Props>>;
mount<HooksConfig extends JsonObject, Component = unknown>(
component: Component,
options?: MountOptions<HooksConfig, Component>
): Promise<MountResult<Component>>;
}

export const test: TestType<
PlaywrightTestArgs & PlaywrightTestOptions & ComponentFixtures,
PlaywrightWorkerArgs & PlaywrightWorkerOptions
>;

/**
* Defines Playwright config
*/
export function defineConfig(config: PlaywrightTestConfig): PlaywrightTestConfig;
export function defineConfig<T>(config: PlaywrightTestConfig<T>): PlaywrightTestConfig<T>;
export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>): PlaywrightTestConfig<T, W>;
Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-ct-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
},
"dependencies": {
"@playwright/experimental-ct-core": "1.37.0-next",
"@vitejs/plugin-vue": "^4.2.1"
"@vitejs/plugin-vue": "^4.2.1",
"vue-component-type-helpers": "^1.6.5"
},
"bin": {
"playwright": "./cli.js"
Expand Down
2 changes: 1 addition & 1 deletion tests/components/ct-vue-vite/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "@vue/tsconfig/tsconfig.web.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue", "playwright"],
"include": ["env.d.ts", "src/**/*", "src/**/*.vue", "tests/**/*", "playwright"],
"compilerOptions": {
"baseUrl": ".",
"paths": {
Expand Down

0 comments on commit 5e1720d

Please sign in to comment.