chore: generate types for TestProject/TestConfig (#13574)

This commit is contained in:
Dmitry Gozman 2022-04-15 10:27:38 -07:00 committed by GitHub
parent 09754100aa
commit 02aa4fe617
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 1599 additions and 1434 deletions

View file

@ -84,7 +84,7 @@ export default config;
```
## property: TestConfig.forbidOnly
- type: <[boolean]>
- type: ?<[boolean]>
Whether to exit with an error if any tests or groups are marked as [`method: Test.only`] or [`method: Test.describe.only`]. Useful on CI.
@ -111,7 +111,7 @@ export default config;
```
## property: TestConfig.fullyParallel
- type: <[boolean]>
- type: ?<[boolean]>
Playwright Test runs tests in parallel. In order to achieve that, it runs several worker processes that run at the same time.
By default, **test files** are run in parallel. Tests in a single file are run in order, in the same worker process.
@ -119,7 +119,7 @@ By default, **test files** are run in parallel. Tests in a single file are run i
You can configure entire test run to concurrently execute all tests in all files using this option.
## property: TestConfig.globalSetup
- type: <[string]>
- type: ?<[string]>
Path to the global setup file. This file will be required and run before all the tests. It must export a single function that takes a [`TestConfig`] argument.
@ -148,7 +148,7 @@ export default config;
```
## property: TestConfig.globalTeardown
- type: <[string]>
- type: ?<[string]>
Path to the global teardown file. This file will be required and run after all the tests. It must export a single function. See also [`property: TestConfig.globalSetup`].
@ -177,7 +177,7 @@ export default config;
```
## property: TestConfig.globalTimeout
- type: <[int]>
- type: ?<[int]>
Maximum time in milliseconds the whole test suite can run. Zero timeout (default) disables this behavior. Useful on CI to prevent broken setup from running too long and wasting resources. Learn more about [various timeouts](../test-timeouts.md).
@ -204,7 +204,7 @@ export default config;
```
## property: TestConfig.grep
- type: <[RegExp]|[Array]<[RegExp]>>
- type: ?<[RegExp]|[Array]<[RegExp]>>
Filter to only run tests with a title matching one of the patterns. For example, passing `grep: /cart/` should only run tests with "cart" in the title. Also available in the [command line](../test-cli.md) with the `-g` option.
@ -212,7 +212,7 @@ Filter to only run tests with a title matching one of the patterns. For example,
## property: TestConfig.grepInvert
- type: <[RegExp]|[Array]<[RegExp]>>
- type: ?<[RegExp]|[Array]<[RegExp]>>
Filter to only run tests with a title **not** matching one of the patterns. This is the opposite of [`property: TestConfig.grep`]. Also available in the [command line](../test-cli.md) with the `--grep-invert` option.
@ -220,7 +220,7 @@ Filter to only run tests with a title **not** matching one of the patterns. This
## property: TestConfig.maxFailures
- type: <[int]>
- type: ?<[int]>
The maximum number of test failures for the whole test suite run. After reaching this number, testing will stop and exit with an error. Setting to zero (default) disables this behavior.
@ -249,17 +249,17 @@ export default config;
```
## property: TestConfig.metadata
- type: <[Object]>
- type: ?<[any]>
Any JSON-serializable metadata that will be put directly to the test report.
## property: TestConfig.name
- type: <[string]>
- type: ?<[string]>
Config name is visible in the report and during test execution, unless overridden by [`property: TestProject.name`].
## property: TestConfig.outputDir
- type: <[string]>
- type: ?<[string]>
The output directory for files created during test execution. Defaults to `<package.json-directory>/test-results`.
@ -311,7 +311,7 @@ test('example test', async ({}, testInfo) => {
## property: TestConfig.snapshotDir
- type: <[string]>
- type: ?<[string]>
The base directory, relative to the config file, for snapshot files created with `toMatchSnapshot`. Defaults to [`property: TestConfig.testDir`].
@ -320,7 +320,7 @@ The directory for each test can be accessed by [`property: TestInfo.snapshotDir`
This path will serve as the base directory for each test file snapshot directory. Setting `snapshotDir` to `'snapshots'`, the [`property: TestInfo.snapshotDir`] would resolve to `snapshots/a.spec.js-snapshots`.
## property: TestConfig.preserveOutput
- type: <[PreserveOutput]<"always"|"never"|"failures-only">>
- type: ?<[PreserveOutput]<"always"|"never"|"failures-only">>
Whether to preserve test output in the [`property: TestConfig.outputDir`]. Defaults to `'always'`.
* `'always'` - preserve output for all tests;
@ -329,23 +329,23 @@ Whether to preserve test output in the [`property: TestConfig.outputDir`]. Defau
## property: TestConfig.projects
- type: <[Array]<[TestProject]>>
- type: ?<[Array]<[TestProject]>>
Playwright Test supports running multiple test projects at the same time. See [TestProject] for more information.
## property: TestConfig.quiet
- type: <[boolean]>
- type: ?<[boolean]>
Whether to suppress stdio and stderr output from the tests.
## property: TestConfig.repeatEach
- type: <[int]>
- type: ?<[int]>
The number of times to repeat each test, useful for debugging flaky tests.
## property: TestConfig.reporter
- type: <[string]|[Array]<[Object]>|[BuiltInReporter]<"list"|"dot"|"line"|"github"|"json"|"junit"|"null"|"html">>
- type: ?<[string]|[Array]<[Object]>|[BuiltInReporter]<"list"|"dot"|"line"|"github"|"json"|"junit"|"null"|"html">>
- `0` <[string]> Reporter name or module or file path
- `1` <[Object]> An object with reporter options if any
@ -381,7 +381,7 @@ export default config;
```
## property: TestConfig.reportSlowTests
- type: <[Object]>
- type: ?<[null]|[Object]>
- `max` <[int]> The maximum number of slow test files to report. Defaults to `5`.
- `threshold` <[float]> Test duration in milliseconds that is considered slow. Defaults to 15 seconds.
@ -390,7 +390,7 @@ Whether to report slow test files. Pass `null` to disable this feature.
Test files that took more than `threshold` milliseconds are considered slow, and the slowest ones are reported, no more than `max` number of them. Passing zero as `max` reports all test files that exceed the threshold.
## property: TestConfig.retries
- type: <[int]>
- type: ?<[int]>
The maximum number of retry attempts given to failed tests. By default failing tests are not retried. Learn more about [test retries](../test-retries.md#retries).
@ -453,7 +453,7 @@ where:
* `Mobile Safari` and `Desktop Chrome` - project names
## property: TestConfig.shard
- type: <[Object]>
- type: ?<[null]|[Object]>
- `total` <[int]> The total number of shards.
- `current` <[int]> The index of the shard to execute, one-based.
@ -462,7 +462,7 @@ Shard tests and execute only the selected shard. Specify in the one-based form l
Learn more about [parallelism and sharding](../test-parallel.md) with Playwright Test.
## property: TestConfig.testDir
- type: <[string]>
- type: ?<[string]>
Directory that will be recursively scanned for test files. Defaults to the directory of the configuration file.
@ -489,7 +489,7 @@ export default config;
```
## property: TestConfig.testIgnore
- type: <[string]|[RegExp]|[Array]<[string]>|[Array]<[RegExp]>>
- type: ?<[string]|[RegExp]|[Array]<[string]|[RegExp]>>
Files matching one of these patterns are not executed as test files. Matching is performed against the absolute file path. Strings are treated as glob patterns.
@ -518,7 +518,7 @@ export default config;
```
## property: TestConfig.testMatch
- type: <[string]|[RegExp]|[Array]<[string]>|[Array]<[RegExp]>>
- type: ?<[string]|[RegExp]|[Array]<[string]|[RegExp]>>
Only the files matching one of these patterns are executed as test files. Matching is performed against the absolute file path. Strings are treated as glob patterns.
@ -547,7 +547,7 @@ export default config;
```
## property: TestConfig.timeout
- type: <[int]>
- type: ?<[int]>
Timeout for each test in milliseconds. Defaults to 30 seconds.
@ -576,7 +576,7 @@ export default config;
```
## property: TestConfig.updateSnapshots
- type: <[UpdateSnapshots]<"all"|"none"|"missing">>
- type: ?<[UpdateSnapshots]<"all"|"none"|"missing">>
Whether to update expected snapshots with the actual results produced by the test run. Defaults to `'missing'`.
* `'all'` - All tests that are executed will update snapshots.
@ -586,7 +586,7 @@ Whether to update expected snapshots with the actual results produced by the tes
Learn more about [snapshots](../test-snapshots.md).
## property: TestConfig.use
- type: <[TestOptions]>
- type: ?<[TestOptions]>
Global options for all tests, for example [`property: TestOptions.browserName`]. Learn more about [configuration](../test-configuration.md) and see [available options][TestOptions].
@ -617,15 +617,15 @@ export default config;
```
## property: TestConfig.webServer
- type: <[Object]>
- `command` <[string]> Command which gets executed
- `port` <[int]> Port to wait on for the web server (exactly one of `port` or `url` is required)
- `url` <[string]> URL to wait on for the web server (exactly one of `port` or `url` is required)
- `ignoreHTTPSErrors` <[boolean]> Whether to ignore HTTPS errors when fetching the `url`. Defaults to `false`.
- `timeout` <[int]> Maximum duration to wait on until the web server is ready
- `reuseExistingServer` <[boolean]> If true, reuse the existing server if it is already running, otherwise it will fail
- `cwd` <[string]> Working directory to run the command in
- `env` <[Object]<[string], [string]>> Environment variables to set for the command
- type: ?<[Object]>
- `command` <[string]> Shell command to start. For example `npm run start`..
- `port` ?<[int]> The port that your http server is expected to appear on. It does wait until it accepts connections. Exactly one of `port` or `url` is required.
- `url` ?<[string]> The url on your http server that is expected to return a 2xx status code when the server is ready to accept connections. Exactly one of `port` or `url` is required.
- `ignoreHTTPSErrors` ?<[boolean]> Whether to ignore HTTPS errors when fetching the `url`. Defaults to `false`.
- `timeout` ?<[int]> How long to wait for the process to start up and be available in milliseconds. Defaults to 60000.
- `reuseExistingServer` ?<[boolean]> If true, it will re-use an existing server on the `port` or `url` when available. If no server is running on that `port` or `url`, it will run the command to start a new server. If `false`, it will throw if an existing process is listening on the `port` or `url`. This should be commonly set to `!process.env.CI` to allow the local dev server when running tests locally.
- `cwd` ?<[string]> Current working directory of the spawned process, `process.cwd()` by default.
- `env` ?<[Object]<[string], [string]>> Environment variables to set for the command, `process.env` by default.
Launch a development web server during the tests.
@ -697,7 +697,7 @@ test('test', async ({ page }) => {
```
## property: TestConfig.workers
- type: <[int]>
- type: ?<[int]>
The maximum number of concurrent worker processes to use for parallelizing tests.

View file

@ -125,7 +125,7 @@ Configuration for the `expect` assertion library.
Use [`property: TestConfig.expect`] to change this option for all projects.
## property: TestProject.fullyParallel
- type: <[boolean]>
- type: ?<[boolean]>
Playwright Test runs tests in parallel. In order to achieve that, it runs several worker processes that run at the same time.
By default, **test files** are run in parallel. Tests in a single file are run in order, in the same worker process.
@ -133,26 +133,26 @@ By default, **test files** are run in parallel. Tests in a single file are run i
You can configure entire test project to concurrently run all tests in all files using this option.
## property: TestProject.grep
- type: <[RegExp]|[Array]<[RegExp]>>
- type: ?<[RegExp]|[Array]<[RegExp]>>
Filter to only run tests with a title matching one of the patterns. For example, passing `grep: /cart/` should only run tests with "cart" in the title. Also available globally and in the [command line](../test-cli.md) with the `-g` option.
`grep` option is also useful for [tagging tests](../test-annotations.md#tag-tests).
## property: TestProject.grepInvert
- type: <[RegExp]|[Array]<[RegExp]>>
- type: ?<[RegExp]|[Array]<[RegExp]>>
Filter to only run tests with a title **not** matching one of the patterns. This is the opposite of [`property: TestProject.grep`]. Also available globally and in the [command line](../test-cli.md) with the `--grep-invert` option.
`grepInvert` option is also useful for [tagging tests](../test-annotations.md#tag-tests).
## property: TestProject.metadata
- type: <[Object]>
- type: ?<[any]>
Any JSON-serializable metadata that will be put directly to the test report.
## property: TestProject.name
- type: <[string]>
- type: ?<[string]>
Project name is visible in the report and during test execution.
@ -195,7 +195,7 @@ where:
## property: TestProject.snapshotDir
- type: <[string]>
- type: ?<[string]>
The base directory, relative to the config file, for snapshot files created with `toMatchSnapshot`. Defaults to [`property: TestProject.testDir`].
@ -204,7 +204,7 @@ The directory for each test can be accessed by [`property: TestInfo.snapshotDir`
This path will serve as the base directory for each test file snapshot directory. Setting `snapshotDir` to `'snapshots'`, the [`property: TestInfo.snapshotDir`] would resolve to `snapshots/a.spec.js-snapshots`.
## property: TestProject.outputDir
- type: <[string]>
- type: ?<[string]>
The output directory for files created during test execution. Defaults to `<package.json-directory>/test-results`.
@ -235,21 +235,21 @@ test('example test', async ({}, testInfo) => {
Use [`property: TestConfig.outputDir`] to change this option for all projects.
## property: TestProject.repeatEach
- type: <[int]>
- type: ?<[int]>
The number of times to repeat each test, useful for debugging flaky tests.
Use [`property: TestConfig.repeatEach`] to change this option for all projects.
## property: TestProject.retries
- type: <[int]>
- type: ?<[int]>
The maximum number of retry attempts given to failed tests. Learn more about [test retries](../test-retries.md#retries).
Use [`property: TestConfig.retries`] to change this option for all projects.
## property: TestProject.testDir
- type: <[string]>
- type: ?<[string]>
Directory that will be recursively scanned for test files. Defaults to the directory of the configuration file.
@ -340,7 +340,7 @@ export default config;
Use [`property: TestConfig.testDir`] to change this option for all projects.
## property: TestProject.testIgnore
- type: <[string]|[RegExp]|[Array]<[string]>|[Array]<[RegExp]>>
- type: ?<[string]|[RegExp]|[Array]<[string]|[RegExp]>>
Files matching one of these patterns are not executed as test files. Matching is performed against the absolute file path. Strings are treated as glob patterns.
@ -349,7 +349,7 @@ For example, `'**/test-assets/**'` will ignore any files in the `test-assets` di
Use [`property: TestConfig.testIgnore`] to change this option for all projects.
## property: TestProject.testMatch
- type: <[string]|[RegExp]|[Array]<[string]>|[Array]<[RegExp]>>
- type: ?<[string]|[RegExp]|[Array]<[string]|[RegExp]>>
Only the files matching one of these patterns are executed as test files. Matching is performed against the absolute file path. Strings are treated as glob patterns.
@ -358,7 +358,7 @@ By default, Playwright Test looks for files matching `.*(test|spec)\.(js|ts|mjs)
Use [`property: TestConfig.testMatch`] to change this option for all projects.
## property: TestProject.timeout
- type: <[int]>
- type: ?<[int]>
Timeout for each test in milliseconds. Defaults to 30 seconds.

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -574,7 +574,7 @@ class TypesGenerator {
'PlaywrightWorkerArgs.playwright',
'Matchers',
]),
doNotExportClassNames: new Set(assertionClasses),
doNotExportClassNames: new Set([...assertionClasses, 'TestProject']),
includeExperimental,
});
return await generator.generateTypes(path.join(__dirname, 'overrides-test.d.ts'));

View file

@ -35,22 +35,6 @@ export type UpdateSnapshots = 'all' | 'none' | 'missing';
type UseOptions<TestArgs, WorkerArgs> = { [K in keyof WorkerArgs]?: WorkerArgs[K] } & { [K in keyof TestArgs]?: TestArgs[K] };
interface TestProject {
fullyParallel?: boolean;
grep?: RegExp | RegExp[];
grepInvert?: RegExp | RegExp[] | null;
metadata?: any;
name?: string;
snapshotDir?: string;
outputDir?: string;
repeatEach?: number;
retries?: number;
testDir?: string;
testIgnore?: string | RegExp | (string | RegExp)[];
testMatch?: string | RegExp | (string | RegExp)[];
timeout?: number;
}
export interface Project<TestArgs = {}, WorkerArgs = {}> extends TestProject {
use?: UseOptions<TestArgs, WorkerArgs>;
}
@ -118,34 +102,7 @@ export type WebServerConfig = {
type LiteralUnion<T extends U, U = string> = T | (U & { zz_IGNORE_ME?: never });
interface TestConfig {
forbidOnly?: boolean;
fullyParallel?: boolean;
globalSetup?: string;
globalTeardown?: string;
globalTimeout?: number;
grep?: RegExp | RegExp[];
grepInvert?: RegExp | RegExp[];
maxFailures?: number;
preserveOutput?: PreserveOutput;
projects?: Project[];
quiet?: boolean;
reporter?: LiteralUnion<'list'|'dot'|'line'|'github'|'json'|'junit'|'null'|'html', string> | ReporterDescription[];
reportSlowTests?: ReportSlowTests;
shard?: Shard;
updateSnapshots?: UpdateSnapshots;
webServer?: WebServerConfig;
workers?: number;
metadata?: any;
name?: string;
snapshotDir?: string;
outputDir?: string;
repeatEach?: number;
retries?: number;
testDir?: string;
testIgnore?: string | RegExp | (string | RegExp)[];
testMatch?: string | RegExp | (string | RegExp)[];
timeout?: number;
}
export interface Config<TestArgs = {}, WorkerArgs = {}> extends TestConfig {