From 11dfd31dd9c44ebe888e0929a1800c70507b227b Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 29 Aug 2022 15:46:34 -0700 Subject: [PATCH] feat: --pass-with-no-tests option (#16902) --- packages/playwright-test/src/cli.ts | 2 ++ packages/playwright-test/src/runner.ts | 3 ++- tests/playwright-test/exit-code.spec.ts | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/playwright-test/src/cli.ts b/packages/playwright-test/src/cli.ts index 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 ', `Stop after the first N failures`); command.option('--output ', `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 ', `Run each test N times (default: 1)`); command.option('--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.ts index 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.ts index 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);