Skip to content

Commit d4b295d

Browse files
Cherry Pick "feat(test-runner): mark launch as experimental (#7757)" #7770
Cherry pick of #7757
1 parent dd4d0c6 commit d4b295d

File tree

6 files changed

+11
-87
lines changed

6 files changed

+11
-87
lines changed

docs/src/test-advanced.md

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ These options would be typically different between local development and CI oper
4242
- `reportSlowTests: { max: number, threshold: number } | null` - Whether to report slow tests. When `null`, slow tests are not reported. Otherwise, tests that took more than `threshold` milliseconds are reported as slow, but no more than `max` number of them. Passing zero as `max` reports all slow tests that exceed the threshold.
4343
- `shard: { total: number, current: number } | null` - [Shard](./test-parallel.md#shards) information.
4444
- `updateSnapshots: boolean` - Whether to update expected snapshots with the actual results produced by the test run.
45-
- `launch: { command: string, waitForPort?: number, waitForPortTimeout?: number, strict?: boolean, cwd?: string, env?: object }[]` - Launch a process before the tests will start. When using `waitForPort` it will wait until the server is available, see [launch server](#launching-a-development-web-server-during-the-tests) configuration for examples. `strict` will verify that the `waitForPort` port is available instead of using it by default.
4645
- `workers: number` - The maximum number of concurrent worker processes to use for parallelizing tests.
4746

4847
Note that each [test project](#projects) can provide its own test suite options, for example two projects can run different tests by providing different `testDir`s. However, test run options are shared between all projects.
@@ -201,80 +200,6 @@ export const test = base.extend<{ saveLogs: void }>({
201200
});
202201
```
203202

204-
## Launching a development web server during the tests
205-
206-
To launch a server during the tests, use the `launch` option in the [configuration file](#configuration-object).
207-
208-
You can specify a port via `waitForPort` or additional environment variables, see [here](#configuration-object). When a port is specified, the server will wait for it to be available before starting. For continuous integration, you may want to use the `strict` option which ensures that the port is available before starting the server.
209-
210-
The port gets then passed over to Playwright as a [`param: baseURL`] when creating the context [`method: Browser.newContext`].
211-
212-
```js js-flavor=ts
213-
// playwright.config.ts
214-
import { PlaywrightTestConfig } from '@playwright/test';
215-
216-
const config: PlaywrightTestConfig = {
217-
launch: {
218-
command: 'npm run start',
219-
waitForPort: 3000,
220-
waitForPortTimeout: 120 * 1000,
221-
strict: !!process.env.CI,
222-
},
223-
};
224-
225-
export default config;
226-
```
227-
228-
```js js-flavor=js
229-
// playwright.config.js
230-
// @ts-check
231-
/** @type {import('@playwright/test').PlaywrightTestConfig} */
232-
const config = {
233-
launch: {
234-
command: 'npm run start',
235-
waitForPort: 3000,
236-
waitForPortTimeout: 120 * 1000,
237-
strict: !!process.env.CI,
238-
},
239-
};
240-
241-
mode.exports = config;
242-
```
243-
244-
Now you can use a relative path when navigating the page, or use `baseURL` fixture:
245-
246-
```js js-flavor=ts
247-
// test.spec.ts
248-
import { test } = from '@playwright/test';
249-
250-
test('test', async ({ page, baseURL }) => {
251-
// baseURL is taken directly from your web server,
252-
// e.g. http://localhost:3000
253-
await page.goto(baseURL + '/bar');
254-
255-
// Alternatively, just use relative path, because baseURL is already
256-
// set for the default context and page.
257-
// For example, this will result in http://localhost:3000/foo
258-
await page.goto('/foo');
259-
});
260-
```
261-
262-
```js js-flavor=js
263-
// test.spec.js
264-
const { test } = require('@playwright/test');
265-
266-
test('test', async ({ page, baseURL }) => {
267-
// baseURL is taken directly from your web server,
268-
// e.g. http://localhost:3000
269-
await page.goto(baseURL + '/bar');
270-
271-
// Alternatively, just use relative path, because baseURL is already
272-
// set for the default context and page.
273-
// For example, this will result in http://localhost:3000/foo
274-
await page.goto('/foo');
275-
});
276-
```
277-
278203
## Global setup and teardown
279204

280205
To set something up once before running all tests, use `globalSetup` option in the [configuration file](#configuration-object).

docs/src/test-configuration.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ In addition to configuring [Browser] or [BrowserContext], videos or screenshots,
478478
- `testIgnore`: Glob patterns or regular expressions that should be ignored when looking for the test files. For example, `'**/test-assets'`.
479479
- `testMatch`: Glob patterns or regular expressions that match test files. For example, `'**/todo-tests/*.spec.ts'`. By default, Playwright Test runs `.*(test|spec)\.(js|ts|mjs)` files.
480480
- `timeout`: Time in milliseconds given to each test.
481-
- `launch: { command: string, waitForPort?: number, waitForPortTimeout?: number, strict?: boolean, cwd?: string, env?: object }` - Launch a process before the tests will start. When using `waitForPort` it will wait until the server is available, see [launch server](./test-advanced.md#launching-a-development-web-server-during-the-tests) configuration for examples. `strict` will verify that the `waitForPort` port is available instead of using it by default.
482481
- `workers`: The maximum number of concurrent worker processes to use for parallelizing tests.
483482

484483
You can specify these options in the configuration file. Note that testing options are **top-level**, do not put them into the `use` section.

src/test/loader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class Loader {
101101
this._fullConfig.shard = takeFirst(this._configOverrides.shard, this._config.shard, baseFullConfig.shard);
102102
this._fullConfig.updateSnapshots = takeFirst(this._configOverrides.updateSnapshots, this._config.updateSnapshots, baseFullConfig.updateSnapshots);
103103
this._fullConfig.workers = takeFirst(this._configOverrides.workers, this._config.workers, baseFullConfig.workers);
104-
this._fullConfig.launch = takeFirst(toLaunchServers(this._configOverrides.launch), toLaunchServers(this._config.launch), baseFullConfig.launch);
104+
this._fullConfig._launch = takeFirst(toLaunchServers(this._configOverrides._launch), toLaunchServers(this._config._launch), baseFullConfig._launch);
105105

106106
for (const project of projects)
107107
this._addProject(project, this._fullConfig.rootDir);
@@ -435,7 +435,7 @@ const baseFullConfig: FullConfig = {
435435
shard: null,
436436
updateSnapshots: 'missing',
437437
workers: 1,
438-
launch: [],
438+
_launch: [],
439439
};
440440

441441
function resolveReporters(reporters: Config['reporter'], rootDir: string): ReporterDescription[]|undefined {

src/test/runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export class Runner {
167167
testFiles.forEach(file => allTestFiles.add(file));
168168
}
169169

170-
const launchServers = await LaunchServers.create(config.launch);
170+
const launchServers = await LaunchServers.create(config._launch);
171171
let globalSetupResult: any;
172172
if (config.globalSetup)
173173
globalSetupResult = await (await this._loader.loadGlobalHook(config.globalSetup, 'globalSetup'))(this._loader.fullConfig());

tests/playwright-test/launch-server.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test('should create a server', async ({ runInlineTest }, { workerIndex }) => {
3232
`,
3333
'playwright.config.ts': `
3434
module.exports = {
35-
launch: {
35+
_launch: {
3636
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',
3737
waitForPort: ${port},
3838
},
@@ -82,7 +82,7 @@ test('should create a server with environment variables', async ({ runInlineTest
8282
`,
8383
'playwright.config.ts': `
8484
module.exports = {
85-
launch: {
85+
_launch: {
8686
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',
8787
waitForPort: ${port},
8888
env: {
@@ -110,7 +110,7 @@ test('should time out waiting for a server', async ({ runInlineTest }, { workerI
110110
`,
111111
'playwright.config.ts': `
112112
module.exports = {
113-
launch: {
113+
_launch: {
114114
command: 'node ${JSON.stringify(JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js')))} ${port}',
115115
waitForPort: ${port},
116116
waitForPortTimeout: 100,
@@ -169,7 +169,7 @@ test('should be able to use an existing server when strict is false ', async ({
169169
`,
170170
'playwright.config.ts': `
171171
module.exports = {
172-
launch: {
172+
_launch: {
173173
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',
174174
waitForPort: ${port},
175175
strict: false,
@@ -202,7 +202,7 @@ test('should throw when a server is already running on the given port and strict
202202
`,
203203
'playwright.config.ts': `
204204
module.exports = {
205-
launch: {
205+
_launch: {
206206
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',
207207
waitForPort: ${port},
208208
strict: true,
@@ -228,7 +228,7 @@ test('should create multiple servers', async ({ runInlineTest }, { workerIndex }
228228
`,
229229
'playwright.config.ts': `
230230
module.exports = {
231-
launch: [{
231+
_launch: [{
232232
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port1}',
233233
waitForPort: ${port1},
234234
},{

types/test.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ interface ConfigBase {
240240
/**
241241
* Launch a web server before running tests.
242242
*/
243-
launch?: LaunchConfig | LaunchConfig[];
243+
_launch?: LaunchConfig | LaunchConfig[];
244244

245245
/**
246246
* The maximum number of concurrent worker processes to use for parallelizing tests.
@@ -275,7 +275,7 @@ export interface FullConfig {
275275
shard: Shard;
276276
updateSnapshots: UpdateSnapshots;
277277
workers: number;
278-
launch: LaunchConfig[];
278+
_launch: LaunchConfig[];
279279
}
280280

281281
export type TestStatus = 'passed' | 'failed' | 'timedOut' | 'skipped';

0 commit comments

Comments
 (0)