-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.ts
111 lines (96 loc) · 3.18 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import * as path from 'node:path';
import type {
EnvironmentProviders,
EventEmitter,
InputSignal,
Provider,
Type,
} from '@angular/core';
import type {
PlaywrightTestConfig,
TestType,
} from '@playwright/experimental-ct-core';
import * as playwrightCtCore from '@playwright/experimental-ct-core';
import { JsonObject } from '@playwright/experimental-ct-core/types/component';
import * as playwright from '@playwright/test';
export type { PlaywrightTestConfig };
export { expect, devices } from '@playwright/test';
export interface ComponentFixtures {
mount<COMPONENT, HOOKS extends JsonObject>(
template: string,
options?: MountTemplateOptions<COMPONENT, HOOKS>,
): Promise<MountResult<COMPONENT>>;
mount<COMPONENT, HOOKS extends JsonObject>(
component: Type<COMPONENT>,
options?: MountOptions<COMPONENT, HOOKS>,
): Promise<MountResult<COMPONENT>>;
}
export interface MountOptions<COMPONENT, HOOKS> {
hooksConfig?: HOOKS;
providers?: Array<Provider | EnvironmentProviders>;
props?: Inputs<COMPONENT>;
on?: OutputListeners<COMPONENT>;
}
export interface MountTemplateOptions<COMPONENT, HOOKS extends JsonObject>
extends MountOptions<COMPONENT, HOOKS> {
imports?: Type<unknown>[];
}
export interface MountResult<COMPONENT> extends playwright.Locator {
unmount(): Promise<void>;
update(options: {
props?: Inputs<COMPONENT>;
on?: OutputListeners<COMPONENT>;
}): Promise<void>;
}
export type Inputs<COMPONENT> = Partial<{
[PROPERTY in keyof COMPONENT]: COMPONENT[PROPERTY] extends InputSignal<
infer VALUE
>
? VALUE
: COMPONENT[PROPERTY];
}>;
export type OutputListeners<COMPONENT> = Partial<{
[PROPERTY in keyof COMPONENT as COMPONENT[PROPERTY] extends Subscribable<unknown>
? PROPERTY
: never]: (value: Emitted<COMPONENT[PROPERTY]>) => void;
}>;
type Subscribable<T> =
| {
subscribe(next: (value: T) => void): void;
}
| EventEmitter<T>;
type Emitted<SUBSCRIBABLE> =
SUBSCRIBABLE extends Subscribable<infer EMITTED> ? EMITTED : SUBSCRIBABLE;
/* @hack `test` is not exported in the type definition of `@playwright/experimental-ct-core`. */
// @eslint-disable-next-line @typescript-eslint/no-explicit-any
export const test: TestType<ComponentFixtures> = (playwrightCtCore as any).test;
export const defineConfig: typeof playwrightCtCore.defineConfig = (
config,
...configs
): PlaywrightTestConfig => {
const original = playwrightCtCore.defineConfig(
{
...config,
'@playwright/test': {
packageJSON: require.resolve('./package.json'),
},
'@playwright/experimental-ct-core': {
registerSourceFile: path.join(__dirname, 'register-source.mjs'),
},
},
...configs,
);
/* @hack for some weird reason, if we do not require the babel plugin here,
* babel loads an empty object instead of the default exported function. */
require('@jscutlery/playwright-ct-angular/transform-angular');
return {
...original,
'@playwright/test': {
...original['@playwright/test'],
babelPlugins: [
...original['@playwright/test'].babelPlugins,
[require.resolve('@jscutlery/playwright-ct-angular/transform-angular')],
],
},
} as PlaywrightTestConfig;
};