feat(test-runner): mark launch as experimental (#7757)
This commit is contained in:
parent
af5eb9c2bd
commit
483b7d6a0d
|
|
@ -42,7 +42,6 @@ These options would be typically different between local development and CI oper
|
||||||
- `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.
|
- `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.
|
||||||
- `shard: { total: number, current: number } | null` - [Shard](./test-parallel.md#shards) information.
|
- `shard: { total: number, current: number } | null` - [Shard](./test-parallel.md#shards) information.
|
||||||
- `updateSnapshots: boolean` - Whether to update expected snapshots with the actual results produced by the test run.
|
- `updateSnapshots: boolean` - Whether to update expected snapshots with the actual results produced by the test run.
|
||||||
- `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.
|
|
||||||
- `workers: number` - The maximum number of concurrent worker processes to use for parallelizing tests.
|
- `workers: number` - The maximum number of concurrent worker processes to use for parallelizing tests.
|
||||||
|
|
||||||
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.
|
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 }>({
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Launching a development web server during the tests
|
|
||||||
|
|
||||||
To launch a server during the tests, use the `launch` option in the [configuration file](#configuration-object).
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
The port gets then passed over to Playwright as a [`param: baseURL`] when creating the context [`method: Browser.newContext`].
|
|
||||||
|
|
||||||
```js js-flavor=ts
|
|
||||||
// playwright.config.ts
|
|
||||||
import { PlaywrightTestConfig } from '@playwright/test';
|
|
||||||
|
|
||||||
const config: PlaywrightTestConfig = {
|
|
||||||
launch: {
|
|
||||||
command: 'npm run start',
|
|
||||||
waitForPort: 3000,
|
|
||||||
waitForPortTimeout: 120 * 1000,
|
|
||||||
strict: !!process.env.CI,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default config;
|
|
||||||
```
|
|
||||||
|
|
||||||
```js js-flavor=js
|
|
||||||
// playwright.config.js
|
|
||||||
// @ts-check
|
|
||||||
/** @type {import('@playwright/test').PlaywrightTestConfig} */
|
|
||||||
const config = {
|
|
||||||
launch: {
|
|
||||||
command: 'npm run start',
|
|
||||||
waitForPort: 3000,
|
|
||||||
waitForPortTimeout: 120 * 1000,
|
|
||||||
strict: !!process.env.CI,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
mode.exports = config;
|
|
||||||
```
|
|
||||||
|
|
||||||
Now you can use a relative path when navigating the page, or use `baseURL` fixture:
|
|
||||||
|
|
||||||
```js js-flavor=ts
|
|
||||||
// test.spec.ts
|
|
||||||
import { test } = from '@playwright/test';
|
|
||||||
|
|
||||||
test('test', async ({ page, baseURL }) => {
|
|
||||||
// baseURL is taken directly from your web server,
|
|
||||||
// e.g. http://localhost:3000
|
|
||||||
await page.goto(baseURL + '/bar');
|
|
||||||
|
|
||||||
// Alternatively, just use relative path, because baseURL is already
|
|
||||||
// set for the default context and page.
|
|
||||||
// For example, this will result in http://localhost:3000/foo
|
|
||||||
await page.goto('/foo');
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
```js js-flavor=js
|
|
||||||
// test.spec.js
|
|
||||||
const { test } = require('@playwright/test');
|
|
||||||
|
|
||||||
test('test', async ({ page, baseURL }) => {
|
|
||||||
// baseURL is taken directly from your web server,
|
|
||||||
// e.g. http://localhost:3000
|
|
||||||
await page.goto(baseURL + '/bar');
|
|
||||||
|
|
||||||
// Alternatively, just use relative path, because baseURL is already
|
|
||||||
// set for the default context and page.
|
|
||||||
// For example, this will result in http://localhost:3000/foo
|
|
||||||
await page.goto('/foo');
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Global setup and teardown
|
## Global setup and teardown
|
||||||
|
|
||||||
To set something up once before running all tests, use `globalSetup` option in the [configuration file](#configuration-object).
|
To set something up once before running all tests, use `globalSetup` option in the [configuration file](#configuration-object).
|
||||||
|
|
|
||||||
|
|
@ -478,7 +478,6 @@ In addition to configuring [Browser] or [BrowserContext], videos or screenshots,
|
||||||
- `testIgnore`: Glob patterns or regular expressions that should be ignored when looking for the test files. For example, `'**/test-assets'`.
|
- `testIgnore`: Glob patterns or regular expressions that should be ignored when looking for the test files. For example, `'**/test-assets'`.
|
||||||
- `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.
|
- `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.
|
||||||
- `timeout`: Time in milliseconds given to each test.
|
- `timeout`: Time in milliseconds given to each test.
|
||||||
- `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.
|
|
||||||
- `workers`: The maximum number of concurrent worker processes to use for parallelizing tests.
|
- `workers`: The maximum number of concurrent worker processes to use for parallelizing tests.
|
||||||
|
|
||||||
You can specify these options in the configuration file. Note that testing options are **top-level**, do not put them into the `use` section.
|
You can specify these options in the configuration file. Note that testing options are **top-level**, do not put them into the `use` section.
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ export class Loader {
|
||||||
this._fullConfig.shard = takeFirst(this._configOverrides.shard, this._config.shard, baseFullConfig.shard);
|
this._fullConfig.shard = takeFirst(this._configOverrides.shard, this._config.shard, baseFullConfig.shard);
|
||||||
this._fullConfig.updateSnapshots = takeFirst(this._configOverrides.updateSnapshots, this._config.updateSnapshots, baseFullConfig.updateSnapshots);
|
this._fullConfig.updateSnapshots = takeFirst(this._configOverrides.updateSnapshots, this._config.updateSnapshots, baseFullConfig.updateSnapshots);
|
||||||
this._fullConfig.workers = takeFirst(this._configOverrides.workers, this._config.workers, baseFullConfig.workers);
|
this._fullConfig.workers = takeFirst(this._configOverrides.workers, this._config.workers, baseFullConfig.workers);
|
||||||
this._fullConfig.launch = takeFirst(toLaunchServers(this._configOverrides.launch), toLaunchServers(this._config.launch), baseFullConfig.launch);
|
this._fullConfig._launch = takeFirst(toLaunchServers(this._configOverrides._launch), toLaunchServers(this._config._launch), baseFullConfig._launch);
|
||||||
|
|
||||||
for (const project of projects)
|
for (const project of projects)
|
||||||
this._addProject(project, this._fullConfig.rootDir);
|
this._addProject(project, this._fullConfig.rootDir);
|
||||||
|
|
@ -435,7 +435,7 @@ const baseFullConfig: FullConfig = {
|
||||||
shard: null,
|
shard: null,
|
||||||
updateSnapshots: 'missing',
|
updateSnapshots: 'missing',
|
||||||
workers: 1,
|
workers: 1,
|
||||||
launch: [],
|
_launch: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
function resolveReporters(reporters: Config['reporter'], rootDir: string): ReporterDescription[]|undefined {
|
function resolveReporters(reporters: Config['reporter'], rootDir: string): ReporterDescription[]|undefined {
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ export class Runner {
|
||||||
testFiles.forEach(file => allTestFiles.add(file));
|
testFiles.forEach(file => allTestFiles.add(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
const launchServers = await LaunchServers.create(config.launch);
|
const launchServers = await LaunchServers.create(config._launch);
|
||||||
let globalSetupResult: any;
|
let globalSetupResult: any;
|
||||||
if (config.globalSetup)
|
if (config.globalSetup)
|
||||||
globalSetupResult = await (await this._loader.loadGlobalHook(config.globalSetup, 'globalSetup'))(this._loader.fullConfig());
|
globalSetupResult = await (await this._loader.loadGlobalHook(config.globalSetup, 'globalSetup'))(this._loader.fullConfig());
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ test('should create a server', async ({ runInlineTest }, { workerIndex }) => {
|
||||||
`,
|
`,
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
module.exports = {
|
module.exports = {
|
||||||
launch: {
|
_launch: {
|
||||||
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',
|
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',
|
||||||
waitForPort: ${port},
|
waitForPort: ${port},
|
||||||
},
|
},
|
||||||
|
|
@ -82,7 +82,7 @@ test('should create a server with environment variables', async ({ runInlineTest
|
||||||
`,
|
`,
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
module.exports = {
|
module.exports = {
|
||||||
launch: {
|
_launch: {
|
||||||
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',
|
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',
|
||||||
waitForPort: ${port},
|
waitForPort: ${port},
|
||||||
env: {
|
env: {
|
||||||
|
|
@ -110,7 +110,7 @@ test('should time out waiting for a server', async ({ runInlineTest }, { workerI
|
||||||
`,
|
`,
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
module.exports = {
|
module.exports = {
|
||||||
launch: {
|
_launch: {
|
||||||
command: 'node ${JSON.stringify(JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js')))} ${port}',
|
command: 'node ${JSON.stringify(JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js')))} ${port}',
|
||||||
waitForPort: ${port},
|
waitForPort: ${port},
|
||||||
waitForPortTimeout: 100,
|
waitForPortTimeout: 100,
|
||||||
|
|
@ -169,7 +169,7 @@ test('should be able to use an existing server when strict is false ', async ({
|
||||||
`,
|
`,
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
module.exports = {
|
module.exports = {
|
||||||
launch: {
|
_launch: {
|
||||||
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',
|
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',
|
||||||
waitForPort: ${port},
|
waitForPort: ${port},
|
||||||
strict: false,
|
strict: false,
|
||||||
|
|
@ -202,7 +202,7 @@ test('should throw when a server is already running on the given port and strict
|
||||||
`,
|
`,
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
module.exports = {
|
module.exports = {
|
||||||
launch: {
|
_launch: {
|
||||||
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',
|
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',
|
||||||
waitForPort: ${port},
|
waitForPort: ${port},
|
||||||
strict: true,
|
strict: true,
|
||||||
|
|
@ -228,7 +228,7 @@ test('should create multiple servers', async ({ runInlineTest }, { workerIndex }
|
||||||
`,
|
`,
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
module.exports = {
|
module.exports = {
|
||||||
launch: [{
|
_launch: [{
|
||||||
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port1}',
|
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port1}',
|
||||||
waitForPort: ${port1},
|
waitForPort: ${port1},
|
||||||
},{
|
},{
|
||||||
|
|
|
||||||
4
types/test.d.ts
vendored
4
types/test.d.ts
vendored
|
|
@ -240,7 +240,7 @@ interface ConfigBase {
|
||||||
/**
|
/**
|
||||||
* Launch a web server before running tests.
|
* Launch a web server before running tests.
|
||||||
*/
|
*/
|
||||||
launch?: LaunchConfig | LaunchConfig[];
|
_launch?: LaunchConfig | LaunchConfig[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum number of concurrent worker processes to use for parallelizing tests.
|
* The maximum number of concurrent worker processes to use for parallelizing tests.
|
||||||
|
|
@ -275,7 +275,7 @@ export interface FullConfig {
|
||||||
shard: Shard;
|
shard: Shard;
|
||||||
updateSnapshots: UpdateSnapshots;
|
updateSnapshots: UpdateSnapshots;
|
||||||
workers: number;
|
workers: number;
|
||||||
launch: LaunchConfig[];
|
_launch: LaunchConfig[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TestStatus = 'passed' | 'failed' | 'timedOut' | 'skipped';
|
export type TestStatus = 'passed' | 'failed' | 'timedOut' | 'skipped';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue