@stencil/playwright 0.1.0 → 0.2.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 CHANGED
@@ -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:
29
28
 
30
29
  ```ts
31
- // playwright.config.ts
32
-
33
30
  import { expect } from '@playwright/test';
34
- import { matchers, createStencilPlaywrightConfig } from '@stencil/playwright';
31
+ import { matchers, createConfig } from '@stencil/playwright';
35
32
 
33
+ // Add custom Stencil matchers to Playwright assertions
36
34
  expect.extend(matchers);
37
35
 
38
- export default createStencilPlaywrightConfig();
36
+ export default createConfig({
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
43
- [`createStencilPlaywrightConfig()` function](#createstencilplaywrightconfigoverrides-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).
44
43
 
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`.
47
46
 
48
- import { expect } from '@playwright/test';
49
- import { matchers, createStencilPlaywrightConfig } from '@stencil/playwright';
47
+ 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
- export default createStencilPlaywrightConfig({
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
+ }
76
+ ```
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:
80
+
81
+ ```ts title="stencil.config.ts"
82
+ {
83
+ type: 'www',
84
+ serviceWorker: null,
85
+ copy: [{ src: '**/test/*.html' }, { src: '**/test/*.css' }]
86
+ }
58
87
  ```
59
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
+
60
95
  ## Testing Patterns
61
96
 
62
97
  ### `page.goto()`
@@ -122,33 +157,48 @@ test.describe('my-component', () => {
122
157
 
123
158
  ## API
124
159
 
125
- ### `createStencilPlaywrightConfig(overrides?: CreateStencilPlaywrightConfigOptions): Promise<PlaywrightTestConfig>`
160
+ ### `createConfig(overrides?: PlaywrightTestConfig): Promise<PlaywrightTestConfig>`
126
161
 
127
162
  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:
134
166
 
135
167
  ```ts
136
- // playwright.config.ts
137
-
138
168
  import { expect } from '@playwright/test';
139
- import { matchers, createStencilPlaywrightConfig } from '@stencil/playwright';
169
+ import { matchers, createConfig } from '@stencil/playwright';
140
170
 
141
171
  expect.extend(matchers);
142
172
 
143
- export default createStencilPlaywrightConfig({
173
+ export default createConfig({
144
174
  // Change which test files Playwright will execute
145
175
  testMatch: '*.spec.ts',
146
176
 
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
+ },
149
181
  });
150
182
  ```
151
183
 
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
+
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.
@@ -1,22 +1,7 @@
1
1
  import { PlaywrightTestConfig } from '@playwright/test';
2
- /**
3
- * Options for creating a Playwright config for Stencil projects. This extends the default Playwright config
4
- * with some additional options specific to overriding options for the Playwright dev server.
5
- */
6
- export type CreateStencilPlaywrightConfigOptions = Partial<PlaywrightTestConfig> & {
7
- /**
8
- * The command to execute to start the dev server. This can be a bash command or a local npm script.
9
- *
10
- * Defaults to `npm start -- --no-open`.
11
- */
12
- webServerCommand?: string;
13
- /**
14
- * The maximum time to wait for the dev server to start before aborting.
15
- *
16
- * Defaults to `60000` (60 seconds).
17
- */
18
- webServerTimeout?: number;
19
- };
2
+ type DeepPartial<T> = T extends object ? {
3
+ [P in keyof T]?: DeepPartial<T[P]>;
4
+ } : T;
20
5
  /**
21
6
  * Helper function to easily create a Playwright config for Stencil projects. This function will
22
7
  * automatically load the Stencil config meta to set default values for the Playwright config respecting the
@@ -26,4 +11,5 @@ export type CreateStencilPlaywrightConfigOptions = Partial<PlaywrightTestConfig>
26
11
  * @param overrides Values to override in the default config. Any Playwright config option can be overridden.
27
12
  * @returns A {@link PlaywrightTestConfig} object
28
13
  */
29
- export declare const createStencilPlaywrightConfig: (overrides?: CreateStencilPlaywrightConfigOptions) => Promise<PlaywrightTestConfig>;
14
+ export declare const createConfig: (overrides?: DeepPartial<PlaywrightTestConfig>) => Promise<PlaywrightTestConfig>;
15
+ export {};