@jscutlery/playwright-ct-angular 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -89
- package/{src/register.d.ts → cli.js} +6 -3
- package/hooks.cjs.js +4 -19
- package/hooks.esm.js +4 -19
- package/index.cjs.js +39 -84
- package/index.esm.js +31 -82
- package/package.json +11 -11
- package/register-source.mjs +121 -41
- package/src/hooks.d.ts +9 -2
- package/src/index.d.ts +39 -19
- package/src/transform-angular.d.ts +29 -0
- package/transform-angular.cjs.d.ts +2 -0
- package/transform-angular.cjs.default.js +1 -0
- package/transform-angular.cjs.js +224 -0
- package/transform-angular.cjs.mjs +2 -0
- package/transform-angular.esm.d.ts +2 -0
- package/transform-angular.esm.js +218 -0
- package/register.cjs.d.ts +0 -2
- package/register.cjs.default.js +0 -1
- package/register.cjs.js +0 -88
- package/register.cjs.mjs +0 -2
- package/register.esm.d.ts +0 -2
- package/register.esm.js +0 -86
- package/src/lib/playwright-ct-angular.d.ts +0 -1062
package/README.md
CHANGED
|
@@ -1,32 +1,64 @@
|
|
|
1
1
|
# Playwright Component Testing for Angular _(experimental)_
|
|
2
2
|
|
|
3
|
-
This library brings **Angular support** to [Playwright's **experimental
|
|
3
|
+
This library brings **Angular support** to [Playwright's **experimental
|
|
4
|
+
** Component Testing](https://playwright.dev/docs/test-components).
|
|
4
5
|
|
|
5
|
-
This will allow
|
|
6
|
+
This will allow you to test your Angular components with Playwright without building the whole app and with more
|
|
7
|
+
control.
|
|
6
8
|
|
|
7
9
|
`@jscutlery/playwright-ct-angular` currently supports:
|
|
8
10
|
|
|
9
|
-
- ✅ **Testing
|
|
10
|
-
- 🎛 **
|
|
11
|
-
-
|
|
11
|
+
- ✅ **Testing Angular components/directives/pipes**
|
|
12
|
+
- 🎛 **Controlling inputs/outputs in a type-safe fashion**
|
|
13
|
+
- 🥸 **Overriding providers**
|
|
14
|
+
- 🍳 **Testing with templates**
|
|
12
15
|
|
|
13
16
|
https://user-images.githubusercontent.com/2674658/206226065-ba856329-dda7-43b1-9c28-4416b190f4d4.mp4
|
|
14
17
|
|
|
15
|
-
#
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
# Table of Contents
|
|
19
|
+
|
|
20
|
+
<!-- TOC -->
|
|
21
|
+
|
|
22
|
+
* [Playwright Component Testing for Angular _(experimental)_](#playwright-component-testing-for-angular-_experimental_)
|
|
23
|
+
* [Table of Contents](#table-of-contents)
|
|
24
|
+
* [🚀 Writing your first test](#-writing-your-first-test)
|
|
25
|
+
* [✅ Basic Test](#-basic-test)
|
|
26
|
+
* [🎛 Testing Inputs](#-testing-inputs)
|
|
27
|
+
* [Passing output callbacks](#passing-output-callbacks)
|
|
28
|
+
* [🥸 Providing Test Doubles & Importing Additional Modules](#-providing-test-doubles--importing-additional-modules)
|
|
29
|
+
* [🎨 Using Styles](#-using-styles)
|
|
30
|
+
* [Shared Styles](#shared-styles)
|
|
31
|
+
* [Specific Styles](#specific-styles)
|
|
32
|
+
* [Angular Material & Angular Libraries with styles](#angular-material--angular-libraries-with-styles)
|
|
33
|
+
* [More examples](#more-examples)
|
|
34
|
+
* [⚠️ Known Limitations](#-known-limitations)
|
|
35
|
+
* [🪄 The Magic Behind the Scenes](#-the-magic-behind-the-scenes)
|
|
36
|
+
* [It is currently impossible to...](#it-is-currently-impossible-to)
|
|
37
|
+
* [...hold the component type in a variable](#hold-the-component-type-in-a-variable)
|
|
38
|
+
* [...use the component type elsewhere in the file.](#use-the-component-type-elsewhere-in-the-file)
|
|
39
|
+
* [...declare components in the same file.](#declare-components-in-the-same-file)
|
|
40
|
+
* [📦 Setup](#-setup)
|
|
41
|
+
* [1. Install](#1-install)
|
|
42
|
+
* [2. Configure](#2-configure)
|
|
43
|
+
* [3. Change tests extension](#3-change-tests-extension)
|
|
44
|
+
|
|
45
|
+
<!-- TOC -->
|
|
46
|
+
|
|
47
|
+
# 🚀 Writing your first test
|
|
48
|
+
|
|
49
|
+
First, you will have to set up Playwright Component Testing as [mentioned below](#setup).
|
|
18
50
|
|
|
19
51
|
⚠️ Make sure to check the [known limitations](#-known-limitations) before writing more tests.
|
|
20
52
|
|
|
21
53
|
## ✅ Basic Test
|
|
22
54
|
|
|
23
|
-
Then,
|
|
55
|
+
Then, you can write your first test in `.../src/greetings.component.pw.ts`:
|
|
24
56
|
|
|
25
57
|
```ts
|
|
26
58
|
import { expect, test } from '@jscutlery/playwright-ct-angular';
|
|
27
59
|
import { GreetingsComponent } from './greetings.component';
|
|
28
60
|
|
|
29
|
-
test(
|
|
61
|
+
test(`GreetingsComponent should be polite`, async ({ mount }) => {
|
|
30
62
|
const locator = await mount(GreetingsComponent);
|
|
31
63
|
expect(locator).toHaveText('👋 Hello!');
|
|
32
64
|
});
|
|
@@ -38,38 +70,20 @@ test('<jc-greetings> should be polite', async ({ mount }) => {
|
|
|
38
70
|
import { expect, test } from '@jscutlery/playwright-ct-angular';
|
|
39
71
|
import { GreetingsComponent } from './greetings.component';
|
|
40
72
|
|
|
41
|
-
test(
|
|
42
|
-
const locator = await mount(GreetingsComponent, {
|
|
73
|
+
test(`GreetingsComponent should be polite`, async ({ mount }) => {
|
|
74
|
+
const locator = await mount(GreetingsComponent, { props: { name: 'Edouard' } });
|
|
43
75
|
expect(locator).toHaveText('👋 Hello Edouard!');
|
|
44
76
|
});
|
|
45
77
|
```
|
|
46
78
|
|
|
47
|
-
## 🎭 Spying on outputs
|
|
48
|
-
|
|
49
|
-
`mount()` will automatically create a `jest-mock`'s spy, subscribe to the outputs given through the `spyOutputs`
|
|
50
|
-
option and return them in the `spies` property, in a type-safe way showing only the outputs that are spied on.
|
|
51
|
-
|
|
52
|
-
Note that the `spyOutputs` is type-safe and will only allow properties that exist on the component.
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
import { expect, test } from '@jscutlery/playwright-ct-angular';
|
|
56
|
-
import { NameEditorComponent } from './name-editor.component';
|
|
57
|
-
|
|
58
|
-
test('<jc-name-editor> should be polite', async ({ mount }) => {
|
|
59
|
-
const locator = await mount(NameEditorComponent, {spyOutputs: ['nameChange']});
|
|
60
|
-
|
|
61
|
-
await locator.getByLabel('Name').type('Edouard');
|
|
62
|
-
|
|
63
|
-
expect(locator.spies.nameChange).lastCalledWith('Edouard');
|
|
64
|
-
});
|
|
65
|
-
```
|
|
66
|
-
|
|
67
79
|
### Passing output callbacks
|
|
68
80
|
|
|
69
|
-
|
|
81
|
+
You can also pass custom output callback functions for some extreme cases or if you want to use a custom spy
|
|
82
|
+
implementation for example or just debug.
|
|
83
|
+
|
|
70
84
|
```ts
|
|
71
85
|
await mount(NameEditorComponent, {
|
|
72
|
-
|
|
86
|
+
on: {
|
|
73
87
|
nameChange(name) {
|
|
74
88
|
console.log(name);
|
|
75
89
|
}
|
|
@@ -89,7 +103,7 @@ import { RecipeSearchTestContainer } from './recipe-search.test-container';
|
|
|
89
103
|
|
|
90
104
|
test('...', async ({ mount }) => {
|
|
91
105
|
await mount(RecipeSearchTestContainer, {
|
|
92
|
-
|
|
106
|
+
props: {
|
|
93
107
|
recipes: [
|
|
94
108
|
beer,
|
|
95
109
|
burger
|
|
@@ -112,20 +126,24 @@ test('...', async ({ mount }) => {
|
|
|
112
126
|
],
|
|
113
127
|
})
|
|
114
128
|
export class RecipeSearchTestContainer {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
this.
|
|
119
|
-
}
|
|
129
|
+
recipes = input<Recipe[]>([]);
|
|
130
|
+
#repo = inject(RecipeRepositoryFake);
|
|
131
|
+
#syncRecipesWithRepo = effect(() => {
|
|
132
|
+
this.#repo.setRecipes(this.recipes());
|
|
133
|
+
});
|
|
120
134
|
}
|
|
121
135
|
|
|
122
136
|
/* Cf. https://github.com/jscutlery/devkit/tree/main/tests/playwright-ct-angular-wide/src/testing/recipe-repository.fake.ts
|
|
123
137
|
* for a better example. */
|
|
124
138
|
class RecipeRepositoryFake implements RecipeRepositoryDef {
|
|
125
|
-
recipes: Recipe[] = [];
|
|
139
|
+
#recipes: Recipe[] = [];
|
|
126
140
|
|
|
127
141
|
searchRecipes() {
|
|
128
|
-
return defer(() => of(this
|
|
142
|
+
return defer(() => of(this.#recipes));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
setRecipes(recipes: Recipe[]) {
|
|
146
|
+
this.#recipes = recipes;
|
|
129
147
|
}
|
|
130
148
|
}
|
|
131
149
|
```
|
|
@@ -134,30 +152,36 @@ class RecipeRepositoryFake implements RecipeRepositoryDef {
|
|
|
134
152
|
|
|
135
153
|
### Shared Styles
|
|
136
154
|
|
|
137
|
-
In order to import styles that are shared between
|
|
138
|
-
|
|
155
|
+
In order to import styles that are shared between your tests, you can do so by importing them in `playwright/index.ts`.
|
|
156
|
+
You can also customize the shared `playwright/index.html` nearby.
|
|
139
157
|
|
|
140
158
|
### Specific Styles
|
|
141
159
|
|
|
142
|
-
If
|
|
160
|
+
If you want to load some specific styles for a single test, you might prefer using a test container component:
|
|
161
|
+
|
|
143
162
|
```ts
|
|
144
163
|
import styles from './some-styles.css';
|
|
164
|
+
|
|
145
165
|
@Component({
|
|
146
166
|
template: '<jc-greetings></jc-greetings>',
|
|
147
167
|
encapsulation: ViewEncapsulation.None,
|
|
148
168
|
styles: [styles]
|
|
149
169
|
})
|
|
150
|
-
class GreetingsTestContainer {
|
|
170
|
+
class GreetingsTestContainer {
|
|
171
|
+
}
|
|
151
172
|
```
|
|
152
173
|
|
|
153
174
|
### Angular Material & Angular Libraries with styles
|
|
154
175
|
|
|
155
176
|
As mentioned in [Versatile Angular Style Blog Post](https://marmicode.io/blog/versatile-angular),
|
|
156
|
-
Angular Material and other Angular libraries might use
|
|
177
|
+
Angular Material and other Angular libraries might use
|
|
178
|
+
a [Conditional "style" Export](https://nodejs.org/api/packages.html#conditional-exports)
|
|
157
179
|
that allows us to import prebuilt styles
|
|
158
|
-
_(
|
|
180
|
+
_(
|
|
181
|
+
Cf. [Angular Package Format](https://angular.io/guide/angular-package-format) [managing assets in a library](https://angular.io/guide/creating-libraries#managing-assets-in-a-library))_.
|
|
159
182
|
|
|
160
183
|
In that case, we can add the following configuration to our `playwright-ct.config.ts`:
|
|
184
|
+
|
|
161
185
|
```ts
|
|
162
186
|
const config: PlaywrightTestConfig = {
|
|
163
187
|
// ...
|
|
@@ -174,28 +198,34 @@ const config: PlaywrightTestConfig = {
|
|
|
174
198
|
```
|
|
175
199
|
|
|
176
200
|
## More examples
|
|
177
|
-
|
|
201
|
+
|
|
202
|
+
Cf. [/tests/playwright-ct-angular-demo/src](https://github.com/jscutlery/devkit/tree/main/tests/playwright-ct-angular-demo/src)
|
|
178
203
|
|
|
179
204
|
# ⚠️ Known Limitations
|
|
180
205
|
|
|
181
|
-
The way Playwright Component Testing works is different from the way things work with Karma, Jest, Vitest, Cypress
|
|
182
|
-
|
|
206
|
+
The way Playwright Component Testing works is different from the way things work with Karma, Jest, Vitest, Cypress
|
|
207
|
+
etc...
|
|
208
|
+
Playwright Component Testing tests run in a Node.js environment and control the browser through Chrome DevTools
|
|
209
|
+
Protocol, while the component is rendered in a browser.
|
|
183
210
|
|
|
184
|
-
This causes a couple of limitations as we can't directly access the `TestBed's
|
|
185
|
-
and we can only exchange serializable data with the component
|
|
211
|
+
This causes a couple of limitations as we can't directly access the `TestBed`'s or the component's internals,
|
|
212
|
+
and **we can only exchange serializable data with the component**.
|
|
186
213
|
|
|
187
214
|
## 🪄 The Magic Behind the Scenes
|
|
188
215
|
|
|
189
216
|
The magical workaround behind the scenes is that at build time:
|
|
217
|
+
|
|
190
218
|
1. Playwright analyses all the calls to `mount()`,
|
|
191
|
-
2. it grabs the
|
|
219
|
+
2. it grabs the arguments (e.g. the component class),
|
|
192
220
|
3. replaces the component class with a unique string (constructed from the component class name and es-module),
|
|
193
|
-
4. adds the component's
|
|
194
|
-
5. and finally creates a map matching each unique string to the right
|
|
221
|
+
4. adds the component's ES module to Vite entrypoints,
|
|
222
|
+
5. and finally creates a map matching each unique string to the right ES module.
|
|
195
223
|
|
|
196
|
-
This way, when calling `mount()`, Playwright
|
|
224
|
+
This way, when calling `mount()`, Playwright will communicate the unique string to the browser who will know which
|
|
225
|
+
ES module to load.
|
|
197
226
|
|
|
198
227
|
Cf. https://youtu.be/y3YxX4sFJbM
|
|
228
|
+
|
|
199
229
|
Cf. https://github.com/microsoft/playwright/blob/cac67fb94f2c8a0ee82878054c39790e660f17ca/packages/playwright-test/src/tsxTransform.ts#L153
|
|
200
230
|
|
|
201
231
|
## It is currently impossible to...
|
|
@@ -212,44 +242,30 @@ await mount(cmp);
|
|
|
212
242
|
|
|
213
243
|
```ts
|
|
214
244
|
// 🛑 this won't work
|
|
215
|
-
test(MyComponent.name, async ({ mount }) => {
|
|
245
|
+
test(MyComponent.name, async ({ mount }) => {
|
|
246
|
+
});
|
|
216
247
|
```
|
|
217
248
|
|
|
218
249
|
### ...declare components in the same file.
|
|
219
250
|
|
|
220
251
|
```ts
|
|
221
252
|
// 🛑 this won't work
|
|
222
|
-
@Component({...})
|
|
223
|
-
class GreetingsComponent {
|
|
253
|
+
@Component({ ... })
|
|
254
|
+
class GreetingsComponent {
|
|
255
|
+
}
|
|
224
256
|
|
|
225
|
-
test('
|
|
257
|
+
test('should work', async ({ mount }) => {
|
|
226
258
|
await mount(GreetingsComponent);
|
|
227
259
|
});
|
|
228
260
|
```
|
|
229
261
|
|
|
230
|
-
|
|
231
|
-
This makes the following impossible:
|
|
232
|
-
- passing providers to the `mount()` function
|
|
233
|
-
- passing modules to the `mount()` function (this is what currently makes the usage of mounting templates impossible)
|
|
234
|
-
- use non-standalone components
|
|
235
|
-
|
|
236
|
-
### ...use non-[Versatile Angular Style](https://marmicode.io/blog/versatile-angular)
|
|
237
|
-
We'll need a vite plugin to support traditional DI, external templates and stylesheets etc...
|
|
238
|
-
|
|
239
|
-
## 🔮 Future workarounds
|
|
262
|
+
# 📦 Setup
|
|
240
263
|
|
|
241
|
-
|
|
242
|
-
we can think of a couple of workarounds like using a vite plugin like **Brandon Roberts' [vite-plugin-angular](https://github.com/analogjs/analog/tree/main/packages/vite-plugin-angular)**
|
|
243
|
-
|
|
244
|
-
We could also implement some custom transform that registers the providers and import modules, like Playwright does for the component class.
|
|
245
|
-
|
|
246
|
-
# Setup
|
|
247
|
-
|
|
248
|
-
## 📦 Install
|
|
264
|
+
### 1. Install
|
|
249
265
|
|
|
250
266
|
```sh
|
|
251
267
|
# You can run this command in an existing workspace.
|
|
252
|
-
|
|
268
|
+
npm create playwright -- --ct
|
|
253
269
|
|
|
254
270
|
# Choose React
|
|
255
271
|
|
|
@@ -259,28 +275,46 @@ yarn create playwright --ct # or npm init playwright@latest -- --ct
|
|
|
259
275
|
# svelte
|
|
260
276
|
# solid
|
|
261
277
|
|
|
262
|
-
|
|
278
|
+
npm add -D @jscutlery/playwright-ct-angular @jscutlery/swc-angular unplugin-swc
|
|
279
|
+
npm uninstall -D @playwright/experimental-ct-react
|
|
263
280
|
```
|
|
264
281
|
|
|
265
|
-
|
|
282
|
+
### 2. Configure
|
|
283
|
+
|
|
284
|
+
- Update `playwright-ct.config.ts` and replace:
|
|
266
285
|
|
|
267
|
-
Update `playwright-ct-config.ts` and replace:
|
|
268
286
|
```ts
|
|
269
|
-
import
|
|
270
|
-
import { devices } from '@playwright/experimental-ct-react';
|
|
287
|
+
import { defineConfig, devices } from '@playwright/experimental-ct-react';
|
|
271
288
|
```
|
|
272
289
|
|
|
273
290
|
with
|
|
274
291
|
|
|
275
292
|
```ts
|
|
276
|
-
import
|
|
277
|
-
import {
|
|
293
|
+
import { defineConfig, devices } from '@jscutlery/playwright-ct-angular';
|
|
294
|
+
import { swcAngularUnpluginOptions } from '@jscutlery/swc-angular'
|
|
295
|
+
import swc from 'unplugin-swc';
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
- Configure vite plugin:
|
|
299
|
+
|
|
300
|
+
```ts
|
|
301
|
+
export default defineConfig({
|
|
302
|
+
use: {
|
|
303
|
+
// ...
|
|
304
|
+
ctViteConfig: {
|
|
305
|
+
// ...
|
|
306
|
+
plugins: [
|
|
307
|
+
swc.vite(swcAngularUnpluginOptions())
|
|
308
|
+
]
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
});
|
|
278
312
|
```
|
|
279
313
|
|
|
280
|
-
### Change tests extension
|
|
314
|
+
### 3. Change tests extension
|
|
281
315
|
|
|
282
316
|
In order to avoid collisions with other tests (e.g. Jest / Vitest),
|
|
283
|
-
|
|
317
|
+
You can replace the default matching extension `.spec.ts` with `.pw.ts`:
|
|
284
318
|
|
|
285
319
|
```ts
|
|
286
320
|
const config: PlaywrightTestConfig = {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Microsoft Corporation.
|
|
3
4
|
*
|
|
@@ -5,7 +6,7 @@
|
|
|
5
6
|
* you may not use this file except in compliance with the License.
|
|
6
7
|
* You may obtain a copy of the License at
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
10
|
*
|
|
10
11
|
* Unless required by applicable law or agreed to in writing, software
|
|
11
12
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
@@ -13,5 +14,7 @@
|
|
|
13
14
|
* See the License for the specific language governing permissions and
|
|
14
15
|
* limitations under the License.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
const { program } = require('@playwright/experimental-ct-core/lib/program');
|
|
19
|
+
|
|
20
|
+
program.parse(process.argv);
|
package/hooks.cjs.js
CHANGED
|
@@ -2,31 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Copyright (c) Microsoft Corporation.
|
|
7
|
-
*
|
|
8
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
-
* you may not use this file except in compliance with the License.
|
|
10
|
-
* You may obtain a copy of the License at
|
|
11
|
-
*
|
|
12
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
-
*
|
|
14
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
-
* See the License for the specific language governing permissions and
|
|
18
|
-
* limitations under the License.
|
|
19
|
-
*/
|
|
20
5
|
const __pw_hooks_before_mount = [];
|
|
21
6
|
const __pw_hooks_after_mount = [];
|
|
22
7
|
window['__pw_hooks_before_mount'] = __pw_hooks_before_mount;
|
|
23
8
|
window['__pw_hooks_after_mount'] = __pw_hooks_after_mount;
|
|
24
|
-
|
|
9
|
+
function beforeMount(callback) {
|
|
25
10
|
__pw_hooks_before_mount.push(callback);
|
|
26
|
-
}
|
|
27
|
-
|
|
11
|
+
}
|
|
12
|
+
function afterMount(callback) {
|
|
28
13
|
__pw_hooks_after_mount.push(callback);
|
|
29
|
-
}
|
|
14
|
+
}
|
|
30
15
|
|
|
31
16
|
exports.afterMount = afterMount;
|
|
32
17
|
exports.beforeMount = beforeMount;
|
package/hooks.esm.js
CHANGED
|
@@ -1,27 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
1
|
const __pw_hooks_before_mount = [];
|
|
17
2
|
const __pw_hooks_after_mount = [];
|
|
18
3
|
window['__pw_hooks_before_mount'] = __pw_hooks_before_mount;
|
|
19
4
|
window['__pw_hooks_after_mount'] = __pw_hooks_after_mount;
|
|
20
|
-
|
|
5
|
+
function beforeMount(callback) {
|
|
21
6
|
__pw_hooks_before_mount.push(callback);
|
|
22
|
-
}
|
|
23
|
-
|
|
7
|
+
}
|
|
8
|
+
function afterMount(callback) {
|
|
24
9
|
__pw_hooks_after_mount.push(callback);
|
|
25
|
-
}
|
|
10
|
+
}
|
|
26
11
|
|
|
27
12
|
export { afterMount, beforeMount };
|
package/index.cjs.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var experimentalCtCore = require('@playwright/experimental-ct-core');
|
|
9
|
-
var path = require('path');
|
|
5
|
+
var path = require('node:path');
|
|
6
|
+
var playwrightCtCore = require('@playwright/experimental-ct-core');
|
|
7
|
+
var test$1 = require('@playwright/test');
|
|
10
8
|
|
|
11
9
|
function _interopNamespace(e) {
|
|
12
10
|
if (e && e.__esModule) return e;
|
|
@@ -26,87 +24,44 @@ function _interopNamespace(e) {
|
|
|
26
24
|
return Object.freeze(n);
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
var playwright__namespace = /*#__PURE__*/_interopNamespace(playwright);
|
|
30
27
|
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
28
|
+
var playwrightCtCore__namespace = /*#__PURE__*/_interopNamespace(playwrightCtCore);
|
|
31
29
|
|
|
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
|
-
/* 2. ...then use it as an output... */
|
|
62
|
-
await mount(component, {
|
|
63
|
-
...options,
|
|
64
|
-
outputs: {
|
|
65
|
-
...options.outputs,
|
|
66
|
-
...spies,
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
/* Grab a locator to the TestBed's root element.
|
|
70
|
-
* We are loading a fresh new page for each test
|
|
71
|
-
* so the id should always be "root0".
|
|
72
|
-
* Otherwise, we'd have to hack our way and somehow grab all
|
|
73
|
-
* the `#root*`, sort them and grab the last one.
|
|
74
|
-
* As a matter of fact, we can't grab a reference to the fixture. */
|
|
75
|
-
const locator = page.locator('#root0');
|
|
76
|
-
/* Add spies to the returned locator. */
|
|
77
|
-
return Object.assign(locator, { spies });
|
|
78
|
-
});
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
const expect = playwright__namespace.expect;
|
|
82
|
-
const devices = playwright__namespace.devices;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Copyright (c) Microsoft Corporation.
|
|
86
|
-
*
|
|
87
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
88
|
-
* you may not use this file except in compliance with the License.
|
|
89
|
-
* You may obtain a copy of the License at
|
|
90
|
-
*
|
|
91
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
92
|
-
*
|
|
93
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
94
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
95
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
96
|
-
* See the License for the specific language governing permissions and
|
|
97
|
-
* limitations under the License.
|
|
98
|
-
*/
|
|
99
|
-
function plugin() {
|
|
100
|
-
/* Only fetch upon request to avoid resolution in workers. */
|
|
101
|
-
const { createPlugin,
|
|
102
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
103
|
-
} = require('@playwright/experimental-ct-core/lib/vitePlugin');
|
|
104
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
105
|
-
return createPlugin(path__namespace.join(__dirname, 'register-source.mjs'), () => { });
|
|
106
|
-
}
|
|
107
|
-
const defineConfig = (config) => experimentalCtCore.defineConfig({ ...config, _plugins: [plugin] });
|
|
30
|
+
/* @hack `test` is not exported in the type definition of `@playwright/experimental-ct-core`. */
|
|
31
|
+
// @eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
const test = playwrightCtCore__namespace.test;
|
|
33
|
+
const defineConfig = (config, ...configs) => {
|
|
34
|
+
const original = playwrightCtCore__namespace.defineConfig({
|
|
35
|
+
...config,
|
|
36
|
+
'@playwright/test': {
|
|
37
|
+
packageJSON: require.resolve('./package.json'),
|
|
38
|
+
},
|
|
39
|
+
'@playwright/experimental-ct-core': {
|
|
40
|
+
registerSourceFile: path__namespace.join(__dirname, 'register-source.mjs'),
|
|
41
|
+
},
|
|
42
|
+
}, ...configs);
|
|
43
|
+
/* @hack for some weird reason, if we do not require the babel plugin here,
|
|
44
|
+
* babel loads an empty object instead of the default exported function. */
|
|
45
|
+
require('@jscutlery/playwright-ct-angular/transform-angular');
|
|
46
|
+
return {
|
|
47
|
+
...original,
|
|
48
|
+
'@playwright/test': {
|
|
49
|
+
...original['@playwright/test'],
|
|
50
|
+
babelPlugins: [
|
|
51
|
+
...original['@playwright/test'].babelPlugins,
|
|
52
|
+
[require.resolve('@jscutlery/playwright-ct-angular/transform-angular')],
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
};
|
|
108
57
|
|
|
58
|
+
Object.defineProperty(exports, 'devices', {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
get: function () { return test$1.devices; }
|
|
61
|
+
});
|
|
62
|
+
Object.defineProperty(exports, 'expect', {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
get: function () { return test$1.expect; }
|
|
65
|
+
});
|
|
109
66
|
exports.defineConfig = defineConfig;
|
|
110
|
-
exports.devices = devices;
|
|
111
|
-
exports.expect = expect;
|
|
112
67
|
exports.test = test;
|