You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+81-31
Original file line number
Diff line number
Diff line change
@@ -8,55 +8,90 @@
8
8
Stencil Playwright is a testing adapter package that allows developers to easily use the [Playwright testing framework](https://playwright.dev/docs/intro)
9
9
in their Stencil project.
10
10
11
-
For full documentation, please see the [Playwright testing docs on the official Stencil site](https://stenciljs.com/docs/next/testing/playwright/overview).
11
+
For full documentation, please see the [Playwright testing docs on the official Stencil site](https://stenciljs.com/docs/testing/playwright/overview).
12
12
13
13
## Getting Started
14
14
15
-
1. Install the necessary packages using your preferred package manager:
15
+
1. Install the necessary dependencies:
16
16
17
17
```bash
18
18
npm i @stencil/playwright @playwright/test --save-dev
19
19
```
20
20
21
-
1. Install Playwright's browser binaries:
21
+
1. Install the Playwright browser binaries:
22
22
23
23
```bash
24
24
npx playwright install
25
25
```
26
26
27
-
1. Create a `playwright.config.ts` file. The `@stencil/playwright` package offers a utility function to quickly create a default configuration that should
28
-
work for most Stencil projects:
27
+
1. Create a Playwright config at the root of your Stencil project:
// Add custom Stencil matchers to Playwright assertions
36
34
expect.extend(matchers);
37
35
38
-
exportdefaultcreateConfig();
36
+
exportdefaultcreateConfig({
37
+
// Overwrite Playwright config options here
38
+
});
39
39
```
40
40
41
-
1. At this point, any tests can be executed using `npx playwright test` (or by updating the project's test command in the `package.json`). By default, Playwright's test matcher
42
-
is configured to run all tests matching the pattern `*.e2e.ts`. This can be changed by overriding the default matcher using the
1. update your project's `tsconfig.json` to add the `ESNext.Disposable` option to the `lib` array:
50
48
51
-
expect.extend(matchers);
49
+
```ts title="tsconfig.json"
50
+
{
51
+
lib: [
52
+
...,
53
+
"ESNext.Disposable"
54
+
],
55
+
...
56
+
}
57
+
```
52
58
53
-
exportdefaultcreateConfig({
54
-
// Change which test files Playwright will execute
55
-
testMatch: '*.spec.ts',
56
-
// Any other Playwright config option can also be overridden
57
-
});
59
+
> [!NOTE]
60
+
> This will resolve a build error related to `Symbol.asyncDispose`. If this is not added, tests may fail to run since the Stencil dev server will be unable
61
+
> to start due to the build error.
62
+
63
+
1. Ensure the Stencil project has a [`www` output target](https://stenciljs.com/docs/www). Playwright relies on pre-compiled output running in a dev server
64
+
to run tests against. When using the `createConfig()` helper, a configuration for the dev server will be automatically created based on
65
+
the Stencil project's `www` output target config and [dev server config](https://stenciljs.com/docs/dev-server). If no `www` output target is specified,
66
+
tests will not be able to run.
67
+
68
+
1. Add the `copy` option to the `www` output target config:
69
+
70
+
```ts title="stencil.config.ts"
71
+
{
72
+
type: 'www',
73
+
serviceWorker: null,
74
+
copy: [{ src: '**/*.html' }, { src: '**/*.css' }]
75
+
}
58
76
```
59
77
78
+
This will clone all HTML and CSS files to the `www` output directory so they can be served by the dev server. If you put all testing related
79
+
files in specific directory(s), you can update the `copy` task glob patterns to only copy those files:
Returns a [Playwright test configuration](https://playwright.dev/docs/test-configuration#introduction).
128
163
129
-
`overrides`, as the name implies, will overwrite the default configuration value(s) if supplied. These values can include any valid Playwright config option as well
130
-
as some options to override specific values in the config options related to the Stencil integration:
131
-
132
-
-`webServerCommand`: This can be specified to change the command that will run to start the Stencil dev server. Defaults to `npm start -- --no-open`.
133
-
-`webServerTimeout`: This can be specified to change the amount of time Playwright will wait for the dev server to start. Defaults to 60 seconds.
164
+
`overrides`, as the name implies, will overwrite the default configuration value(s) if supplied. These values can include any valid Playwright config option. Changing
165
+
option values in a nested object will use a "deep merge" to combine the default and overridden values. So, creating a config like the following:
// Only timeout gets overridden, not the entire object
197
+
timeout: 30000,
198
+
},
199
+
}
200
+
```
201
+
152
202
### `test`
153
203
154
204
`test` designates which tests will be executed by Playwright. See the [Playwright API documentation](https://playwright.dev/docs/api/class-test#test-call) regarding usage.
0 commit comments