Skip to content

Commit 3ae5de8

Browse files
authored
chore(readme): sync w/ docs content & add config naming limitation (#40)
* sync readme with docs content * config naming limitation admonition * PR feedback
1 parent ead95cd commit 3ae5de8

File tree

1 file changed

+81
-31
lines changed

1 file changed

+81
-31
lines changed

README.md

+81-31
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,90 @@
88
Stencil Playwright is a testing adapter package that allows developers to easily use the [Playwright testing framework](https://playwright.dev/docs/intro)
99
in their Stencil project.
1010

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).
1212

1313
## Getting Started
1414

15-
1. Install the necessary packages using your preferred package manager:
15+
1. Install the necessary dependencies:
1616

1717
```bash
1818
npm i @stencil/playwright @playwright/test --save-dev
1919
```
2020

21-
1. Install Playwright's browser binaries:
21+
1. Install the Playwright browser binaries:
2222

2323
```bash
2424
npx playwright install
2525
```
2626

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:
2928

3029
```ts
31-
// playwright.config.ts
32-
3330
import { expect } from '@playwright/test';
3431
import { matchers, createConfig } from '@stencil/playwright';
3532

33+
// Add custom Stencil matchers to Playwright assertions
3634
expect.extend(matchers);
3735

38-
export default createConfig();
36+
export default createConfig({
37+
// Overwrite Playwright config options here
38+
});
3939
```
4040

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
43-
[`createConfig()` function](#createconfigoverrides-createstencilplaywrightconfigoptions-promiseplaywrighttestconfig):
41+
The `createConfig()` function is a utility that will create a default Playwright configuration based on your project's Stencil config. Read
42+
more about how to use this utility in the [API section](#createconfigoverrides-playwrighttestconfig-promiseplaywrighttestconfig).
4443

45-
```ts
46-
// playwright.config.ts
44+
> [!NOTE]
45+
> For `createConfig()` to work correctly, your Stencil config must be named either `stencil.config.ts` or `stencil.config.js`.
4746
48-
import { expect } from '@playwright/test';
49-
import { matchers, createConfig } from '@stencil/playwright';
47+
1. update your project's `tsconfig.json` to add the `ESNext.Disposable` option to the `lib` array:
5048

51-
expect.extend(matchers);
49+
```ts title="tsconfig.json"
50+
{
51+
lib: [
52+
...,
53+
"ESNext.Disposable"
54+
],
55+
...
56+
}
57+
```
5258

53-
export default createConfig({
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+
}
5876
```
5977

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:
80+
81+
```ts title="stencil.config.ts"
82+
{
83+
type: 'www',
84+
serviceWorker: null,
85+
copy: [{ src: '**/test/*.html' }, { src: '**/test/*.css' }]
86+
}
87+
```
88+
89+
> [!NOTE]
90+
> If the `copy` property is not set, you will not be able to use the `page.goto` testing pattern!
91+
92+
1. Test away! Check out the [e2e testing page on the Stencil docs](https://stenciljs.com/docs/testing/playwright/e2e-testing) for more help
93+
getting started writing tests.
94+
6095
## Testing Patterns
6196

6297
### `page.goto()`
@@ -122,19 +157,14 @@ test.describe('my-component', () => {
122157

123158
## API
124159

125-
### `createConfig(overrides?: CreateStencilPlaywrightConfigOptions): Promise<PlaywrightTestConfig>`
160+
### `createConfig(overrides?: PlaywrightTestConfig): Promise<PlaywrightTestConfig>`
126161

127162
Returns a [Playwright test configuration](https://playwright.dev/docs/test-configuration#introduction).
128163

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:
134166

135167
```ts
136-
// playwright.config.ts
137-
138168
import { expect } from '@playwright/test';
139169
import { matchers, createConfig } from '@stencil/playwright';
140170

@@ -144,11 +174,31 @@ export default createConfig({
144174
// Change which test files Playwright will execute
145175
testMatch: '*.spec.ts',
146176

147-
// Only wait max 30 seconds for server to start
148-
webServerTimeout: 30000,
177+
webServer: {
178+
// Only wait max 30 seconds for server to start
179+
timeout: 30000,
180+
},
149181
});
150182
```
151183

184+
Will result in:
185+
186+
```ts
187+
{
188+
testMatch: '*.spec.ts',
189+
use: {
190+
baseURL: 'http://localhost:3333',
191+
},
192+
webServer: {
193+
command: 'stencil build --dev --watch --serve --no-open',
194+
url: 'http://localhost:3333/ping',
195+
reuseExistingServer: !process.env.CI,
196+
// Only timeout gets overridden, not the entire object
197+
timeout: 30000,
198+
},
199+
}
200+
```
201+
152202
### `test`
153203

154204
`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

Comments
 (0)