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
feat: --pass-with-no-tests option (#16902)
Yury Semikhatsky11dfd31dd9c4
diff --git a/packages/playwright-test/src/cli.ts b/packages/playwright-test/src/cli.tsindex bb3f665cbb..1ae5cf5542 100644--- a/packages/playwright-test/src/cli.ts+++ b/packages/playwright-test/src/cli.ts@@ -50,6 +50,7 @@ function addTestCommand(program: Command) {command.option('--list', `Collect all the tests and report them, but do not run`);command.option('--max-failures <N>', `Stop after the first N failures`);command.option('--output <dir>', `Folder for output artifacts (default: "test-results")`);+ command.option('--pass-with-no-tests', `Makes test run succeed even if no tests were found`);command.option('--quiet', `Suppress stdio`);command.option('--repeat-each <N>', `Run each test N times (default: 1)`);command.option('--reporter <reporter>', `Reporter to use, comma-separated, can be ${builtInReporters.map(name => `"${name}"`).join(', ')} (default: "${baseFullConfig.reporter[0]}")`);@@ -165,6 +166,7 @@ async function runTests(args: string[], opts: { [key: string]: any }) {testFileFilters,projectFilter: opts.project || undefined,watchMode: !!process.env.PW_TEST_WATCH,+ passWithNoTests: opts.passWithNoTests,});await stopProfiling(undefined);diff --git a/packages/playwright-test/src/runner.ts b/packages/playwright-test/src/runner.tsindex fbb8aab982..9287a068fa 100644--- a/packages/playwright-test/src/runner.ts+++ b/packages/playwright-test/src/runner.ts@@ -56,6 +56,7 @@ type RunOptions = {testFileFilters?: TestFileFilter[];projectFilter?: string[];watchMode?: boolean;+ passWithNoTests?: boolean;};export type ConfigCLIOverrides = {@@ -337,7 +338,7 @@ export class Runner {// 7. Fail when no tests.let total = rootSuite.allTests().length;- if (!total)+ if (!total && !options.passWithNoTests)fatalErrors.push(createNoTestsError());// 8. Compute shards.diff --git a/tests/playwright-test/exit-code.spec.ts b/tests/playwright-test/exit-code.spec.tsindex eac2c8a963..9126ba9af6 100644--- a/tests/playwright-test/exit-code.spec.ts+++ b/tests/playwright-test/exit-code.spec.ts@@ -156,6 +156,16 @@ test('should exit with code 1 if passed a file name', async ({ runInlineTest })expect(result.output).toContain(`no tests found.`);});+test('should exit with code 0 with --pass-with-no-tests', async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'playwright.config.ts': `+ module.exports = { testDir: 'unknown' };+ `,+ }, undefined, undefined, { additionalArgs: ['--pass-with-no-tests'] });+ expect(result.exitCode).toBe(0);+ expect(result.output).toContain(`Running 0 tests using 0 workers`);+});+test('should exit with code 1 when config is not found', async ({ runInlineTest }) => {const result = await runInlineTest({ 'my.config.js': '' }, { 'config': 'foo.config.js' });expect(result.exitCode).toBe(1);