diff --git a/docs/src/test-api/class-configinworker.md b/docs/src/test-api/class-configinworker.md new file mode 100644 index 0000000000..5832dca885 --- /dev/null +++ b/docs/src/test-api/class-configinworker.md @@ -0,0 +1,135 @@ +# class: ConfigInWorker +* since: v1.10 +* langs: js + +Resolved configuration available via [`property: TestInfo.config`] and [`property: WorkerInfo.config`]. + +## property: ConfigInWorker.configFile +* since: v1.20 +- type: ?<[string]> + +Path to the configuration file (if any) used to run the tests. + +## property: ConfigInWorker.forbidOnly +* since: v1.10 +- type: <[boolean]> + +See [`property: TestConfig.forbidOnly`]. + +## property: ConfigInWorker.fullyParallel +* since: v1.20 +- type: <[boolean]> + +See [`property: TestConfig.fullyParallel`]. + +## property: ConfigInWorker.globalSetup +* since: v1.10 +- type: <[null]|[string]> + +See [`property: TestConfig.globalSetup`]. + +## property: ConfigInWorker.globalTeardown +* since: v1.10 +- type: <[null]|[string]> + +See [`property: TestConfig.globalTeardown`]. + +## property: ConfigInWorker.globalTimeout +* since: v1.10 +- type: <[int]> + +See [`property: TestConfig.globalTimeout`]. + +## property: ConfigInWorker.grep +* since: v1.10 +- type: <[RegExp]|[Array]<[RegExp]>> + +See [`property: TestConfig.grep`]. + +## property: ConfigInWorker.grepInvert +* since: v1.10 +- type: <[null]|[RegExp]|[Array]<[RegExp]>> + +See [`property: TestConfig.grepInvert`]. + +## property: ConfigInWorker.maxFailures +* since: v1.10 +- type: <[int]> + +See [`property: TestConfig.maxFailures`]. + +## property: ConfigInWorker.metadata +* since: v1.10 +- type: <[Metadata]> + +See [`property: TestConfig.metadata`]. + +## property: ConfigInWorker.preserveOutput +* since: v1.10 +- type: <[PreserveOutput]<"always"|"never"|"failures-only">> + +See [`property: TestConfig.preserveOutput`]. + +## property: ConfigInWorker.projects +* since: v1.10 +- type: <[Array]<[ProjectInWorker]>> + +List of resolved projects. + +## property: ConfigInWorker.quiet +* since: v1.10 +- type: <[boolean]> + +See [`property: TestConfig.quiet`]. + +## property: ConfigInWorker.reporter +* since: v1.10 +- 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 + +See [`property: TestConfig.reporter`]. + +## property: ConfigInWorker.reportSlowTests +* since: v1.10 +- 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. + +See [`property: TestConfig.reportSlowTests`]. + +## property: ConfigInWorker.rootDir +* since: v1.20 +- type: <[string]> + +## property: ConfigInWorker.shard +* since: v1.10 +- type: <[null]|[Object]> + - `total` <[int]> The total number of shards. + - `current` <[int]> The index of the shard to execute, one-based. + +See [`property: TestConfig.shard`]. + +## property: ConfigInWorker.updateSnapshots +* since: v1.10 +- type: <[UpdateSnapshots]<"all"|"none"|"missing">> + +See [`property: TestConfig.updateSnapshots`]. + +## property: ConfigInWorker.version +* since: v1.20 +- type: <[string]> + +Playwright version. + +## property: ConfigInWorker.webServer +* since: v1.10 +- type: <[null]|[Object]> + +See [`property: TestConfig.webServer`]. + +## property: ConfigInWorker.workers +* since: v1.10 +- type: <[int]> + +See [`property: TestConfig.workers`]. diff --git a/docs/src/test-api/class-projectinworker.md b/docs/src/test-api/class-projectinworker.md new file mode 100644 index 0000000000..c8ede102ba --- /dev/null +++ b/docs/src/test-api/class-projectinworker.md @@ -0,0 +1,96 @@ +# class: ProjectInWorker +* since: v1.10 +* langs: js + +Runtime representation of the test project configuration that can be accessed +in the tests via [`property: TestInfo.project`] and [`property: WorkerInfo.project`]. + +## property: ProjectInWorker.dependencies +* since: v1.31 +- type: <[Array]<[string]>> + +See [`property: TestProject.dependencies`]. + +## property: ProjectInWorker.grep +* since: v1.10 +- type: <[RegExp]|[Array]<[RegExp]>> + +See [`property: TestProject.grep`]. + +## property: ProjectInWorker.grepInvert +* since: v1.10 +- type: <[null]|[RegExp]|[Array]<[RegExp]>> + +See [`property: TestProject.grepInvert`]. + +## property: ProjectInWorker.metadata +* since: v1.10 +- type: <[Metadata]> + +See [`property: TestProject.metadata`]. + +## property: ProjectInWorker.name +* since: v1.10 +- type: <[string]> + +See [`property: TestProject.name`]. + +## property: ProjectInWorker.snapshotDir +* since: v1.10 +- type: <[string]> + +See [`property: TestProject.snapshotDir`]. + +## property: ProjectInWorker.outputDir +* since: v1.10 +- type: <[string]> + +See [`property: TestProject.outputDir`]. + +## property: ProjectInWorker.repeatEach +* since: v1.10 +- type: <[int]> + +See [`property: TestProject.repeatEach`]. + +## property: ProjectInWorker.retries +* since: v1.10 +- type: <[int]> + +See [`property: TestProject.retries`]. + +## property: ProjectInWorker.teardown +* since: v1.34 +- type: ?<[string]> + +See [`property: TestProject.teardown`]. + +## property: ProjectInWorker.testDir +* since: v1.10 +- type: <[string]> + +See [`property: TestProject.testDir`]. + +## property: ProjectInWorker.testIgnore +* since: v1.10 +- type: <[string]|[RegExp]|[Array]<[string]|[RegExp]>> + +See [`property: TestProject.testIgnore`]. + +## property: ProjectInWorker.testMatch +* since: v1.10 +- type: <[string]|[RegExp]|[Array]<[string]|[RegExp]>> + +See [`property: TestProject.testMatch`]. + +## property: ProjectInWorker.timeout +* since: v1.10 +- type: <[int]> + +See [`property: TestProject.timeout`]. + +## property: ProjectInWorker.use +* since: v1.10 +- type: <[Fixtures]> + +See [`property: TestProject.use`]. diff --git a/docs/src/test-api/class-testinfo.md b/docs/src/test-api/class-testinfo.md index 97e9c16ebf..096fbfcc10 100644 --- a/docs/src/test-api/class-testinfo.md +++ b/docs/src/test-api/class-testinfo.md @@ -106,7 +106,7 @@ Column number where the currently running test is declared. ## property: TestInfo.config * since: v1.10 -- type: <[TestConfig]> +- type: <[ConfigInWorker]> Processed configuration from the [configuration file](../test-configuration.md). @@ -279,7 +279,7 @@ Also available as `process.env.TEST_PARALLEL_INDEX`. Learn more about [paralleli ## property: TestInfo.project * since: v1.10 -- type: <[TestProject]> +- type: <[ProjectInWorker]> Processed project configuration from the [configuration file](../test-configuration.md). diff --git a/docs/src/test-api/class-workerinfo.md b/docs/src/test-api/class-workerinfo.md index ac8927bfc9..e7ae892190 100644 --- a/docs/src/test-api/class-workerinfo.md +++ b/docs/src/test-api/class-workerinfo.md @@ -6,7 +6,7 @@ ## property: WorkerInfo.config * since: v1.10 -- type: <[TestConfig]> +- type: <[ConfigInWorker]> Processed configuration from the [configuration file](../test-configuration.md). @@ -22,7 +22,7 @@ Also available as `process.env.TEST_PARALLEL_INDEX`. Learn more about [paralleli ## property: WorkerInfo.project * since: v1.10 -- type: <[TestProject]> +- type: <[ProjectInWorker]> Processed project configuration from the [configuration file](../test-configuration.md). diff --git a/docs/src/test-reporter-api/class-fullconfig.md b/docs/src/test-reporter-api/class-fullconfig.md new file mode 100644 index 0000000000..ce4318560f --- /dev/null +++ b/docs/src/test-reporter-api/class-fullconfig.md @@ -0,0 +1,135 @@ +# class: FullConfig +* since: v1.10 +* langs: js + +Resolved configuration passed to [`method: Reporter.onBegin`]. + +## property: FullConfig.configFile +* since: v1.20 +- type: ?<[string]> + +Path to the configuration file (if any) used to run the tests. + +## property: FullConfig.forbidOnly +* since: v1.10 +- type: <[boolean]> + +See [`property: TestConfig.forbidOnly`]. + +## property: FullConfig.fullyParallel +* since: v1.20 +- type: <[boolean]> + +See [`property: TestConfig.fullyParallel`]. + +## property: FullConfig.globalSetup +* since: v1.10 +- type: <[null]|[string]> + +See [`property: TestConfig.globalSetup`]. + +## property: FullConfig.globalTeardown +* since: v1.10 +- type: <[null]|[string]> + +See [`property: TestConfig.globalTeardown`]. + +## property: FullConfig.globalTimeout +* since: v1.10 +- type: <[int]> + +See [`property: TestConfig.globalTimeout`]. + +## property: FullConfig.grep +* since: v1.10 +- type: <[RegExp]|[Array]<[RegExp]>> + +See [`property: TestConfig.grep`]. + +## property: FullConfig.grepInvert +* since: v1.10 +- type: <[null]|[RegExp]|[Array]<[RegExp]>> + +See [`property: TestConfig.grepInvert`]. + +## property: FullConfig.maxFailures +* since: v1.10 +- type: <[int]> + +See [`property: TestConfig.maxFailures`]. + +## property: FullConfig.metadata +* since: v1.10 +- type: <[Metadata]> + +See [`property: TestConfig.metadata`]. + +## property: FullConfig.preserveOutput +* since: v1.10 +- type: <[PreserveOutput]<"always"|"never"|"failures-only">> + +See [`property: TestConfig.preserveOutput`]. + +## property: FullConfig.projects +* since: v1.10 +- type: <[Array]<[FullProject]>> + +List of resolved projects. + +## property: FullConfig.quiet +* since: v1.10 +- type: <[boolean]> + +See [`property: TestConfig.quiet`]. + +## property: FullConfig.reporter +* since: v1.10 +- 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 + +See [`property: TestConfig.reporter`]. + +## property: FullConfig.reportSlowTests +* since: v1.10 +- 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. + +See [`property: TestConfig.reportSlowTests`]. + +## property: FullConfig.rootDir +* since: v1.20 +- type: <[string]> + +## property: FullConfig.shard +* since: v1.10 +- type: <[null]|[Object]> + - `total` <[int]> The total number of shards. + - `current` <[int]> The index of the shard to execute, one-based. + +See [`property: TestConfig.shard`]. + +## property: FullConfig.updateSnapshots +* since: v1.10 +- type: <[UpdateSnapshots]<"all"|"none"|"missing">> + +See [`property: TestConfig.updateSnapshots`]. + +## property: FullConfig.version +* since: v1.20 +- type: <[string]> + +Playwright version. + +## property: FullConfig.webServer +* since: v1.10 +- type: <[null]|[Object]> + +See [`property: TestConfig.webServer`]. + +## property: FullConfig.workers +* since: v1.10 +- type: <[int]> + +See [`property: TestConfig.workers`]. diff --git a/docs/src/test-reporter-api/class-fullproject.md b/docs/src/test-reporter-api/class-fullproject.md new file mode 100644 index 0000000000..9a744115df --- /dev/null +++ b/docs/src/test-reporter-api/class-fullproject.md @@ -0,0 +1,98 @@ +# class: FullProject +* since: v1.10 +* langs: js + +Runtime representation of the test project configuration that is passed +to [Reporter]. It exposes some of the resolved fields declared in +[TestProject]. You can get [FullProject] instance from [`property: FullConfig.projects`] +or [`method: Suite.project`]. + +## property: FullProject.dependencies +* since: v1.31 +- type: <[Array]<[string]>> + +See [`property: TestProject.dependencies`]. + +## property: FullProject.grep +* since: v1.10 +- type: <[RegExp]|[Array]<[RegExp]>> + +See [`property: TestProject.grep`]. + +## property: FullProject.grepInvert +* since: v1.10 +- type: <[null]|[RegExp]|[Array]<[RegExp]>> + +See [`property: TestProject.grepInvert`]. + +## property: FullProject.metadata +* since: v1.10 +- type: <[Metadata]> + +See [`property: TestProject.metadata`]. + +## property: FullProject.name +* since: v1.10 +- type: <[string]> + +See [`property: TestProject.name`]. + +## property: FullProject.snapshotDir +* since: v1.10 +- type: <[string]> + +See [`property: TestProject.snapshotDir`]. + +## property: FullProject.outputDir +* since: v1.10 +- type: <[string]> + +See [`property: TestProject.outputDir`]. + +## property: FullProject.repeatEach +* since: v1.10 +- type: <[int]> + +See [`property: TestProject.repeatEach`]. + +## property: FullProject.retries +* since: v1.10 +- type: <[int]> + +See [`property: TestProject.retries`]. + +## property: FullProject.teardown +* since: v1.34 +- type: ?<[string]> + +See [`property: TestProject.teardown`]. + +## property: FullProject.testDir +* since: v1.10 +- type: <[string]> + +See [`property: TestProject.testDir`]. + +## property: FullProject.testIgnore +* since: v1.10 +- type: <[string]|[RegExp]|[Array]<[string]|[RegExp]>> + +See [`property: TestProject.testIgnore`]. + +## property: FullProject.testMatch +* since: v1.10 +- type: <[string]|[RegExp]|[Array]<[string]|[RegExp]>> + +See [`property: TestProject.testMatch`]. + +## property: FullProject.timeout +* since: v1.10 +- type: <[int]> + +See [`property: TestProject.timeout`]. + +## property: FullProject.use +* since: v1.10 +- type: <[Fixtures]> + +See [`property: TestProject.use`]. diff --git a/docs/src/test-reporter-api/class-reporter.md b/docs/src/test-reporter-api/class-reporter.md index ead4002171..7b3d394cc8 100644 --- a/docs/src/test-reporter-api/class-reporter.md +++ b/docs/src/test-reporter-api/class-reporter.md @@ -103,7 +103,7 @@ Called once before running tests. All tests have been already discovered and put ### param: Reporter.onBegin.config * since: v1.10 -- `config` <[TestConfig]> +- `config` <[FullConfig]> Resolved configuration. diff --git a/docs/src/test-reporter-api/class-suite.md b/docs/src/test-reporter-api/class-suite.md index fc6b3e0aa9..80642def9e 100644 --- a/docs/src/test-reporter-api/class-suite.md +++ b/docs/src/test-reporter-api/class-suite.md @@ -4,7 +4,7 @@ `Suite` is a group of tests. All tests in Playwright Test form the following hierarchy: -* Root suite has a child suite for each [TestProject]. +* Root suite has a child suite for each [FullProject]. * Project suite #1. Has a child suite for each test file in the project. * File suite #1 * [TestCase] #1 @@ -46,7 +46,7 @@ Parent suite, missing for the root suite. ## method: Suite.project * since: v1.10 -- returns: ?<[TestProject]> +- returns: <[FullProject]|[undefined]> Configuration of the project this suite belongs to, or [void] for the root suite. diff --git a/packages/playwright-ct-core/src/cliOverrides.ts b/packages/playwright-ct-core/src/cliOverrides.ts index 3ebcd09cbc..aaa456427c 100644 --- a/packages/playwright-ct-core/src/cliOverrides.ts +++ b/packages/playwright-ct-core/src/cliOverrides.ts @@ -19,8 +19,7 @@ import { removeFolder } from 'playwright/lib/program'; import { affectedTestFiles, cacheDir } from 'playwright/lib/transform/compilationCache'; import { buildBundle } from './vitePlugin'; import { resolveDirs } from './viteUtils'; -import type { Suite } from 'playwright/lib/common/test'; -import type { FullConfig } from 'playwright/test'; +import type { FullConfig, Suite } from 'playwright/types/testReporter'; export async function clearCacheCommand(config: FullConfig, configDir: string) { const dirs = await resolveDirs(configDir, config); diff --git a/packages/playwright-ct-core/src/vitePlugin.ts b/packages/playwright-ct-core/src/vitePlugin.ts index cc26fdc807..26964e079b 100644 --- a/packages/playwright-ct-core/src/vitePlugin.ts +++ b/packages/playwright-ct-core/src/vitePlugin.ts @@ -22,8 +22,7 @@ import { assert, calculateSha1, getPlaywrightVersion, isURLAvailable } from 'pla import { debug } from 'playwright-core/lib/utilsBundle'; import { internalDependenciesForTestFile, setExternalDependencies } from 'playwright/lib/transform/compilationCache'; import { stoppable } from 'playwright/lib/utilsBundle'; -import type { FullConfig } from 'playwright/test'; -import type { Suite } from 'playwright/types/testReporter'; +import type { FullConfig, Suite } from 'playwright/types/testReporter'; import type { PluginContext } from 'rollup'; import type { Plugin, ResolveFn, ResolvedConfig } from 'vite'; import type { TestRunnerPlugin } from '../../playwright/src/plugins'; diff --git a/packages/playwright-ct-core/src/viteUtils.ts b/packages/playwright-ct-core/src/viteUtils.ts index 00da627432..505301c48e 100644 --- a/packages/playwright-ct-core/src/viteUtils.ts +++ b/packages/playwright-ct-core/src/viteUtils.ts @@ -18,7 +18,8 @@ import fs from 'fs'; import path from 'path'; import { debug } from 'playwright-core/lib/utilsBundle'; import { getUserData } from 'playwright/lib/transform/compilationCache'; -import type { PlaywrightTestConfig as BasePlaywrightTestConfig, FullConfig } from 'playwright/test'; +import type { PlaywrightTestConfig as BasePlaywrightTestConfig } from 'playwright/types/test'; +import type { FullConfig } from 'playwright/types/testReporter'; import type { InlineConfig, Plugin, TransformResult, UserConfig } from 'vite'; import type { ImportInfo } from './tsxTransform'; import { resolveHook } from 'playwright/lib/transform/transform'; diff --git a/packages/playwright/src/common/config.ts b/packages/playwright/src/common/config.ts index cfe294a75c..9b8be8e730 100644 --- a/packages/playwright/src/common/config.ts +++ b/packages/playwright/src/common/config.ts @@ -23,7 +23,7 @@ import type { TestRunnerPluginRegistration } from '../plugins'; import { getPackageJsonPath, mergeObjects } from '../util'; import type { Matcher } from '../util'; import type { ConfigCLIOverrides } from './ipc'; -import type { FullConfig, FullProject } from '../../types/test'; +import type { FullConfig, FullProject } from '../../types/testReporter'; import { setTransformConfig } from '../transform/transform'; export type ConfigLocation = { @@ -46,7 +46,7 @@ export class FullConfigInternal { readonly configCLIOverrides: ConfigCLIOverrides; readonly ignoreSnapshots: boolean; readonly preserveOutputDir: boolean; - readonly webServers: Exclude[]; + readonly webServers: NonNullable[]; readonly plugins: TestRunnerPluginRegistration[]; readonly projects: FullProjectInternal[] = []; cliArgs: string[] = []; @@ -182,7 +182,7 @@ export class FullProjectInternal { // project is top-level vs dependency. See collectProjectsAndTestFiles in loadUtils. repeatEach: takeFirst(projectConfig.repeatEach, config.repeatEach, 1), retries: takeFirst(configCLIOverrides.retries, projectConfig.retries, config.retries, 0), - metadata: takeFirst(projectConfig.metadata, config.metadata, undefined), + metadata: takeFirst(projectConfig.metadata, config.metadata, {}), name: takeFirst(projectConfig.name, config.name, ''), testDir, snapshotDir: takeFirst(pathResolve(configDir, projectConfig.snapshotDir), pathResolve(configDir, config.snapshotDir), testDir), diff --git a/packages/playwright/src/common/test.ts b/packages/playwright/src/common/test.ts index 50f547b6ee..5f22f8fe3b 100644 --- a/packages/playwright/src/common/test.ts +++ b/packages/playwright/src/common/test.ts @@ -19,8 +19,7 @@ import type * as reporterTypes from '../../types/testReporter'; import type { TestTypeImpl } from './testType'; import { rootTestType } from './testType'; import type { Annotation, FixturesWithLocation, FullProjectInternal } from './config'; -import type { FullProject } from '../../types/test'; -import type { Location } from '../../types/testReporter'; +import type { Location, FullProject } from '../../types/testReporter'; class Base { title: string; diff --git a/packages/playwright/src/isomorphic/teleReceiver.ts b/packages/playwright/src/isomorphic/teleReceiver.ts index 879d37e010..5b23b4a7b3 100644 --- a/packages/playwright/src/isomorphic/teleReceiver.ts +++ b/packages/playwright/src/isomorphic/teleReceiver.ts @@ -15,7 +15,7 @@ */ import type { Annotation } from '../common/config'; -import type { FullProject, Metadata } from '../../types/test'; +import type { Metadata } from '../../types/test'; import type * as reporterTypes from '../../types/testReporter'; import type { ReporterV2 } from '../reporters/reporterV2'; @@ -590,7 +590,7 @@ class TeleTestResult implements reporterTypes.TestResult { } } -export type TeleFullProject = FullProject; +export type TeleFullProject = reporterTypes.FullProject; export const baseFullConfig: reporterTypes.FullConfig = { forbidOnly: false, diff --git a/packages/playwright/src/worker/testInfo.ts b/packages/playwright/src/worker/testInfo.ts index 3e0dab8b95..cb3d352f40 100644 --- a/packages/playwright/src/worker/testInfo.ts +++ b/packages/playwright/src/worker/testInfo.ts @@ -17,7 +17,7 @@ import fs from 'fs'; import path from 'path'; import { captureRawStack, monotonicTime, zones, sanitizeForFilePath, stringifyStackFrames } from 'playwright-core/lib/utils'; -import type { TestInfoError, TestInfo, TestStatus, FullProject, FullConfig } from '../../types/test'; +import type { TestInfoError, TestInfo, TestStatus, ProjectInWorker, ConfigInWorker } from '../../types/test'; import type { AttachmentPayload, StepBeginPayload, StepEndPayload, WorkerInitParams } from '../common/ipc'; import type { TestCase } from '../common/test'; import { TimeoutManager, TimeoutManagerError, kMaxDeadline } from './timeoutManager'; @@ -81,8 +81,8 @@ export class TestInfoImpl implements TestInfo { readonly retry: number; readonly workerIndex: number; readonly parallelIndex: number; - readonly project: FullProject; - readonly config: FullConfig; + readonly project: ProjectInWorker; + readonly config: ConfigInWorker; readonly title: string; readonly titlePath: string[]; readonly file: string; diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index 8bdfe088c8..5d9911f07c 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -30,7 +30,7 @@ export type ReporterDescription = ['null'] | [string] | [string, any]; -type UseOptions = { [K in keyof WorkerArgs]?: WorkerArgs[K] } & { [K in keyof TestArgs]?: TestArgs[K] }; +type UseOptions = Partial & Partial; /** * Playwright Test supports running multiple test projects at the same time. This is useful for running tests in @@ -111,336 +111,84 @@ export interface Project extends TestProject { } /** - * Playwright Test supports running multiple test projects at the same time. This is useful for running tests in - * multiple configurations. For example, consider running tests against multiple browsers. - * - * `TestProject` encapsulates configuration specific to a single project. Projects are configured in - * [testConfig.projects](https://playwright.dev/docs/api/class-testconfig#test-config-projects) specified in the - * [configuration file](https://playwright.dev/docs/test-configuration). Note that all properties of {@link TestProject} are available in - * the top-level {@link TestConfig}, in which case they are shared between all projects. - * - * Here is an example configuration that runs every test in Chromium, Firefox and WebKit, both Desktop and Mobile - * versions. - * - * ```js - * // playwright.config.ts - * import { defineConfig, devices } from '@playwright/test'; - * - * export default defineConfig({ - * // Options shared for all projects. - * timeout: 30000, - * use: { - * ignoreHTTPSErrors: true, - * }, - * - * // Options specific to each project. - * projects: [ - * { - * name: 'chromium', - * use: devices['Desktop Chrome'], - * }, - * { - * name: 'firefox', - * use: devices['Desktop Firefox'], - * }, - * { - * name: 'webkit', - * use: devices['Desktop Safari'], - * }, - * { - * name: 'Mobile Chrome', - * use: devices['Pixel 5'], - * }, - * { - * name: 'Mobile Safari', - * use: devices['iPhone 12'], - * }, - * ], - * }); - * ``` - * + * Runtime representation of the test project configuration that can be accessed in the tests via + * [testInfo.project](https://playwright.dev/docs/api/class-testinfo#test-info-project) and + * [workerInfo.project](https://playwright.dev/docs/api/class-workerinfo#worker-info-project). */ -export interface FullProject { +export interface ProjectInWorker { /** - * 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](https://playwright.dev/docs/test-cli) with the `-g` - * option. The regular expression will be tested against the string that consists of the test file name, - * `test.describe` name (if any) and the test name divided by spaces, e.g. `my-test.spec.ts my-suite my-test`. - * - * `grep` option is also useful for [tagging tests](https://playwright.dev/docs/test-annotations#tag-tests). - */ - grep: RegExp | RegExp[]; - /** - * Filter to only run tests with a title **not** matching one of the patterns. This is the opposite of - * [testProject.grep](https://playwright.dev/docs/api/class-testproject#test-project-grep). Also available globally - * and in the [command line](https://playwright.dev/docs/test-cli) with the `--grep-invert` option. - * - * `grepInvert` option is also useful for [tagging tests](https://playwright.dev/docs/test-annotations#tag-tests). - */ - grepInvert: RegExp | RegExp[] | null; - /** - * Metadata that will be put directly to the test report serialized as JSON. - */ - metadata: Metadata; - /** - * Project name is visible in the report and during test execution. - */ - name: string; - /** - * List of projects that need to run before any test in this project runs. Dependencies can be useful for configuring - * the global setup actions in a way that every action is in a form of a test. Passing `--no-deps` argument ignores - * the dependencies and behaves as if they were not specified. - * - * Using dependencies allows global setup to produce traces and other artifacts, see the setup steps in the test - * report, etc. - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * projects: [ - * { - * name: 'setup', - * testMatch: /global.setup\.ts/, - * }, - * { - * name: 'chromium', - * use: devices['Desktop Chrome'], - * dependencies: ['setup'], - * }, - * { - * name: 'firefox', - * use: devices['Desktop Firefox'], - * dependencies: ['setup'], - * }, - * { - * name: 'webkit', - * use: devices['Desktop Safari'], - * dependencies: ['setup'], - * }, - * ], - * }); - * ``` - * - */ - dependencies: string[]; - /** - * The base directory, relative to the config file, for snapshot files created with `toMatchSnapshot`. Defaults to - * [testProject.testDir](https://playwright.dev/docs/api/class-testproject#test-project-test-dir). - * - * The directory for each test can be accessed by - * [testInfo.snapshotDir](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-dir) and - * [testInfo.snapshotPath(...pathSegments)](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-path). - * - * This path will serve as the base directory for each test file snapshot directory. Setting `snapshotDir` to - * `'snapshots'`, the [testInfo.snapshotDir](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-dir) - * would resolve to `snapshots/a.spec.js-snapshots`. - */ - snapshotDir: string; - /** - * The output directory for files created during test execution. Defaults to `/test-results`. - * - * This directory is cleaned at the start. When running a test, a unique subdirectory inside the - * [testProject.outputDir](https://playwright.dev/docs/api/class-testproject#test-project-output-dir) is created, - * guaranteeing that test running in parallel do not conflict. This directory can be accessed by - * [testInfo.outputDir](https://playwright.dev/docs/api/class-testinfo#test-info-output-dir) and - * [testInfo.outputPath(...pathSegments)](https://playwright.dev/docs/api/class-testinfo#test-info-output-path). - * - * Here is an example that uses - * [testInfo.outputPath(...pathSegments)](https://playwright.dev/docs/api/class-testinfo#test-info-output-path) to - * create a temporary file. - * - * ```js - * import { test, expect } from '@playwright/test'; - * import fs from 'fs'; - * - * test('example test', async ({}, testInfo) => { - * const file = testInfo.outputPath('temporary-file.txt'); - * await fs.promises.writeFile(file, 'Put some data to the file', 'utf8'); - * }); - * ``` - * - * Use [testConfig.outputDir](https://playwright.dev/docs/api/class-testconfig#test-config-output-dir) to change this - * option for all projects. - */ - outputDir: string; - /** - * The number of times to repeat each test, useful for debugging flaky tests. - * - * Use [testConfig.repeatEach](https://playwright.dev/docs/api/class-testconfig#test-config-repeat-each) to change - * this option for all projects. - */ - repeatEach: number; - /** - * The maximum number of retry attempts given to failed tests. Learn more about - * [test retries](https://playwright.dev/docs/test-retries#retries). - * - * Use [test.describe.configure([options])](https://playwright.dev/docs/api/class-test#test-describe-configure) to - * change the number of retries for a specific file or a group of tests. - * - * Use [testConfig.retries](https://playwright.dev/docs/api/class-testconfig#test-config-retries) to change this - * option for all projects. - */ - retries: number; - /** - * Name of a project that needs to run after this and all dependent projects have finished. Teardown is useful to - * cleanup any resources acquired by this project. - * - * Passing `--no-deps` argument ignores - * [testProject.teardown](https://playwright.dev/docs/api/class-testproject#test-project-teardown) and behaves as if - * it was not specified. - * - * **Usage** - * - * A common pattern is a "setup" dependency that has a corresponding "teardown": - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * projects: [ - * { - * name: 'setup', - * testMatch: /global.setup\.ts/, - * teardown: 'teardown', - * }, - * { - * name: 'teardown', - * testMatch: /global.teardown\.ts/, - * }, - * { - * name: 'chromium', - * use: devices['Desktop Chrome'], - * dependencies: ['setup'], - * }, - * { - * name: 'firefox', - * use: devices['Desktop Firefox'], - * dependencies: ['setup'], - * }, - * { - * name: 'webkit', - * use: devices['Desktop Safari'], - * dependencies: ['setup'], - * }, - * ], - * }); - * ``` - * - */ - teardown?: string; - /** - * Directory that will be recursively scanned for test files. Defaults to the directory of the configuration file. - * - * Each project can use a different directory. Here is an example that runs smoke tests in three browsers and all - * other tests in stable Chrome browser. - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * projects: [ - * { - * name: 'Smoke Chromium', - * testDir: './smoke-tests', - * use: { - * browserName: 'chromium', - * } - * }, - * { - * name: 'Smoke WebKit', - * testDir: './smoke-tests', - * use: { - * browserName: 'webkit', - * } - * }, - * { - * name: 'Smoke Firefox', - * testDir: './smoke-tests', - * use: { - * browserName: 'firefox', - * } - * }, - * { - * name: 'Chrome Stable', - * testDir: './', - * use: { - * browserName: 'chromium', - * channel: 'chrome', - * } - * }, - * ], - * }); - * ``` - * - * Use [testConfig.testDir](https://playwright.dev/docs/api/class-testconfig#test-config-test-dir) to change this - * option for all projects. - */ - testDir: string; - /** - * 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. - * - * For example, `'**\/test-assets/**'` will ignore any files in the `test-assets` directory. - * - * Use [testConfig.testIgnore](https://playwright.dev/docs/api/class-testconfig#test-config-test-ignore) to change - * this option for all projects. - */ - testIgnore: string | RegExp | (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. - * - * By default, Playwright looks for files matching the following glob pattern: `**\/*.@(spec|test).?(c|m)[jt]s?(x)`. - * This means JavaScript or TypeScript files with `".test"` or `".spec"` suffix, for example - * `login-screen.wrong-credentials.spec.ts`. - * - * Use [testConfig.testMatch](https://playwright.dev/docs/api/class-testconfig#test-config-test-match) to change this - * option for all projects. - */ - testMatch: string | RegExp | (string | RegExp)[]; - /** - * Timeout for each test in milliseconds. Defaults to 30 seconds. - * - * This is a base timeout for all tests. Each test can configure its own timeout with - * [test.setTimeout(timeout)](https://playwright.dev/docs/api/class-test#test-set-timeout). Each file or a group of - * tests can configure the timeout with - * [test.describe.configure([options])](https://playwright.dev/docs/api/class-test#test-describe-configure). - * - * Use [testConfig.timeout](https://playwright.dev/docs/api/class-testconfig#test-config-timeout) to change this - * option for all projects. - */ - timeout: number; - /** - * Options for all tests in this project, for example - * [testOptions.browserName](https://playwright.dev/docs/api/class-testoptions#test-options-browser-name). Learn more - * about [configuration](https://playwright.dev/docs/test-configuration) and see [available options]{@link TestOptions}. - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * projects: [ - * { - * name: 'Chromium', - * use: { - * browserName: 'chromium', - * }, - * }, - * ], - * }); - * ``` - * - * Use [testConfig.use](https://playwright.dev/docs/api/class-testconfig#test-config-use) to change this option for - * all projects. + * See [testProject.use](https://playwright.dev/docs/api/class-testproject#test-project-use). */ use: UseOptions; + /** + * See [testProject.dependencies](https://playwright.dev/docs/api/class-testproject#test-project-dependencies). + */ + dependencies: Array; + + /** + * See [testProject.grep](https://playwright.dev/docs/api/class-testproject#test-project-grep). + */ + grep: RegExp|Array; + + /** + * See [testProject.grepInvert](https://playwright.dev/docs/api/class-testproject#test-project-grep-invert). + */ + grepInvert: null|RegExp|Array; + + /** + * See [testProject.metadata](https://playwright.dev/docs/api/class-testproject#test-project-metadata). + */ + metadata: Metadata; + + /** + * See [testProject.name](https://playwright.dev/docs/api/class-testproject#test-project-name). + */ + name: string; + + /** + * See [testProject.outputDir](https://playwright.dev/docs/api/class-testproject#test-project-output-dir). + */ + outputDir: string; + + /** + * See [testProject.repeatEach](https://playwright.dev/docs/api/class-testproject#test-project-repeat-each). + */ + repeatEach: number; + + /** + * See [testProject.retries](https://playwright.dev/docs/api/class-testproject#test-project-retries). + */ + retries: number; + + /** + * See [testProject.snapshotDir](https://playwright.dev/docs/api/class-testproject#test-project-snapshot-dir). + */ + snapshotDir: string; + + /** + * See [testProject.teardown](https://playwright.dev/docs/api/class-testproject#test-project-teardown). + */ + teardown?: string; + + /** + * See [testProject.testDir](https://playwright.dev/docs/api/class-testproject#test-project-test-dir). + */ + testDir: string; + + /** + * See [testProject.testIgnore](https://playwright.dev/docs/api/class-testproject#test-project-test-ignore). + */ + testIgnore: string|RegExp|Array; + + /** + * See [testProject.testMatch](https://playwright.dev/docs/api/class-testproject#test-project-test-match). + */ + testMatch: string|RegExp|Array; + + /** + * See [testProject.timeout](https://playwright.dev/docs/api/class-testproject#test-project-timeout). + */ + timeout: number; } type LiteralUnion = T | (U & { zz_IGNORE_ME?: never }); @@ -1445,928 +1193,133 @@ export interface Config extends TestConfig { export type Metadata = { [key: string]: any }; /** - * Playwright Test provides many options to configure how your tests are collected and executed, for example `timeout` - * or `testDir`. These options are described in the {@link TestConfig} object in the - * [configuration file](https://playwright.dev/docs/test-configuration). - * - * Playwright Test supports running multiple test projects at the same time. Project-specific options should be put to - * [testConfig.projects](https://playwright.dev/docs/api/class-testconfig#test-config-projects), but top-level {@link - * TestConfig} can also define base options shared between all projects. - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * timeout: 30000, - * globalTimeout: 600000, - * reporter: 'list', - * testDir: './tests', - * }); - * ``` - * + * Resolved configuration available via + * [testInfo.config](https://playwright.dev/docs/api/class-testinfo#test-info-config) and + * [workerInfo.config](https://playwright.dev/docs/api/class-workerinfo#worker-info-config). */ -export interface FullConfig { +export interface ConfigInWorker { /** - * Whether to exit with an error if any tests or groups are marked as - * [test.only(title[, details, body])](https://playwright.dev/docs/api/class-test#test-only) or - * [test.describe.only([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe-only). - * Useful on CI. - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * forbidOnly: !!process.env.CI, - * }); - * ``` - * + * List of resolved projects. */ - forbidOnly: boolean; + projects: ProjectInWorker[]; /** - * 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. - * - * You can configure entire test run to concurrently execute all tests in all files using this option. - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * fullyParallel: true, - * }); - * ``` - * - */ - fullyParallel: boolean; - /** - * 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. - * - * Learn more about [global setup and teardown](https://playwright.dev/docs/test-global-setup-teardown). - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * globalSetup: './global-setup', - * }); - * ``` - * - */ - globalSetup: string | null; - /** - * 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 - * [testConfig.globalSetup](https://playwright.dev/docs/api/class-testconfig#test-config-global-setup). - * - * Learn more about [global setup and teardown](https://playwright.dev/docs/test-global-setup-teardown). - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * globalTeardown: './global-teardown', - * }); - * ``` - * - */ - globalTeardown: string | null; - /** - * 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](https://playwright.dev/docs/test-timeouts). - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * globalTimeout: process.env.CI ? 60 * 60 * 1000 : undefined, - * }); - * ``` - * - */ - globalTimeout: number; - /** - * 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](https://playwright.dev/docs/test-cli) with the `-g` option. The - * regular expression will be tested against the string that consists of the test file name, `test.describe` name (if - * any) and the test name divided by spaces, e.g. `my-test.spec.ts my-suite my-test`. - * - * `grep` option is also useful for [tagging tests](https://playwright.dev/docs/test-annotations#tag-tests). - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * grep: /smoke/, - * }); - * ``` - * - */ - grep: RegExp | RegExp[]; - /** - * Filter to only run tests with a title **not** matching one of the patterns. This is the opposite of - * [testConfig.grep](https://playwright.dev/docs/api/class-testconfig#test-config-grep). Also available in the - * [command line](https://playwright.dev/docs/test-cli) with the `--grep-invert` option. - * - * `grepInvert` option is also useful for [tagging tests](https://playwright.dev/docs/test-annotations#tag-tests). - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * grepInvert: /manual/, - * }); - * ``` - * - */ - grepInvert: RegExp | RegExp[] | null; - /** - * 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. - * - * Also available in the [command line](https://playwright.dev/docs/test-cli) with the `--max-failures` and `-x` options. - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * maxFailures: process.env.CI ? 1 : 0, - * }); - * ``` - * - */ - maxFailures: number; - /** - * Metadata that will be put directly to the test report serialized as JSON. - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * metadata: 'acceptance tests', - * }); - * ``` - * - */ - metadata: Metadata; - version: string; - /** - * Whether to preserve test output in the - * [testConfig.outputDir](https://playwright.dev/docs/api/class-testconfig#test-config-output-dir). Defaults to - * `'always'`. - * - `'always'` - preserve output for all tests; - * - `'never'` - do not preserve output for any tests; - * - `'failures-only'` - only preserve output for failed tests. - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * preserveOutput: 'always', - * }); - * ``` - * - */ - preserveOutput: 'always' | 'never' | 'failures-only'; - /** - * Playwright Test supports running multiple test projects at the same time. See {@link TestProject} for more - * information. - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig, devices } from '@playwright/test'; - * - * export default defineConfig({ - * projects: [ - * { name: 'chromium', use: devices['Desktop Chrome'] } - * ] - * }); - * ``` - * - */ - projects: FullProject[]; - /** - * The list of reporters to use. Each reporter can be: - * - A builtin reporter name like `'list'` or `'json'`. - * - A module name like `'my-awesome-reporter'`. - * - A relative path to the reporter like `'./reporters/my-awesome-reporter.js'`. - * - * You can pass options to the reporter in a tuple like `['json', { outputFile: './report.json' }]`. - * - * Learn more in the [reporters guide](https://playwright.dev/docs/test-reporters). - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * reporter: 'line', - * }); - * ``` - * + * See [testConfig.reporter](https://playwright.dev/docs/api/class-testconfig#test-config-reporter). */ reporter: ReporterDescription[]; /** - * Whether to report slow test files. Pass `null` to disable this feature. - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * reportSlowTests: null, - * }); - * ``` - * - * **Details** - * - * 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. - */ - reportSlowTests: { max: number, threshold: number } | null; - rootDir: string; - /** - * Whether to suppress stdio and stderr output from the tests. - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * quiet: !!process.env.CI, - * }); - * ``` - * - */ - quiet: boolean; - /** - * Shard tests and execute only the selected shard. Specify in the one-based form like `{ total: 5, current: 2 }`. - * - * Learn more about [parallelism and sharding](https://playwright.dev/docs/test-parallel) with Playwright Test. - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * shard: { total: 10, current: 3 }, - * }); - * ``` - * - */ - shard: { total: number, current: number } | null; - /** - * 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 that did not match. Matching snapshots will not be - * updated. - * - `'none'` - No snapshots are updated. - * - `'missing'` - Missing snapshots are created, for example when authoring a new test and running it for the first - * time. This is the default. - * - * Learn more about [snapshots](https://playwright.dev/docs/test-snapshots). - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * updateSnapshots: 'missing', - * }); - * ``` - * - */ - updateSnapshots: 'all' | 'none' | 'missing'; - /** - * The maximum number of concurrent worker processes to use for parallelizing tests. Can also be set as percentage of - * logical CPU cores, e.g. `'50%'.` - * - * Playwright Test uses worker processes to run tests. There is always at least one worker process, but more can be - * used to speed up test execution. - * - * Defaults to half of the number of logical CPU cores. Learn more about - * [parallelism and sharding](https://playwright.dev/docs/test-parallel) with Playwright Test. - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * - * export default defineConfig({ - * workers: 3, - * }); - * ``` - * - */ - workers: number; - /** - * Launch a development web server (or multiple) during the tests. - * - * **Details** - * - * If the port is specified, Playwright Test will wait for it to be available on `127.0.0.1` or `::1`, before running - * the tests. If the url is specified, Playwright Test will wait for the URL to return a 2xx, 3xx, 400, 401, 402, or - * 403 status code before running the tests. - * - * For continuous integration, you may want to use the `reuseExistingServer: !process.env.CI` option which does not - * use an existing server on the CI. To see the stdout, you can set the `DEBUG=pw:webserver` environment variable. - * - * The `port` (but not the `url`) gets passed over to Playwright as a - * [testOptions.baseURL](https://playwright.dev/docs/api/class-testoptions#test-options-base-url). For example port - * `8080` produces `baseURL` equal `http://localhost:8080`. If `webServer` is specified as an array, you must - * explicitly configure the `baseURL` (even if it only has one entry). - * - * **NOTE** It is also recommended to specify - * [testOptions.baseURL](https://playwright.dev/docs/api/class-testoptions#test-options-base-url) in the config, so - * that tests could use relative urls. - * - * **Usage** - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * export default defineConfig({ - * webServer: { - * command: 'npm run start', - * url: 'http://127.0.0.1:3000', - * timeout: 120 * 1000, - * reuseExistingServer: !process.env.CI, - * }, - * use: { - * baseURL: 'http://localhost:3000/', - * }, - * }); - * ``` - * - * Now you can use a relative path when navigating the page: - * - * ```js - * // test.spec.ts - * import { test } from '@playwright/test'; - * - * test('test', async ({ page }) => { - * // This will result in http://localhost:3000/foo - * await page.goto('/foo'); - * }); - * ``` - * - * Multiple web servers (or background processes) can be launched: - * - * ```js - * // playwright.config.ts - * import { defineConfig } from '@playwright/test'; - * export default defineConfig({ - * webServer: [ - * { - * command: 'npm run start', - * url: 'http://127.0.0.1:3000', - * timeout: 120 * 1000, - * reuseExistingServer: !process.env.CI, - * }, - * { - * command: 'npm run backend', - * url: 'http://127.0.0.1:3333', - * timeout: 120 * 1000, - * reuseExistingServer: !process.env.CI, - * } - * ], - * use: { - * baseURL: 'http://127.0.0.1:3000', - * }, - * }); - * ``` - * + * See [testConfig.webServer](https://playwright.dev/docs/api/class-testconfig#test-config-web-server). */ webServer: TestConfigWebServer | null; + /** + * Path to the configuration file (if any) used to run the tests. + */ configFile?: string; + + /** + * See [testConfig.forbidOnly](https://playwright.dev/docs/api/class-testconfig#test-config-forbid-only). + */ + forbidOnly: boolean; + + /** + * See [testConfig.fullyParallel](https://playwright.dev/docs/api/class-testconfig#test-config-fully-parallel). + */ + fullyParallel: boolean; + + /** + * See [testConfig.globalSetup](https://playwright.dev/docs/api/class-testconfig#test-config-global-setup). + */ + globalSetup: null|string; + + /** + * See [testConfig.globalTeardown](https://playwright.dev/docs/api/class-testconfig#test-config-global-teardown). + */ + globalTeardown: null|string; + + /** + * See [testConfig.globalTimeout](https://playwright.dev/docs/api/class-testconfig#test-config-global-timeout). + */ + globalTimeout: number; + + /** + * See [testConfig.grep](https://playwright.dev/docs/api/class-testconfig#test-config-grep). + */ + grep: RegExp|Array; + + /** + * See [testConfig.grepInvert](https://playwright.dev/docs/api/class-testconfig#test-config-grep-invert). + */ + grepInvert: null|RegExp|Array; + + /** + * See [testConfig.maxFailures](https://playwright.dev/docs/api/class-testconfig#test-config-max-failures). + */ + maxFailures: number; + + /** + * See [testConfig.metadata](https://playwright.dev/docs/api/class-testconfig#test-config-metadata). + */ + metadata: Metadata; + + /** + * See [testConfig.preserveOutput](https://playwright.dev/docs/api/class-testconfig#test-config-preserve-output). + */ + preserveOutput: "always"|"never"|"failures-only"; + + /** + * See [testConfig.quiet](https://playwright.dev/docs/api/class-testconfig#test-config-quiet). + */ + quiet: boolean; + + /** + * See [testConfig.reportSlowTests](https://playwright.dev/docs/api/class-testconfig#test-config-report-slow-tests). + */ + reportSlowTests: null|{ + /** + * The maximum number of slow test files to report. Defaults to `5`. + */ + max: number; + + /** + * Test duration in milliseconds that is considered slow. Defaults to 15 seconds. + */ + threshold: number; + }; + + rootDir: string; + + /** + * See [testConfig.shard](https://playwright.dev/docs/api/class-testconfig#test-config-shard). + */ + shard: null|{ + /** + * The total number of shards. + */ + total: number; + + /** + * The index of the shard to execute, one-based. + */ + current: number; + }; + + /** + * See [testConfig.updateSnapshots](https://playwright.dev/docs/api/class-testconfig#test-config-update-snapshots). + */ + updateSnapshots: "all"|"none"|"missing"; + + /** + * Playwright version. + */ + version: string; + + /** + * See [testConfig.workers](https://playwright.dev/docs/api/class-testconfig#test-config-workers). + */ + workers: number; } export type TestStatus = 'passed' | 'failed' | 'timedOut' | 'skipped' | 'interrupted'; -/** - * `WorkerInfo` contains information about the worker that is running tests and is available to worker-scoped - * fixtures. `WorkerInfo` is a subset of {@link TestInfo} that is available in many other places. - */ -export interface WorkerInfo { - /** - * Processed configuration from the [configuration file](https://playwright.dev/docs/test-configuration). - */ - config: FullConfig; - /** - * Processed project configuration from the [configuration file](https://playwright.dev/docs/test-configuration). - */ - project: FullProject; - /** - * The index of the worker between `0` and `workers - 1`. It is guaranteed that workers running at the same time have - * a different `parallelIndex`. When a worker is restarted, for example after a failure, the new worker process has - * the same `parallelIndex`. - * - * Also available as `process.env.TEST_PARALLEL_INDEX`. Learn more about - * [parallelism and sharding](https://playwright.dev/docs/test-parallel) with Playwright Test. - */ - parallelIndex: number; - - /** - * The unique index of the worker process that is running the test. When a worker is restarted, for example after a - * failure, the new worker process gets a new unique `workerIndex`. - * - * Also available as `process.env.TEST_WORKER_INDEX`. Learn more about [parallelism and sharding](https://playwright.dev/docs/test-parallel) - * with Playwright Test. - */ - workerIndex: number; -} - -/** - * `TestInfo` contains information about currently running test. It is available to test functions, - * [test.beforeEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-before-each), - * [test.afterEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-each), - * [test.beforeAll([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-before-all) and - * [test.afterAll([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-all) hooks, and - * test-scoped fixtures. `TestInfo` provides utilities to control test execution: attach files, update test timeout, - * determine which test is currently running and whether it was retried, etc. - * - * ```js - * import { test, expect } from '@playwright/test'; - * - * test('basic test', async ({ page }, testInfo) => { - * expect(testInfo.title).toBe('basic test'); - * await page.screenshot(testInfo.outputPath('screenshot.png')); - * }); - * ``` - * - */ -export interface TestInfo { - /** - * Processed configuration from the [configuration file](https://playwright.dev/docs/test-configuration). - */ - config: FullConfig; - /** - * Processed project configuration from the [configuration file](https://playwright.dev/docs/test-configuration). - */ - project: FullProject; - /** - * Attach a value or a file from disk to the current test. Some reporters show test attachments. Either `path` or - * `body` must be specified, but not both. - * - * For example, you can attach a screenshot to the test: - * - * ```js - * import { test, expect } from '@playwright/test'; - * - * test('basic test', async ({ page }, testInfo) => { - * await page.goto('https://playwright.dev'); - * const screenshot = await page.screenshot(); - * await testInfo.attach('screenshot', { body: screenshot, contentType: 'image/png' }); - * }); - * ``` - * - * Or you can attach files returned by your APIs: - * - * ```js - * import { test, expect } from '@playwright/test'; - * import { download } from './my-custom-helpers'; - * - * test('basic test', async ({}, testInfo) => { - * const tmpPath = await download('a'); - * await testInfo.attach('downloaded', { path: tmpPath }); - * }); - * ``` - * - * **NOTE** [testInfo.attach(name[, options])](https://playwright.dev/docs/api/class-testinfo#test-info-attach) - * automatically takes care of copying attached files to a location that is accessible to reporters. You can safely - * remove the attachment after awaiting the attach call. - * @param name Attachment name. The name will also be sanitized and used as the prefix of file name when saving to disk. - * @param options - */ - attach(name: string, options?: { - /** - * Attachment body. Mutually exclusive with `path`. - */ - body?: string|Buffer; - - /** - * Content type of this attachment to properly present in the report, for example `'application/json'` or - * `'image/png'`. If omitted, content type is inferred based on the `path`, or defaults to `text/plain` for [string] - * attachments and `application/octet-stream` for [Buffer] attachments. - */ - contentType?: string; - - /** - * Path on the filesystem to the attached file. Mutually exclusive with `body`. - */ - path?: string; - }): Promise; - - /** - * Marks the currently running test as "should fail". Playwright Test runs this test and ensures that it is actually - * failing. This is useful for documentation purposes to acknowledge that some functionality is broken until it is - * fixed. This is similar to - * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail). - */ - fail(): void; - - /** - * Conditionally mark the currently running test as "should fail" with an optional description. This is similar to - * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail). - * @param condition Test is marked as "should fail" when the condition is `true`. - * @param description Optional description that will be reflected in a test report. - */ - fail(condition: boolean, description?: string): void; - - /** - * Mark a test as "fixme", with the intention to fix it. Test is immediately aborted. This is similar to - * [test.fixme([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fixme). - */ - fixme(): void; - - /** - * Conditionally mark the currently running test as "fixme" with an optional description. This is similar to - * [test.fixme([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fixme). - * @param condition Test is marked as "fixme" when the condition is `true`. - * @param description Optional description that will be reflected in a test report. - */ - fixme(condition: boolean, description?: string): void; - - /** - * Returns a path inside the [testInfo.outputDir](https://playwright.dev/docs/api/class-testinfo#test-info-output-dir) - * where the test can safely put a temporary file. Guarantees that tests running in parallel will not interfere with - * each other. - * - * ```js - * import { test, expect } from '@playwright/test'; - * import fs from 'fs'; - * - * test('example test', async ({}, testInfo) => { - * const file = testInfo.outputPath('dir', 'temporary-file.txt'); - * await fs.promises.writeFile(file, 'Put some data to the dir/temporary-file.txt', 'utf8'); - * }); - * ``` - * - * > Note that `pathSegments` accepts path segments to the test output directory such as - * `testInfo.outputPath('relative', 'path', 'to', 'output')`. - * > However, this path must stay within the - * [testInfo.outputDir](https://playwright.dev/docs/api/class-testinfo#test-info-output-dir) directory for each test - * (i.e. `test-results/a-test-title`), otherwise it will throw. - * @param pathSegments Path segments to append at the end of the resulting path. - */ - outputPath(...pathSegments: ReadonlyArray): string; - - /** - * Changes the timeout for the currently running test. Zero means no timeout. Learn more about - * [various timeouts](https://playwright.dev/docs/test-timeouts). - * - * Timeout is usually specified in the [configuration file](https://playwright.dev/docs/test-configuration), but it could be useful to - * change the timeout in certain scenarios: - * - * ```js - * import { test, expect } from '@playwright/test'; - * - * test.beforeEach(async ({ page }, testInfo) => { - * // Extend timeout for all tests running this hook by 30 seconds. - * testInfo.setTimeout(testInfo.timeout + 30000); - * }); - * ``` - * - * @param timeout Timeout in milliseconds. - */ - setTimeout(timeout: number): void; - - /** - * Unconditionally skip the currently running test. Test is immediately aborted. This is similar to - * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip). - */ - skip(): void; - - /** - * Conditionally skips the currently running test with an optional description. This is similar to - * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip). - * @param condition A skip condition. Test is skipped when the condition is `true`. - * @param description Optional description that will be reflected in a test report. - */ - skip(condition: boolean, description?: string): void; - - /** - * Marks the currently running test as "slow", giving it triple the default timeout. This is similar to - * [test.slow([condition, callback, description])](https://playwright.dev/docs/api/class-test#test-slow). - */ - slow(): void; - - /** - * Conditionally mark the currently running test as "slow" with an optional description, giving it triple the default - * timeout. This is similar to - * [test.slow([condition, callback, description])](https://playwright.dev/docs/api/class-test#test-slow). - * @param condition Test is marked as "slow" when the condition is `true`. - * @param description Optional description that will be reflected in a test report. - */ - slow(condition: boolean, description?: string): void; - - /** - * Returns a path to a snapshot file with the given `pathSegments`. Learn more about - * [snapshots](https://playwright.dev/docs/test-snapshots). - * - * > Note that `pathSegments` accepts path segments to the snapshot file such as `testInfo.snapshotPath('relative', - * 'path', 'to', 'snapshot.png')`. - * > However, this path must stay within the snapshots directory for each test file (i.e. `a.spec.js-snapshots`), - * otherwise it will throw. - * @param pathSegments The name of the snapshot or the path segments to define the snapshot file path. Snapshots with the same name in the - * same test file are expected to be the same. - */ - snapshotPath(...pathSegments: ReadonlyArray): string; - - /** - * The list of annotations applicable to the current test. Includes annotations from the test, annotations from all - * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe) groups the - * test belongs to and file-level annotations for the test file. - * - * Learn more about [test annotations](https://playwright.dev/docs/test-annotations). - */ - annotations: Array<{ - /** - * Annotation type, for example `'skip'` or `'fail'`. - */ - type: string; - - /** - * Optional description. - */ - description?: string; - }>; - - /** - * The list of files or buffers attached to the current test. Some reporters show test attachments. - * - * To add an attachment, use - * [testInfo.attach(name[, options])](https://playwright.dev/docs/api/class-testinfo#test-info-attach) instead of - * directly pushing onto this array. - */ - attachments: Array<{ - /** - * Attachment name. - */ - name: string; - - /** - * Content type of this attachment to properly present in the report, for example `'application/json'` or - * `'image/png'`. - */ - contentType: string; - - /** - * Optional path on the filesystem to the attached file. - */ - path?: string; - - /** - * Optional attachment body used instead of a file. - */ - body?: Buffer; - }>; - - /** - * Column number where the currently running test is declared. - */ - column: number; - - /** - * The number of milliseconds the test took to finish. Always zero before the test finishes, either successfully or - * not. Can be used in - * [test.afterEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-each) hook. - */ - duration: number; - - /** - * First error thrown during test execution, if any. This is equal to the first element in - * [testInfo.errors](https://playwright.dev/docs/api/class-testinfo#test-info-errors). - */ - error?: TestInfoError; - - /** - * Errors thrown during test execution, if any. - */ - errors: Array; - - /** - * Expected status for the currently running test. This is usually `'passed'`, except for a few cases: - * - `'skipped'` for skipped tests, e.g. with - * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip); - * - `'failed'` for tests marked as failed with - * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail). - * - * Expected status is usually compared with the actual - * [testInfo.status](https://playwright.dev/docs/api/class-testinfo#test-info-status): - * - * ```js - * import { test, expect } from '@playwright/test'; - * - * test.afterEach(async ({}, testInfo) => { - * if (testInfo.status !== testInfo.expectedStatus) - * console.log(`${testInfo.title} did not run as expected!`); - * }); - * ``` - * - */ - expectedStatus: "passed"|"failed"|"timedOut"|"skipped"|"interrupted"; - - /** - * Absolute path to a file where the currently running test is declared. - */ - file: string; - - /** - * Test function as passed to `test(title, testFunction)`. - */ - fn: Function; - - /** - * Line number where the currently running test is declared. - */ - line: number; - - /** - * Absolute path to the output directory for this specific test run. Each test run gets its own directory so they - * cannot conflict. - */ - outputDir: string; - - /** - * The index of the worker between `0` and `workers - 1`. It is guaranteed that workers running at the same time have - * a different `parallelIndex`. When a worker is restarted, for example after a failure, the new worker process has - * the same `parallelIndex`. - * - * Also available as `process.env.TEST_PARALLEL_INDEX`. Learn more about - * [parallelism and sharding](https://playwright.dev/docs/test-parallel) with Playwright Test. - */ - parallelIndex: number; - - /** - * Specifies a unique repeat index when running in "repeat each" mode. This mode is enabled by passing `--repeat-each` - * to the [command line](https://playwright.dev/docs/test-cli). - */ - repeatEachIndex: number; - - /** - * Specifies the retry number when the test is retried after a failure. The first test run has - * [testInfo.retry](https://playwright.dev/docs/api/class-testinfo#test-info-retry) equal to zero, the first retry has - * it equal to one, and so on. Learn more about [retries](https://playwright.dev/docs/test-retries#retries). - * - * ```js - * import { test, expect } from '@playwright/test'; - * - * test.beforeEach(async ({}, testInfo) => { - * // You can access testInfo.retry in any hook or fixture. - * if (testInfo.retry > 0) - * console.log(`Retrying!`); - * }); - * - * test('my test', async ({ page }, testInfo) => { - * // Here we clear some server-side state when retrying. - * if (testInfo.retry) - * await cleanSomeCachesOnTheServer(); - * // ... - * }); - * ``` - * - */ - retry: number; - - /** - * Absolute path to the snapshot output directory for this specific test. Each test suite gets its own directory so - * they cannot conflict. - * - * This property does not account for the - * [testProject.snapshotPathTemplate](https://playwright.dev/docs/api/class-testproject#test-project-snapshot-path-template) - * configuration. - */ - snapshotDir: string; - - /** - * **NOTE** Use of [testInfo.snapshotSuffix](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-suffix) - * is discouraged. Please use - * [testConfig.snapshotPathTemplate](https://playwright.dev/docs/api/class-testconfig#test-config-snapshot-path-template) - * to configure snapshot paths. - * - * Suffix used to differentiate snapshots between multiple test configurations. For example, if snapshots depend on - * the platform, you can set `testInfo.snapshotSuffix` equal to `process.platform`. In this case - * `expect(value).toMatchSnapshot(snapshotName)` will use different snapshots depending on the platform. Learn more - * about [snapshots](https://playwright.dev/docs/test-snapshots). - */ - snapshotSuffix: string; - - /** - * Actual status for the currently running test. Available after the test has finished in - * [test.afterEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-each) hook and - * fixtures. - * - * Status is usually compared with the - * [testInfo.expectedStatus](https://playwright.dev/docs/api/class-testinfo#test-info-expected-status): - * - * ```js - * import { test, expect } from '@playwright/test'; - * - * test.afterEach(async ({}, testInfo) => { - * if (testInfo.status !== testInfo.expectedStatus) - * console.log(`${testInfo.title} did not run as expected!`); - * }); - * ``` - * - */ - status?: "passed"|"failed"|"timedOut"|"skipped"|"interrupted"; - - /** - * Tags that apply to the test. Learn more about [tags](https://playwright.dev/docs/test-annotations#tag-tests). - * - * Note that any changes made to this list while the test is running will not be visible to test reporters. - */ - tags: Array; - - /** - * Test id matching the test case id in the reporter API. - */ - testId: string; - - /** - * Timeout in milliseconds for the currently running test. Zero means no timeout. Learn more about - * [various timeouts](https://playwright.dev/docs/test-timeouts). - * - * Timeout is usually specified in the [configuration file](https://playwright.dev/docs/test-configuration) - * - * ```js - * import { test, expect } from '@playwright/test'; - * - * test.beforeEach(async ({ page }, testInfo) => { - * // Extend timeout for all tests running this hook by 30 seconds. - * testInfo.setTimeout(testInfo.timeout + 30000); - * }); - * ``` - * - */ - timeout: number; - - /** - * The title of the currently running test as passed to `test(title, testFunction)`. - */ - title: string; - - /** - * The full title path starting with the project. - */ - titlePath: Array; - - /** - * The unique index of the worker process that is running the test. When a worker is restarted, for example after a - * failure, the new worker process gets a new unique `workerIndex`. - * - * Also available as `process.env.TEST_WORKER_INDEX`. Learn more about [parallelism and sharding](https://playwright.dev/docs/test-parallel) - * with Playwright Test. - */ - workerIndex: number; -} - type TestDetailsAnnotation = { type: string; description?: string; @@ -8396,6 +7349,454 @@ interface SnapshotAssertions { }): void; } +/** + * `TestInfo` contains information about currently running test. It is available to test functions, + * [test.beforeEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-before-each), + * [test.afterEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-each), + * [test.beforeAll([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-before-all) and + * [test.afterAll([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-all) hooks, and + * test-scoped fixtures. `TestInfo` provides utilities to control test execution: attach files, update test timeout, + * determine which test is currently running and whether it was retried, etc. + * + * ```js + * import { test, expect } from '@playwright/test'; + * + * test('basic test', async ({ page }, testInfo) => { + * expect(testInfo.title).toBe('basic test'); + * await page.screenshot(testInfo.outputPath('screenshot.png')); + * }); + * ``` + * + */ +export interface TestInfo { + /** + * Attach a value or a file from disk to the current test. Some reporters show test attachments. Either `path` or + * `body` must be specified, but not both. + * + * For example, you can attach a screenshot to the test: + * + * ```js + * import { test, expect } from '@playwright/test'; + * + * test('basic test', async ({ page }, testInfo) => { + * await page.goto('https://playwright.dev'); + * const screenshot = await page.screenshot(); + * await testInfo.attach('screenshot', { body: screenshot, contentType: 'image/png' }); + * }); + * ``` + * + * Or you can attach files returned by your APIs: + * + * ```js + * import { test, expect } from '@playwright/test'; + * import { download } from './my-custom-helpers'; + * + * test('basic test', async ({}, testInfo) => { + * const tmpPath = await download('a'); + * await testInfo.attach('downloaded', { path: tmpPath }); + * }); + * ``` + * + * **NOTE** [testInfo.attach(name[, options])](https://playwright.dev/docs/api/class-testinfo#test-info-attach) + * automatically takes care of copying attached files to a location that is accessible to reporters. You can safely + * remove the attachment after awaiting the attach call. + * @param name Attachment name. The name will also be sanitized and used as the prefix of file name when saving to disk. + * @param options + */ + attach(name: string, options?: { + /** + * Attachment body. Mutually exclusive with `path`. + */ + body?: string|Buffer; + + /** + * Content type of this attachment to properly present in the report, for example `'application/json'` or + * `'image/png'`. If omitted, content type is inferred based on the `path`, or defaults to `text/plain` for [string] + * attachments and `application/octet-stream` for [Buffer] attachments. + */ + contentType?: string; + + /** + * Path on the filesystem to the attached file. Mutually exclusive with `body`. + */ + path?: string; + }): Promise; + + /** + * Marks the currently running test as "should fail". Playwright Test runs this test and ensures that it is actually + * failing. This is useful for documentation purposes to acknowledge that some functionality is broken until it is + * fixed. This is similar to + * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail). + */ + fail(): void; + + /** + * Conditionally mark the currently running test as "should fail" with an optional description. This is similar to + * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail). + * @param condition Test is marked as "should fail" when the condition is `true`. + * @param description Optional description that will be reflected in a test report. + */ + fail(condition: boolean, description?: string): void; + + /** + * Mark a test as "fixme", with the intention to fix it. Test is immediately aborted. This is similar to + * [test.fixme([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fixme). + */ + fixme(): void; + + /** + * Conditionally mark the currently running test as "fixme" with an optional description. This is similar to + * [test.fixme([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fixme). + * @param condition Test is marked as "fixme" when the condition is `true`. + * @param description Optional description that will be reflected in a test report. + */ + fixme(condition: boolean, description?: string): void; + + /** + * Returns a path inside the [testInfo.outputDir](https://playwright.dev/docs/api/class-testinfo#test-info-output-dir) + * where the test can safely put a temporary file. Guarantees that tests running in parallel will not interfere with + * each other. + * + * ```js + * import { test, expect } from '@playwright/test'; + * import fs from 'fs'; + * + * test('example test', async ({}, testInfo) => { + * const file = testInfo.outputPath('dir', 'temporary-file.txt'); + * await fs.promises.writeFile(file, 'Put some data to the dir/temporary-file.txt', 'utf8'); + * }); + * ``` + * + * > Note that `pathSegments` accepts path segments to the test output directory such as + * `testInfo.outputPath('relative', 'path', 'to', 'output')`. + * > However, this path must stay within the + * [testInfo.outputDir](https://playwright.dev/docs/api/class-testinfo#test-info-output-dir) directory for each test + * (i.e. `test-results/a-test-title`), otherwise it will throw. + * @param pathSegments Path segments to append at the end of the resulting path. + */ + outputPath(...pathSegments: ReadonlyArray): string; + + /** + * Changes the timeout for the currently running test. Zero means no timeout. Learn more about + * [various timeouts](https://playwright.dev/docs/test-timeouts). + * + * Timeout is usually specified in the [configuration file](https://playwright.dev/docs/test-configuration), but it could be useful to + * change the timeout in certain scenarios: + * + * ```js + * import { test, expect } from '@playwright/test'; + * + * test.beforeEach(async ({ page }, testInfo) => { + * // Extend timeout for all tests running this hook by 30 seconds. + * testInfo.setTimeout(testInfo.timeout + 30000); + * }); + * ``` + * + * @param timeout Timeout in milliseconds. + */ + setTimeout(timeout: number): void; + + /** + * Unconditionally skip the currently running test. Test is immediately aborted. This is similar to + * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip). + */ + skip(): void; + + /** + * Conditionally skips the currently running test with an optional description. This is similar to + * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip). + * @param condition A skip condition. Test is skipped when the condition is `true`. + * @param description Optional description that will be reflected in a test report. + */ + skip(condition: boolean, description?: string): void; + + /** + * Marks the currently running test as "slow", giving it triple the default timeout. This is similar to + * [test.slow([condition, callback, description])](https://playwright.dev/docs/api/class-test#test-slow). + */ + slow(): void; + + /** + * Conditionally mark the currently running test as "slow" with an optional description, giving it triple the default + * timeout. This is similar to + * [test.slow([condition, callback, description])](https://playwright.dev/docs/api/class-test#test-slow). + * @param condition Test is marked as "slow" when the condition is `true`. + * @param description Optional description that will be reflected in a test report. + */ + slow(condition: boolean, description?: string): void; + + /** + * Returns a path to a snapshot file with the given `pathSegments`. Learn more about + * [snapshots](https://playwright.dev/docs/test-snapshots). + * + * > Note that `pathSegments` accepts path segments to the snapshot file such as `testInfo.snapshotPath('relative', + * 'path', 'to', 'snapshot.png')`. + * > However, this path must stay within the snapshots directory for each test file (i.e. `a.spec.js-snapshots`), + * otherwise it will throw. + * @param pathSegments The name of the snapshot or the path segments to define the snapshot file path. Snapshots with the same name in the + * same test file are expected to be the same. + */ + snapshotPath(...pathSegments: ReadonlyArray): string; + + /** + * The list of annotations applicable to the current test. Includes annotations from the test, annotations from all + * [test.describe([title, details, callback])](https://playwright.dev/docs/api/class-test#test-describe) groups the + * test belongs to and file-level annotations for the test file. + * + * Learn more about [test annotations](https://playwright.dev/docs/test-annotations). + */ + annotations: Array<{ + /** + * Annotation type, for example `'skip'` or `'fail'`. + */ + type: string; + + /** + * Optional description. + */ + description?: string; + }>; + + /** + * The list of files or buffers attached to the current test. Some reporters show test attachments. + * + * To add an attachment, use + * [testInfo.attach(name[, options])](https://playwright.dev/docs/api/class-testinfo#test-info-attach) instead of + * directly pushing onto this array. + */ + attachments: Array<{ + /** + * Attachment name. + */ + name: string; + + /** + * Content type of this attachment to properly present in the report, for example `'application/json'` or + * `'image/png'`. + */ + contentType: string; + + /** + * Optional path on the filesystem to the attached file. + */ + path?: string; + + /** + * Optional attachment body used instead of a file. + */ + body?: Buffer; + }>; + + /** + * Column number where the currently running test is declared. + */ + column: number; + + /** + * Processed configuration from the [configuration file](https://playwright.dev/docs/test-configuration). + */ + config: ConfigInWorker; + + /** + * The number of milliseconds the test took to finish. Always zero before the test finishes, either successfully or + * not. Can be used in + * [test.afterEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-each) hook. + */ + duration: number; + + /** + * First error thrown during test execution, if any. This is equal to the first element in + * [testInfo.errors](https://playwright.dev/docs/api/class-testinfo#test-info-errors). + */ + error?: TestInfoError; + + /** + * Errors thrown during test execution, if any. + */ + errors: Array; + + /** + * Expected status for the currently running test. This is usually `'passed'`, except for a few cases: + * - `'skipped'` for skipped tests, e.g. with + * [test.skip([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-skip); + * - `'failed'` for tests marked as failed with + * [test.fail([title, details, body, condition, callback, description])](https://playwright.dev/docs/api/class-test#test-fail). + * + * Expected status is usually compared with the actual + * [testInfo.status](https://playwright.dev/docs/api/class-testinfo#test-info-status): + * + * ```js + * import { test, expect } from '@playwright/test'; + * + * test.afterEach(async ({}, testInfo) => { + * if (testInfo.status !== testInfo.expectedStatus) + * console.log(`${testInfo.title} did not run as expected!`); + * }); + * ``` + * + */ + expectedStatus: "passed"|"failed"|"timedOut"|"skipped"|"interrupted"; + + /** + * Absolute path to a file where the currently running test is declared. + */ + file: string; + + /** + * Test function as passed to `test(title, testFunction)`. + */ + fn: Function; + + /** + * Line number where the currently running test is declared. + */ + line: number; + + /** + * Absolute path to the output directory for this specific test run. Each test run gets its own directory so they + * cannot conflict. + */ + outputDir: string; + + /** + * The index of the worker between `0` and `workers - 1`. It is guaranteed that workers running at the same time have + * a different `parallelIndex`. When a worker is restarted, for example after a failure, the new worker process has + * the same `parallelIndex`. + * + * Also available as `process.env.TEST_PARALLEL_INDEX`. Learn more about + * [parallelism and sharding](https://playwright.dev/docs/test-parallel) with Playwright Test. + */ + parallelIndex: number; + + /** + * Processed project configuration from the [configuration file](https://playwright.dev/docs/test-configuration). + */ + project: ProjectInWorker; + + /** + * Specifies a unique repeat index when running in "repeat each" mode. This mode is enabled by passing `--repeat-each` + * to the [command line](https://playwright.dev/docs/test-cli). + */ + repeatEachIndex: number; + + /** + * Specifies the retry number when the test is retried after a failure. The first test run has + * [testInfo.retry](https://playwright.dev/docs/api/class-testinfo#test-info-retry) equal to zero, the first retry has + * it equal to one, and so on. Learn more about [retries](https://playwright.dev/docs/test-retries#retries). + * + * ```js + * import { test, expect } from '@playwright/test'; + * + * test.beforeEach(async ({}, testInfo) => { + * // You can access testInfo.retry in any hook or fixture. + * if (testInfo.retry > 0) + * console.log(`Retrying!`); + * }); + * + * test('my test', async ({ page }, testInfo) => { + * // Here we clear some server-side state when retrying. + * if (testInfo.retry) + * await cleanSomeCachesOnTheServer(); + * // ... + * }); + * ``` + * + */ + retry: number; + + /** + * Absolute path to the snapshot output directory for this specific test. Each test suite gets its own directory so + * they cannot conflict. + * + * This property does not account for the + * [testProject.snapshotPathTemplate](https://playwright.dev/docs/api/class-testproject#test-project-snapshot-path-template) + * configuration. + */ + snapshotDir: string; + + /** + * **NOTE** Use of [testInfo.snapshotSuffix](https://playwright.dev/docs/api/class-testinfo#test-info-snapshot-suffix) + * is discouraged. Please use + * [testConfig.snapshotPathTemplate](https://playwright.dev/docs/api/class-testconfig#test-config-snapshot-path-template) + * to configure snapshot paths. + * + * Suffix used to differentiate snapshots between multiple test configurations. For example, if snapshots depend on + * the platform, you can set `testInfo.snapshotSuffix` equal to `process.platform`. In this case + * `expect(value).toMatchSnapshot(snapshotName)` will use different snapshots depending on the platform. Learn more + * about [snapshots](https://playwright.dev/docs/test-snapshots). + */ + snapshotSuffix: string; + + /** + * Actual status for the currently running test. Available after the test has finished in + * [test.afterEach([title, hookFunction])](https://playwright.dev/docs/api/class-test#test-after-each) hook and + * fixtures. + * + * Status is usually compared with the + * [testInfo.expectedStatus](https://playwright.dev/docs/api/class-testinfo#test-info-expected-status): + * + * ```js + * import { test, expect } from '@playwright/test'; + * + * test.afterEach(async ({}, testInfo) => { + * if (testInfo.status !== testInfo.expectedStatus) + * console.log(`${testInfo.title} did not run as expected!`); + * }); + * ``` + * + */ + status?: "passed"|"failed"|"timedOut"|"skipped"|"interrupted"; + + /** + * Tags that apply to the test. Learn more about [tags](https://playwright.dev/docs/test-annotations#tag-tests). + * + * Note that any changes made to this list while the test is running will not be visible to test reporters. + */ + tags: Array; + + /** + * Test id matching the test case id in the reporter API. + */ + testId: string; + + /** + * Timeout in milliseconds for the currently running test. Zero means no timeout. Learn more about + * [various timeouts](https://playwright.dev/docs/test-timeouts). + * + * Timeout is usually specified in the [configuration file](https://playwright.dev/docs/test-configuration) + * + * ```js + * import { test, expect } from '@playwright/test'; + * + * test.beforeEach(async ({ page }, testInfo) => { + * // Extend timeout for all tests running this hook by 30 seconds. + * testInfo.setTimeout(testInfo.timeout + 30000); + * }); + * ``` + * + */ + timeout: number; + + /** + * The title of the currently running test as passed to `test(title, testFunction)`. + */ + title: string; + + /** + * The full title path starting with the project. + */ + titlePath: Array; + + /** + * The unique index of the worker process that is running the test. When a worker is restarted, for example after a + * failure, the new worker process gets a new unique `workerIndex`. + * + * Also available as `process.env.TEST_WORKER_INDEX`. Learn more about [parallelism and sharding](https://playwright.dev/docs/test-parallel) + * with Playwright Test. + */ + workerIndex: number; +} + /** * Information about an error thrown during test execution. */ @@ -8945,6 +8346,41 @@ interface TestProject { timeout?: number; } +/** + * `WorkerInfo` contains information about the worker that is running tests and is available to worker-scoped + * fixtures. `WorkerInfo` is a subset of {@link TestInfo} that is available in many other places. + */ +export interface WorkerInfo { + /** + * Processed configuration from the [configuration file](https://playwright.dev/docs/test-configuration). + */ + config: ConfigInWorker; + + /** + * The index of the worker between `0` and `workers - 1`. It is guaranteed that workers running at the same time have + * a different `parallelIndex`. When a worker is restarted, for example after a failure, the new worker process has + * the same `parallelIndex`. + * + * Also available as `process.env.TEST_PARALLEL_INDEX`. Learn more about + * [parallelism and sharding](https://playwright.dev/docs/test-parallel) with Playwright Test. + */ + parallelIndex: number; + + /** + * Processed project configuration from the [configuration file](https://playwright.dev/docs/test-configuration). + */ + project: ProjectInWorker; + + /** + * The unique index of the worker process that is running the test. When a worker is restarted, for example after a + * failure, the new worker process gets a new unique `workerIndex`. + * + * Also available as `process.env.TEST_WORKER_INDEX`. Learn more about [parallelism and sharding](https://playwright.dev/docs/test-parallel) + * with Playwright Test. + */ + workerIndex: number; +} + interface TestConfigWebServer { /** * Shell command to start. For example `npm run start`.. diff --git a/packages/playwright/types/testReporter.d.ts b/packages/playwright/types/testReporter.d.ts index 605012071c..5ed0d34eca 100644 --- a/packages/playwright/types/testReporter.d.ts +++ b/packages/playwright/types/testReporter.d.ts @@ -15,12 +15,221 @@ * limitations under the License. */ -import type { FullConfig, FullProject, TestStatus, Metadata } from './test'; -export type { FullConfig, TestStatus, FullProject } from './test'; +import type { TestStatus, Metadata, PlaywrightTestOptions, PlaywrightWorkerOptions, ReporterDescription, ConfigInWorker } from './test'; +export type { TestStatus } from './test'; + +type UseOptions = Partial & Partial; + +/** + * Resolved configuration passed to + * [reporter.onBegin(config, suite)](https://playwright.dev/docs/api/class-reporter#reporter-on-begin). + */ +export interface FullConfig { + /** + * List of resolved projects. + */ + projects: FullProject[]; + /** + * See [testConfig.reporter](https://playwright.dev/docs/api/class-testconfig#test-config-reporter). + */ + reporter: ReporterDescription[]; + /** + * See [testConfig.webServer](https://playwright.dev/docs/api/class-testconfig#test-config-web-server). + */ + webServer: ConfigInWorker['webServer']; + /** + * Path to the configuration file (if any) used to run the tests. + */ + configFile?: string; + + /** + * See [testConfig.forbidOnly](https://playwright.dev/docs/api/class-testconfig#test-config-forbid-only). + */ + forbidOnly: boolean; + + /** + * See [testConfig.fullyParallel](https://playwright.dev/docs/api/class-testconfig#test-config-fully-parallel). + */ + fullyParallel: boolean; + + /** + * See [testConfig.globalSetup](https://playwright.dev/docs/api/class-testconfig#test-config-global-setup). + */ + globalSetup: null|string; + + /** + * See [testConfig.globalTeardown](https://playwright.dev/docs/api/class-testconfig#test-config-global-teardown). + */ + globalTeardown: null|string; + + /** + * See [testConfig.globalTimeout](https://playwright.dev/docs/api/class-testconfig#test-config-global-timeout). + */ + globalTimeout: number; + + /** + * See [testConfig.grep](https://playwright.dev/docs/api/class-testconfig#test-config-grep). + */ + grep: RegExp|Array; + + /** + * See [testConfig.grepInvert](https://playwright.dev/docs/api/class-testconfig#test-config-grep-invert). + */ + grepInvert: null|RegExp|Array; + + /** + * See [testConfig.maxFailures](https://playwright.dev/docs/api/class-testconfig#test-config-max-failures). + */ + maxFailures: number; + + /** + * See [testConfig.metadata](https://playwright.dev/docs/api/class-testconfig#test-config-metadata). + */ + metadata: Metadata; + + /** + * See [testConfig.preserveOutput](https://playwright.dev/docs/api/class-testconfig#test-config-preserve-output). + */ + preserveOutput: "always"|"never"|"failures-only"; + + /** + * See [testConfig.quiet](https://playwright.dev/docs/api/class-testconfig#test-config-quiet). + */ + quiet: boolean; + + /** + * See [testConfig.reportSlowTests](https://playwright.dev/docs/api/class-testconfig#test-config-report-slow-tests). + */ + reportSlowTests: null|{ + /** + * The maximum number of slow test files to report. Defaults to `5`. + */ + max: number; + + /** + * Test duration in milliseconds that is considered slow. Defaults to 15 seconds. + */ + threshold: number; + }; + + rootDir: string; + + /** + * See [testConfig.shard](https://playwright.dev/docs/api/class-testconfig#test-config-shard). + */ + shard: null|{ + /** + * The total number of shards. + */ + total: number; + + /** + * The index of the shard to execute, one-based. + */ + current: number; + }; + + /** + * See [testConfig.updateSnapshots](https://playwright.dev/docs/api/class-testconfig#test-config-update-snapshots). + */ + updateSnapshots: "all"|"none"|"missing"; + + /** + * Playwright version. + */ + version: string; + + /** + * See [testConfig.workers](https://playwright.dev/docs/api/class-testconfig#test-config-workers). + */ + workers: number; +} + +/** + * Runtime representation of the test project configuration that is passed to {@link Reporter}. It exposes some of the + * resolved fields declared in {@link TestProject}. You can get {@link FullProject} instance from + * [fullConfig.projects](https://playwright.dev/docs/api/class-fullconfig#full-config-projects) or + * [suite.project()](https://playwright.dev/docs/api/class-suite#suite-project). + */ +export interface FullProject { + /** + * See [testProject.use](https://playwright.dev/docs/api/class-testproject#test-project-use). + */ + use: UseOptions; + /** + * See [testProject.dependencies](https://playwright.dev/docs/api/class-testproject#test-project-dependencies). + */ + dependencies: Array; + + /** + * See [testProject.grep](https://playwright.dev/docs/api/class-testproject#test-project-grep). + */ + grep: RegExp|Array; + + /** + * See [testProject.grepInvert](https://playwright.dev/docs/api/class-testproject#test-project-grep-invert). + */ + grepInvert: null|RegExp|Array; + + /** + * See [testProject.metadata](https://playwright.dev/docs/api/class-testproject#test-project-metadata). + */ + metadata: Metadata; + + /** + * See [testProject.name](https://playwright.dev/docs/api/class-testproject#test-project-name). + */ + name: string; + + /** + * See [testProject.outputDir](https://playwright.dev/docs/api/class-testproject#test-project-output-dir). + */ + outputDir: string; + + /** + * See [testProject.repeatEach](https://playwright.dev/docs/api/class-testproject#test-project-repeat-each). + */ + repeatEach: number; + + /** + * See [testProject.retries](https://playwright.dev/docs/api/class-testproject#test-project-retries). + */ + retries: number; + + /** + * See [testProject.snapshotDir](https://playwright.dev/docs/api/class-testproject#test-project-snapshot-dir). + */ + snapshotDir: string; + + /** + * See [testProject.teardown](https://playwright.dev/docs/api/class-testproject#test-project-teardown). + */ + teardown?: string; + + /** + * See [testProject.testDir](https://playwright.dev/docs/api/class-testproject#test-project-test-dir). + */ + testDir: string; + + /** + * See [testProject.testIgnore](https://playwright.dev/docs/api/class-testproject#test-project-test-ignore). + */ + testIgnore: string|RegExp|Array; + + /** + * See [testProject.testMatch](https://playwright.dev/docs/api/class-testproject#test-project-test-match). + */ + testMatch: string|RegExp|Array; + + /** + * See [testProject.timeout](https://playwright.dev/docs/api/class-testproject#test-project-timeout). + */ + timeout: number; +} /** * `Suite` is a group of tests. All tests in Playwright Test form the following hierarchy: - * - Root suite has a child suite for each {@link TestProject}. + * - Root suite has a child suite for each {@link FullProject}. * - Project suite #1. Has a child suite for each test file in the project. * - File suite #1 * - {@link TestCase} #1 @@ -45,10 +254,6 @@ export interface Suite { * -> ...`describe` -> `test`. */ type: 'root' | 'project' | 'file' | 'describe'; - /** - * Configuration of the project this suite belongs to, or [void] for the root suite. - */ - project(): FullProject | undefined; /** * Returns the list of all test cases in this suite and its descendants, as opposite to * [suite.tests](https://playwright.dev/docs/api/class-suite#suite-tests). @@ -63,6 +268,11 @@ export interface Suite { */ entries(): Array; + /** + * Configuration of the project this suite belongs to, or [void] for the root suite. + */ + project(): FullProject|undefined; + /** * Returns a list of titles from the root down to this suite. */ @@ -454,13 +664,6 @@ export interface FullResult { * [reporter.onBegin(config, suite)](https://playwright.dev/docs/api/class-reporter#reporter-on-begin). */ export interface Reporter { - /** - * Called once before running tests. All tests have been already discovered and put into a hierarchy of {@link - * Suite}s. - * @param config Resolved configuration. - * @param suite The root suite that contains all projects, files and test cases. - */ - onBegin?(config: FullConfig, suite: Suite): void; /** * Called after all tests have been run, or testing has been interrupted. Note that this method may return a [Promise] * and Playwright Test will await it. Reporter is allowed to override the status and hence affect the exit code of the @@ -474,6 +677,14 @@ export interface Reporter { * - `'interrupted'` - Interrupted by the user. */ onEnd?(result: FullResult): Promise<{ status?: FullResult['status'] } | undefined | void> | void; + /** + * Called once before running tests. All tests have been already discovered and put into a hierarchy of {@link + * Suite}s. + * @param config Resolved configuration. + * @param suite The root suite that contains all projects, files and test cases. + */ + onBegin?(config: FullConfig, suite: Suite): void; + /** * Called on some global error, for example unhandled exception in the worker process. * @param error The error. diff --git a/tests/playwright-test/global-setup.spec.ts b/tests/playwright-test/global-setup.spec.ts index 3d28be82cd..bcb9013387 100644 --- a/tests/playwright-test/global-setup.spec.ts +++ b/tests/playwright-test/global-setup.spec.ts @@ -280,8 +280,8 @@ const authFiles = { export default config; `, 'auth.ts': ` - import { chromium, FullConfig } from '@playwright/test'; - async function globalSetup(config: FullConfig) { + import { chromium, ConfigInWorker } from '@playwright/test'; + async function globalSetup(config: ConfigInWorker) { const { baseURL, storageState } = config.projects[0].use; const browser = await chromium.launch(); const page = await browser.newPage(); diff --git a/utils/doclint/generateFullConfigDoc.js b/utils/doclint/generateFullConfigDoc.js new file mode 100644 index 0000000000..8c00f7f8a2 --- /dev/null +++ b/utils/doclint/generateFullConfigDoc.js @@ -0,0 +1,121 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// @ts-check + +const path = require('path'); +const fs = require('fs'); +const PROJECT_DIR = path.join(__dirname, '..', '..'); + +function generateFullConfigClass(fromClassName, toClassName, allowList) { + const allowedNames = new Set(allowList); + + const content = fs.readFileSync(path.join(PROJECT_DIR, `docs/src/test-api/class-${fromClassName.toLowerCase()}.md`)).toString(); + let sections = content.split('\n## '); + sections = filterAllowedSections(sections, allowedNames); + if (allowedNames.size) + console.log(`Undocumented properties for ${fromClassName}:\n ${[...allowedNames].join('\n ')}`); + sections = changeClassName(sections, fromClassName, toClassName); + sections = replacePropertyDescriptions(sections, fromClassName); + const fullconfig = sections.join('\n## '); + fs.writeFileSync(path.join(PROJECT_DIR, `docs/src/test-api/class-${toClassName.toLowerCase()}.md`), fullconfig); +} + +function propertyNameFromSection(section) { + section = section.split('\n')[0]; + const match = /\.(\w+)/.exec(section); + if (!match) + return null; + return match[1]; +} + +function filterAllowedSections(sections, allowedNames) { + return sections.filter(section => { + section = section.split('\n')[0]; + const name = propertyNameFromSection(section); + if (!name) + return true; + return allowedNames.delete(name); + }); +} + +function changeClassName(sections, from, to) { + return sections.map(section => { + const lines = section.split('\n'); + lines[0] = lines[0].replace(from, to); + return lines.join('\n'); + }); +} + +function replacePropertyDescriptions(sections, configClassName) { + return sections.map(section => { + const parts = section.split('\n\n'); + section = parts[0]; + const name = propertyNameFromSection(section); + if (!name) + return `${section}\n`; + return `${section}\n\nSee [\`property: ${configClassName}.${name}\`].\n`; + }); +} + +function generateFullConfig() { + generateFullConfigClass('TestConfig', 'FullConfig', [ + 'forbidOnly', + 'fullyParallel', + 'globalSetup', + 'globalTeardown', + 'globalTimeout', + 'grep', + 'grepInvert', + 'maxFailures', + 'metadata', + 'version', + 'preserveOutput', + 'projects', + 'reporter', + 'reportSlowTests', + 'rootDir', + 'quiet', + 'shard', + 'updateSnapshots', + 'workers', + 'webServer', + 'configFile', + ]); +} + +function generateFullProject() { + generateFullConfigClass('TestProject', 'FullProject', [ + 'grep', + 'grepInvert', + 'metadata', + 'name', + 'dependencies', + 'snapshotDir', + 'outputDir', + 'repeatEach', + 'retries', + 'teardown', + 'testDir', + 'testIgnore', + 'testMatch', + 'timeout', + 'use', + ]); +} + +generateFullConfig(); +generateFullProject(); diff --git a/utils/generate_types/index.js b/utils/generate_types/index.js index e16f6df772..06863d9c9f 100644 --- a/utils/generate_types/index.js +++ b/utils/generate_types/index.js @@ -553,9 +553,7 @@ class TypesGenerator { overridesToDocsClassMapping: new Map([ ['TestType', 'Test'], ['Config', 'TestConfig'], - ['FullConfig', 'TestConfig'], ['Project', 'TestProject'], - ['FullProject', 'TestProject'], ['PlaywrightWorkerOptions', 'TestOptions'], ['PlaywrightTestOptions', 'TestOptions'], ['PlaywrightWorkerArgs', 'Fixtures'], @@ -563,9 +561,6 @@ class TypesGenerator { ['AsymmetricMatchers', 'GenericAssertions'], ]), ignoreMissing: new Set([ - 'FullConfig.configFile', - 'FullConfig.version', - 'FullConfig.rootDir', 'SuiteFunction', 'TestFunction', 'PlaywrightWorkerOptions.defaultBrowserType', diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.ts index 9ace4f70cc..a10938a49a 100644 --- a/utils/generate_types/overrides-test.d.ts +++ b/utils/generate_types/overrides-test.d.ts @@ -29,33 +29,15 @@ export type ReporterDescription = ['null'] | [string] | [string, any]; -type UseOptions = { [K in keyof WorkerArgs]?: WorkerArgs[K] } & { [K in keyof TestArgs]?: TestArgs[K] }; +type UseOptions = Partial & Partial; export interface Project extends TestProject { use?: UseOptions; } -// [internal] !!! DO NOT ADD TO THIS !!! -// [internal] It is part of the public API and is computed from the user's config. -// [internal] If you need new fields internally, add them to FullProjectInternal instead. -export interface FullProject { - grep: RegExp | RegExp[]; - grepInvert: RegExp | RegExp[] | null; - metadata: Metadata; - name: string; - dependencies: string[]; - snapshotDir: string; - outputDir: string; - repeatEach: number; - retries: number; - teardown?: string; - testDir: string; - testIgnore: string | RegExp | (string | RegExp)[]; - testMatch: string | RegExp | (string | RegExp)[]; - timeout: number; +export interface ProjectInWorker { use: UseOptions; } -// [internal] !!! DO NOT ADD TO THIS !!! See prior note. type LiteralUnion = T | (U & { zz_IGNORE_ME?: never }); @@ -71,46 +53,14 @@ export interface Config extends TestConfig { export type Metadata = { [key: string]: any }; -// [internal] !!! DO NOT ADD TO THIS !!! -// [internal] It is part of the public API and is computed from the user's config. -// [internal] If you need new fields internally, add them to FullConfigInternal instead. -export interface FullConfig { - forbidOnly: boolean; - fullyParallel: boolean; - globalSetup: string | null; - globalTeardown: string | null; - globalTimeout: number; - grep: RegExp | RegExp[]; - grepInvert: RegExp | RegExp[] | null; - maxFailures: number; - metadata: Metadata; - version: string; - preserveOutput: 'always' | 'never' | 'failures-only'; - projects: FullProject[]; +export interface ConfigInWorker { + projects: ProjectInWorker[]; reporter: ReporterDescription[]; - reportSlowTests: { max: number, threshold: number } | null; - rootDir: string; - quiet: boolean; - shard: { total: number, current: number } | null; - updateSnapshots: 'all' | 'none' | 'missing'; - workers: number; webServer: TestConfigWebServer | null; - configFile?: string; - // [internal] !!! DO NOT ADD TO THIS !!! See prior note. } export type TestStatus = 'passed' | 'failed' | 'timedOut' | 'skipped' | 'interrupted'; -export interface WorkerInfo { - config: FullConfig; - project: FullProject; -} - -export interface TestInfo { - config: FullConfig; - project: FullProject; -} - type TestDetailsAnnotation = { type: string; description?: string; diff --git a/utils/generate_types/overrides-testReporter.d.ts b/utils/generate_types/overrides-testReporter.d.ts index 8faa956928..129faf30fc 100644 --- a/utils/generate_types/overrides-testReporter.d.ts +++ b/utils/generate_types/overrides-testReporter.d.ts @@ -14,12 +14,23 @@ * limitations under the License. */ -import type { FullConfig, FullProject, TestStatus, Metadata } from './test'; -export type { FullConfig, TestStatus, FullProject } from './test'; +import type { TestStatus, Metadata, PlaywrightTestOptions, PlaywrightWorkerOptions, ReporterDescription, ConfigInWorker } from './test'; +export type { TestStatus } from './test'; + +type UseOptions = Partial & Partial; + +export interface FullConfig { + projects: FullProject[]; + reporter: ReporterDescription[]; + webServer: ConfigInWorker['webServer']; +} + +export interface FullProject { + use: UseOptions; +} export interface Suite { type: 'root' | 'project' | 'file' | 'describe'; - project(): FullProject | undefined; } export interface TestCase { @@ -56,7 +67,6 @@ export interface FullResult { } export interface Reporter { - onBegin?(config: FullConfig, suite: Suite): void; onEnd?(result: FullResult): Promise<{ status?: FullResult['status'] } | undefined | void> | void; }