Skip to content

Commit cb0b00a

Browse files
authored
feat(playwright-ct-angular): ✨ allow zoneless testing (#427)
- remove zone.js from register-source - make demo zoneless - update docs
1 parent 45dbdac commit cb0b00a

7 files changed

Lines changed: 48 additions & 13 deletions

File tree

packages/playwright-ct-angular/README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ Cf. https://youtu.be/y3YxX4sFJbM
281281

282282
Cf. https://github.com/microsoft/playwright/blob/cac67fb94f2c8a0ee82878054c39790e660f17ca/packages/playwright-test/src/tsxTransform.ts#L153
283283

284-
###
284+
###
285285

286286
# 📦 Setup
287287

@@ -347,3 +347,34 @@ const config: PlaywrightTestConfig = {
347347
...
348348
}
349349
```
350+
351+
### 4. Choose between zoneful or zoneless testing
352+
353+
#### Zoneful Testing
354+
355+
If you want to use zoneful testing, you have to import `zone.js` in your `playwright/index.ts`:
356+
357+
```ts
358+
// playwright/index.ts
359+
import 'zone.js';
360+
```
361+
362+
#### Zoneless Testing
363+
364+
For zoneless testing, you have to provide `provideExperimentalZonelessChangeDetection()` in your `playwright/index.ts`:
365+
366+
```ts
367+
// playwright/index.ts
368+
import { provideExperimentalZonelessChangeDetection } from '@angular/core';
369+
import { beforeMount } from '@jscutlery/playwright-ct-angular/hooks';
370+
371+
beforeMount(async ({ TestBed }) => {
372+
TestBed.configureTestingModule({
373+
providers: [
374+
provideExperimentalZonelessChangeDetection(),
375+
],
376+
});
377+
});
378+
```
379+
380+
Cf. [Zoneless Example's `playwright/index.ts`](../../tests/playwright-ct-angular-demo/playwright/index.ts)

packages/playwright-ct-angular/src/register-source.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import '@angular/compiler';
2-
import 'zone.js';
31
import { Component, reflectComponentType } from '@angular/core';
42
import { ComponentFixtureAutoDetect, getTestBed, TestBed, TestComponentRenderer } from '@angular/core/testing';
53
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1+
import '@angular/compiler';
12
import '@angular/material/prebuilt-themes/indigo-pink.css';
3+
import { provideExperimentalZonelessChangeDetection } from '@angular/core';
4+
import { provideAnimations } from '@angular/platform-browser/animations';
5+
import { beforeMount } from '@jscutlery/playwright-ct-angular/hooks';
6+
7+
beforeMount(async ({ TestBed }) => {
8+
TestBed.configureTestingModule({
9+
providers: [
10+
provideAnimations(),
11+
provideExperimentalZonelessChangeDetection(),
12+
],
13+
});
14+
});

tests/playwright-ct-angular-demo/src/recipe-filter.component.pw.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
} from '@jscutlery/playwright-ct-angular';
66
import { RecipeFilter } from './recipe-filter';
77
import { RecipeFilterComponent } from './recipe-filter.component';
8-
import { TESTING_PROVIDERS } from './testing/providers';
98

109
test.describe('<wm-recipe-filter>', () => {
1110
test('should search recipes without keyword on load', async ({ mount }) => {
@@ -24,7 +23,6 @@ test.describe('<wm-recipe-filter>', () => {
2423
async function renderRecipeFilter({ mount }: ComponentFixtures) {
2524
const filterChangeCalls: RecipeFilter[] = [];
2625
const locator = await mount(RecipeFilterComponent, {
27-
providers: [TESTING_PROVIDERS],
2826
on: {
2927
filterChange(filter: RecipeFilter) {
3028
filterChangeCalls.push(filter);

tests/playwright-ct-angular-demo/src/recipe-search.component.pw.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
test,
55
} from '@jscutlery/playwright-ct-angular';
66
import { RecipeSearchTestContainer } from './recipe-search.test-container';
7-
import { TESTING_PROVIDERS } from './testing/providers';
87

98
test.describe('<wm-recipe-search>', () => {
109
test('should search recipes without keyword on load', async ({ mount }) => {
@@ -29,14 +28,12 @@ test.describe('<wm-recipe-search>', () => {
2928
});
3029

3130
async function renderSearchComponent({ mount }: ComponentFixtures) {
32-
const locator = await mount(RecipeSearchTestContainer, {
33-
providers: [TESTING_PROVIDERS],
34-
});
31+
const locator = await mount(RecipeSearchTestContainer);
3532

3633
return {
3734
recipeTitleLocator: locator.getByTestId('recipe-name'),
3835
async updateFilter({ keywords }: { keywords: string }) {
39-
await locator.getByLabel('Keywords').type(keywords);
36+
await locator.getByLabel('Keywords').fill(keywords);
4037
},
4138
async verifyScreenshot(name: string) {
4239
/* Wait for images to load. */

tests/playwright-ct-angular-demo/src/testing/providers.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/playwright-ct-angular-wide/playwright/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'zone.js';
12
import { beforeMount } from '@jscutlery/playwright-ct-angular/hooks';
23
import { TOKEN } from '../src/inject.component';
34

0 commit comments

Comments
 (0)