Skip to content

Commit

Permalink
chore(ct): dedupe types
Browse files Browse the repository at this point in the history
  • Loading branch information
sand4rt committed Dec 29, 2023
1 parent 39abc63 commit 8d7671d
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 212 deletions.
30 changes: 30 additions & 0 deletions packages/playwright-ct-core/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { InlineConfig } from 'vite';
import type {
TestType as BaseTestType,
PlaywrightTestArgs,
PlaywrightTestConfig as BasePlaywrightTestConfig,
PlaywrightTestOptions,
PlaywrightWorkerArgs,
PlaywrightWorkerOptions,
} from 'playwright/test';

export type PlaywrightTestConfig<T = {}, W = {}> = Omit<BasePlaywrightTestConfig<T, W>, 'use'> & {
use?: BasePlaywrightTestConfig<T, W>['use'] & {
ctPort?: number;
ctTemplateDir?: string;
ctCacheDir?: string;
ctViteConfig?: InlineConfig | (() => Promise<InlineConfig>);
};
};

export type TestType<ComponentFixtures> = BaseTestType<
PlaywrightTestArgs & PlaywrightTestOptions & ComponentFixtures,
PlaywrightWorkerArgs & PlaywrightWorkerOptions
>;

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>;
export function defineConfig(config: PlaywrightTestConfig, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig;
export function defineConfig<T>(config: PlaywrightTestConfig<T>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T>;
export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T, W>;
41 changes: 5 additions & 36 deletions packages/playwright-ct-react/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,9 @@
* limitations under the License.
*/

import type {
TestType,
PlaywrightTestArgs,
PlaywrightTestConfig as BasePlaywrightTestConfig,
PlaywrightTestOptions,
PlaywrightWorkerArgs,
PlaywrightWorkerOptions,
Locator,
} from 'playwright/test';
import type { Locator } from 'playwright/test';
import type { JsonObject } from '@playwright/experimental-ct-core/types/component';
import type { InlineConfig } from 'vite';

export type PlaywrightTestConfig<T = {}, W = {}> = Omit<BasePlaywrightTestConfig<T, W>, 'use'> & {
use?: BasePlaywrightTestConfig<T, W>['use'] & {
ctPort?: number;
ctTemplateDir?: string;
ctCacheDir?: string;
ctViteConfig?: InlineConfig | (() => Promise<InlineConfig>);
};
};
import type { TestType } from '@playwright/experimental-ct-core/types';

export interface MountOptions<HooksConfig extends JsonObject> {
hooksConfig?: HooksConfig;
Expand All @@ -44,26 +27,12 @@ interface MountResult extends Locator {
update(component: JSX.Element): Promise<void>;
}

export interface ComponentFixtures {
export const test: TestType<{
mount<HooksConfig extends JsonObject>(
component: JSX.Element,
options?: MountOptions<HooksConfig>
): Promise<MountResult>;
}

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>;
export function defineConfig(config: PlaywrightTestConfig, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig;
export function defineConfig<T>(config: PlaywrightTestConfig<T>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T>;
export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T, W>;
}>;

export { defineConfig, PlaywrightTestConfig } from '@playwright/experimental-ct-core/types';
export { expect, devices } from 'playwright/test';
2 changes: 1 addition & 1 deletion packages/playwright-ct-react/register.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export default function pwRegister(components: Record<string, any>): void
export default function pwRegister(components: Record<string, any>): void;
41 changes: 5 additions & 36 deletions packages/playwright-ct-react17/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,9 @@
* limitations under the License.
*/

import type {
TestType,
PlaywrightTestArgs,
PlaywrightTestConfig as BasePlaywrightTestConfig,
PlaywrightTestOptions,
PlaywrightWorkerArgs,
PlaywrightWorkerOptions,
Locator,
} from 'playwright/test';
import type { Locator } from 'playwright/test';
import type { JsonObject } from '@playwright/experimental-ct-core/types/component';
import type { InlineConfig } from 'vite';

export type PlaywrightTestConfig<T = {}, W = {}> = Omit<BasePlaywrightTestConfig<T, W>, 'use'> & {
use?: BasePlaywrightTestConfig<T, W>['use'] & {
ctPort?: number;
ctTemplateDir?: string;
ctCacheDir?: string;
ctViteConfig?: InlineConfig | (() => Promise<InlineConfig>);
};
};
import type { TestType } from '@playwright/experimental-ct-core/types';

export interface MountOptions<HooksConfig extends JsonObject> {
hooksConfig?: HooksConfig;
Expand All @@ -44,26 +27,12 @@ interface MountResult extends Locator {
update(component: JSX.Element): Promise<void>;
}

export interface ComponentFixtures {
export const test: TestType<{
mount<HooksConfig extends JsonObject>(
component: JSX.Element,
options?: MountOptions<HooksConfig>
): Promise<MountResult>;
}

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>;
export function defineConfig(config: PlaywrightTestConfig, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig;
export function defineConfig<T>(config: PlaywrightTestConfig<T>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T>;
export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T, W>;
}>;

export { defineConfig, PlaywrightTestConfig } from '@playwright/experimental-ct-core/types';
export { expect, devices } from 'playwright/test';
2 changes: 1 addition & 1 deletion packages/playwright-ct-react17/register.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export default function pwRegister(components: Record<string, any>): void
export default function pwRegister(components: Record<string, any>): void;
41 changes: 5 additions & 36 deletions packages/playwright-ct-solid/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,9 @@
* limitations under the License.
*/

import type {
TestType,
PlaywrightTestArgs,
PlaywrightTestConfig as BasePlaywrightTestConfig,
PlaywrightTestOptions,
PlaywrightWorkerArgs,
PlaywrightWorkerOptions,
Locator,
} from 'playwright/test';
import type { Locator } from 'playwright/test';
import type { JsonObject } from '@playwright/experimental-ct-core/types/component';
import type { InlineConfig } from 'vite';

export type PlaywrightTestConfig<T = {}, W = {}> = Omit<BasePlaywrightTestConfig<T, W>, 'use'> & {
use?: BasePlaywrightTestConfig<T, W>['use'] & {
ctPort?: number;
ctTemplateDir?: string;
ctCacheDir?: string;
ctViteConfig?: InlineConfig | (() => Promise<InlineConfig>);
};
};
import type { TestType } from '@playwright/experimental-ct-core/types';

export interface MountOptions<HooksConfig extends JsonObject> {
hooksConfig?: HooksConfig;
Expand All @@ -44,26 +27,12 @@ interface MountResult extends Locator {
update(component: JSX.Element): Promise<void>;
}

export interface ComponentFixtures {
export const test: TestType<{
mount<HooksConfig extends JsonObject>(
component: JSX.Element,
options?: MountOptions<HooksConfig>
): Promise<MountResult>;
}

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>;
export function defineConfig(config: PlaywrightTestConfig, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig;
export function defineConfig<T>(config: PlaywrightTestConfig<T>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T>;
export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T, W>;
}>;

export { defineConfig, PlaywrightTestConfig } from '@playwright/experimental-ct-core/types';
export { expect, devices } from 'playwright/test';
2 changes: 1 addition & 1 deletion packages/playwright-ct-solid/register.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export default function pwRegister(components: Record<string, any>): void
export default function pwRegister(components: Record<string, any>): void;
38 changes: 5 additions & 33 deletions packages/playwright-ct-svelte/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,10 @@
* limitations under the License.
*/

import type {
TestType,
PlaywrightTestArgs,
PlaywrightTestConfig as BasePlaywrightTestConfig,
PlaywrightTestOptions,
PlaywrightWorkerArgs,
PlaywrightWorkerOptions,
Locator,
} from 'playwright/test';
import type { Locator } from 'playwright/test';
import type { JsonObject } from '@playwright/experimental-ct-core/types/component';
import type { InlineConfig } from 'vite';
import type { SvelteComponent, ComponentProps } from 'svelte/types/runtime';

export type PlaywrightTestConfig<T = {}, W = {}> = Omit<BasePlaywrightTestConfig<T, W>, 'use'> & {
use?: BasePlaywrightTestConfig<T, W>['use'] & {
ctPort?: number;
ctTemplateDir?: string;
ctCacheDir?: string;
ctViteConfig?: InlineConfig | (() => Promise<InlineConfig>);
};
};
import type { TestType } from '@playwright/experimental-ct-core/types';

type ComponentSlot = string | string[];
type ComponentSlots = Record<string, ComponentSlot> & { default?: ComponentSlot };
Expand All @@ -55,23 +38,12 @@ interface MountResult<Component extends SvelteComponent> extends Locator {
}): Promise<void>;
}

interface ComponentFixtures {
export const test: TestType<{
mount<HooksConfig extends JsonObject, Component extends SvelteComponent = SvelteComponent>(
component: new (...args: any[]) => Component,
options?: MountOptions<HooksConfig, Component>
): Promise<MountResult<Component>>;
}

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

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>;
export function defineConfig(config: PlaywrightTestConfig, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig;
export function defineConfig<T>(config: PlaywrightTestConfig<T>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T>;
export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T, W>;
}>;

export { defineConfig, PlaywrightTestConfig } from '@playwright/experimental-ct-core/types';
export { expect, devices } from 'playwright/test';
38 changes: 5 additions & 33 deletions packages/playwright-ct-vue/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,9 @@
* limitations under the License.
*/

import type {
TestType,
PlaywrightTestArgs,
PlaywrightTestConfig as BasePlaywrightTestConfig,
PlaywrightTestOptions,
PlaywrightWorkerArgs,
PlaywrightWorkerOptions,
Locator,
} from 'playwright/test';
import type { Locator } from 'playwright/test';
import type { JsonObject } from '@playwright/experimental-ct-core/types/component';
import type { InlineConfig } from 'vite';

export type PlaywrightTestConfig<T = {}, W = {}> = Omit<BasePlaywrightTestConfig<T, W>, 'use'> & {
use?: BasePlaywrightTestConfig<T, W>['use'] & {
ctPort?: number;
ctTemplateDir?: string;
ctCacheDir?: string;
ctViteConfig?: InlineConfig | (() => Promise<InlineConfig>);
};
};
import type { TestType } from '@playwright/experimental-ct-core/types';

type ComponentSlot = string | string[];
type ComponentSlots = Record<string, ComponentSlot> & { default?: ComponentSlot };
Expand Down Expand Up @@ -71,7 +54,7 @@ interface MountResultJsx extends Locator {
update(component: JSX.Element): Promise<void>;
}

export interface ComponentFixtures {
export const test: TestType<{
mount<HooksConfig extends JsonObject>(
component: JSX.Element,
options: MountOptionsJsx<HooksConfig>
Expand All @@ -80,18 +63,7 @@ export interface ComponentFixtures {
component: Component,
options?: MountOptions<HooksConfig, Component>
): Promise<MountResult<Component>>;
}

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

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>;
export function defineConfig(config: PlaywrightTestConfig, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig;
export function defineConfig<T>(config: PlaywrightTestConfig<T>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T>;
export function defineConfig<T, W>(config: PlaywrightTestConfig<T, W>, ...configs: PlaywrightTestConfig[]): PlaywrightTestConfig<T, W>;
}>;

export { defineConfig, PlaywrightTestConfig } from '@playwright/experimental-ct-core/types';
export { expect, devices } from 'playwright/test';
2 changes: 1 addition & 1 deletion packages/playwright-ct-vue/register.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ export default function pwRegister(
setDevtoolsHook: any,
h: any,
}
): void
): void;
Loading

0 comments on commit 8d7671d

Please sign in to comment.