Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: unship --filter cli option (#37030)
Dmitry Gozman75db8e5ef7d8
diff --git a/docs/src/test-cli-js.md b/docs/src/test-cli-js.mdindex 0082a3f9c3..0688e328d7 100644--- a/docs/src/test-cli-js.md+++ b/docs/src/test-cli-js.md@@ -82,7 +82,6 @@ npx playwright test --ui| `-c <file>` or `--config <file>` | Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}". Defaults to `playwright.config.ts` or `playwright.config.js` in the current directory. || `--debug` | Run tests with Playwright Inspector. Shortcut for `PWDEBUG=1` environment variable and `--timeout=0 --max-failures=1 --headed --workers=1` options. || `--fail-on-flaky-tests` | Fail if any test is flagged as flaky (default: false). |-| `--filter` | Path to a [test filter file](#test-filter-file). || `--forbid-only` | Fail if `test.only` is called (default: false). Useful on CI. || `--fully-parallel` | Run all tests in parallel (default: false). || `--global-timeout <timeout>` | Maximum time this test suite can run in milliseconds (default: unlimited). |@@ -114,18 +113,6 @@ npx playwright test --ui| `--update-source-method [mode]` | Update snapshots with actual results. Possible values are "patch" (default), "3way" and "overwrite". "Patch" creates a unified diff file that can be used to update the source code later. "3way" generates merge conflict markers in source code. "Overwrite" overwrites the source code with the new snapshot values.|| `-x` | Stop after the first failure. |-#### Test filter file--Option `--filter` allows to specify a json file to filter tests. It must contain an array property `titlePath`. For each test that should be run, `titlePath` contains a project name, relative path to the test file, all suite titles and the test title, similar to [`method: TestCase.titlePath`].--```json title="filter.json"-{- "titlePath": [- ["chromium", "path/to/example.spec.ts", "describe title", "test title"],- ["firefox", "path/to/another.spec.ts", "top-level test title"]- ]-}-```### Show Reportdiff --git a/packages/playwright/src/common/config.ts b/packages/playwright/src/common/config.tsindex 5876889ffb..660aa77add 100644--- a/packages/playwright/src/common/config.ts+++ b/packages/playwright/src/common/config.ts@@ -57,7 +57,6 @@ export class FullConfigInternal {cliListOnly = false;cliPassWithNoTests?: boolean;cliLastFailed?: boolean;- cliFilterFile?: string;preOnlyTestFilters: TestCaseFilter[] = [];postShardTestFilters: TestCaseFilter[] = [];defineConfigWasUsed = false;diff --git a/packages/playwright/src/program.ts b/packages/playwright/src/program.tsindex bc402b10f8..c2f5f4540c 100644--- a/packages/playwright/src/program.ts+++ b/packages/playwright/src/program.ts@@ -176,7 +176,6 @@ async function runTests(args: string[], opts: { [key: string]: any }) {config.cliProjectFilter = opts.project || undefined;config.cliPassWithNoTests = !!opts.passWithNoTests;config.cliLastFailed = !!opts.lastFailed;- config.cliFilterFile = opts.filter ? path.resolve(process.cwd(), opts.filter) : undefined;// Evaluate project filters against config before starting execution. This enables a consistent error message across run modesfilterProjects(config.projects, config.cliProjectFilter);@@ -381,7 +380,6 @@ const testOptions: [string, { description: string, choices?: string[], preset?:['-c, --config <file>', { description: `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"` }],['--debug', { description: `Run tests with Playwright Inspector. Shortcut for "PWDEBUG=1" environment variable and "--timeout=0 --max-failures=1 --headed --workers=1" options` }],['--fail-on-flaky-tests', { description: `Fail if any test is flagged as flaky (default: false)` }],- ['--filter <file>', { description: `Path to a test filter file. See documentation for details.` }],['--forbid-only', { description: `Fail if test.only is called (default: false)` }],['--fully-parallel', { description: `Run all tests in parallel (default: false)` }],['--global-timeout <timeout>', { description: `Maximum time this test suite can run in milliseconds (default: unlimited)` }],diff --git a/packages/playwright/src/runner/tasks.ts b/packages/playwright/src/runner/tasks.tsindex c7113c204b..ea4123be24 100644--- a/packages/playwright/src/runner/tasks.ts+++ b/packages/playwright/src/runner/tasks.ts@@ -31,7 +31,7 @@ import { detectChangedTestFiles } from './vcs';import { Suite } from '../common/test';import { createTestGroups } from '../runner/testGroups';import { cacheDir } from '../transform/compilationCache';-import { loadTestFilterFile, removeDirAndLogToConsole } from '../util';+import { removeDirAndLogToConsole } from '../util';import type { TestGroup } from '../runner/testGroups';import type { EnvByProjectId } from './dispatcher';@@ -269,16 +269,6 @@ export function createLoadTask(mode: 'out-of-process' | 'in-process', options: {testRun.config.preOnlyTestFilters.push(test => changedFiles.has(test.location.file));}- if (testRun.config.cliFilterFile) {- try {- testRun.config.preOnlyTestFilters.push(await loadTestFilterFile(testRun.config.cliFilterFile));- } catch (error) {- if (options.failOnLoadErrors)- throw error;- softErrors.push(error);- }- }-testRun.rootSuite = await createRootSuite(testRun, options.failOnLoadErrors ? errors : softErrors, !!options.filterOnly);testRun.failureTracker.onRootSuite(testRun.rootSuite);// Fail when no tests.diff --git a/packages/playwright/src/util.ts b/packages/playwright/src/util.tsindex 19116a9ae9..71aab10048 100644--- a/packages/playwright/src/util.ts+++ b/packages/playwright/src/util.ts@@ -19,7 +19,7 @@ import path from 'path';import url from 'url';import util from 'util';-import { rewriteErrorMessage, toPosixPath, parseStackFrame, sanitizeForFilePath, calculateSha1, isRegExp, isString, stringifyStackFrames } from 'playwright-core/lib/utils';+import { parseStackFrame, sanitizeForFilePath, calculateSha1, isRegExp, isString, stringifyStackFrames } from 'playwright-core/lib/utils';import { colors, debug, mime, minimatch } from 'playwright-core/lib/utilsBundle';import type { Location } from './../types/testReporter';@@ -422,24 +422,3 @@ export const ansiRegex = new RegExp('([\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zAexport function stripAnsiEscapes(str: string): string {return str.replace(ansiRegex, '');}--type TestFileFilterData = {- titlePath: string[][],-};--export async function loadTestFilterFile(filePath: string): Promise<TestCaseFilter> {- try {- const data = JSON.parse(await fs.promises.readFile(filePath, 'utf8')) as TestFileFilterData;- if (!data || typeof data !== 'object' || !Array.isArray(data.titlePath) || !data.titlePath.every(path => Array.isArray(path)))- throw new Error(`Wrong test filter file format`);- const toId = (titlePath: string[]) => {- const [project, file, ...titles] = titlePath; // At the time of filtering, there is no root yet.- return `${project}\x1e${toPosixPath(file)}\x1e${titles.join('\x1e')}`;- };- const ids = new Set(data.titlePath.map(titlePath => toId(titlePath)));- return test => ids.has(toId(test.titlePath()));- } catch (error) {- rewriteErrorMessage(error, `Failed to read test filter file "${filePath}": ${error.message}`);- throw error;- }-}diff --git a/tests/playwright-test/test-filter.spec.ts b/tests/playwright-test/test-filter.spec.tsdeleted file mode 100644index acb792aebf..0000000000--- a/tests/playwright-test/test-filter.spec.ts+++ /dev/null@@ -1,95 +0,0 @@-/**- * Copyright Microsoft Corporation. All rights reserved.- *- * 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.- */--import { test, expect } from './playwright-test-fixtures';--test('--filter should work', async ({ runInlineTest }) => {- const result = await runInlineTest({- 'playwright.config.ts': `- module.exports = { projects: [{}, { name: 'p1' }, { name: 'p2' }] };- `,- 'filter.json': `- {- "titlePath": [- ["p2", "b.test.ts", "test2"],- ["p1", "a.test.ts", "suite2", "test2"],- ["p1", "b.test.ts", "suite2", "test1"],- ["", "a.test.ts", "suite1", "test1"]- ]- }- `,- 'a.test.ts': `- import { test, expect } from '@playwright/test';- test.describe('suite1', () => {- test('test1', async () => { console.log('\\n%%a-' + test.info().project.name + '-suite1-test1'); });- test('test2', async () => { console.log('\\n%%a-' + test.info().project.name + '-suite1-test2'); });- });- test.describe('suite2', () => {- test('test1', async () => { console.log('\\n%%a-' + test.info().project.name + '-suite2-test1'); });- test('test2', async () => { console.log('\\n%%a-' + test.info().project.name + '-suite2-test2'); });- });- test('test1', async () => { console.log('\\n%%a-' + test.info().project.name + '-test1'); });- test('test2', async () => { console.log('\\n%%a-' + test.info().project.name + '-test2'); });- `,- 'b.test.ts': `- import { test, expect } from '@playwright/test';- test.describe('suite1', () => {- test('test1', async () => { console.log('\\n%%b-' + test.info().project.name + '-suite1-test1'); });- test('test2', async () => { console.log('\\n%%b-' + test.info().project.name + '-suite1-test2'); });- });- test.describe('suite2', () => {- test('test1', async () => { console.log('\\n%%b-' + test.info().project.name + '-suite2-test1'); });- test('test2', async () => { console.log('\\n%%b-' + test.info().project.name + '-suite2-test2'); });- });- test('test1', async () => { console.log('\\n%%b-' + test.info().project.name + '-test1'); });- test('test2', async () => { console.log('\\n%%b-' + test.info().project.name + '-test2'); });- `,- }, { workers: 1, filter: 'filter.json' });- expect(result.exitCode).toBe(0);- expect(result.passed).toBe(4);- expect(result.failed).toBe(0);- expect(result.outputLines).toEqual([- 'a--suite1-test1',- 'a-p1-suite2-test2',- 'b-p1-suite2-test1',- 'b-p2-test2',- ]);-});--test('--filter should complain about missing file', async ({ runInlineTest }) => {- const result = await runInlineTest({- 'a.test.ts': `- import { test, expect } from '@playwright/test';- test('test1', () => {});- `,- }, { workers: 1, filter: 'filter.json' });- expect(result.exitCode).toBe(1);- expect(result.output).toContain(`Failed to read test filter file "${test.info().outputPath('filter.json')}"`);-});--test('--filter should complain about malformed file', async ({ runInlineTest }) => {- const result = await runInlineTest({- 'filter.json': `- { "titlePath": [[], "not an array"] }- `,- 'a.test.ts': `- import { test, expect } from '@playwright/test';- test('test1', () => {});- `,- }, { workers: 1, filter: 'filter.json' });- expect(result.exitCode).toBe(1);- expect(result.output).toContain(`Failed to read test filter file "${test.info().outputPath('filter.json')}": Wrong test filter file format`);-});