diff --git a/packages/playwright/src/program.ts b/packages/playwright/src/program.ts index 803b9d2291..b68fb86068 100644 --- a/packages/playwright/src/program.ts +++ b/packages/playwright/src/program.ts @@ -198,7 +198,7 @@ async function runTests(args: string[], opts: { [key: string]: any }) { config.cliGrepInvert = opts.grepInvert as string | undefined; config.cliListOnly = !!opts.list; config.cliProjectFilter = opts.project || undefined; - config.cliPassWithNoTests = !!opts.passWithNoTests; + config.cliPassWithNoTests = !!(opts.passWithNoTests ?? opts.onlyChanged); config.cliFailOnFlakyTests = !!opts.failOnFlakyTests; const runner = new Runner(config); diff --git a/tests/playwright-test/only-changed.spec.ts b/tests/playwright-test/only-changed.spec.ts index 355bcf977d..72ddf1ef93 100644 --- a/tests/playwright-test/only-changed.spec.ts +++ b/tests/playwright-test/only-changed.spec.ts @@ -413,4 +413,20 @@ test('should run project dependencies of changed tests', { expect(result.passed).toBe(1); expect(result.output).toContain('setup test is executed'); +}); + +test('exits successfully if there are no changes', async ({ runInlineTest, git, writeFiles }) => { + await writeFiles({ + 'a.spec.ts': ` + import { test, expect } from '@playwright/test'; + test('fails', () => { expect(1).toBe(2); }); + `, + }); + + git(`add .`); + git(`commit -m init`); + + const result = await runInlineTest({}, { 'only-changed': true }); + + expect(result.exitCode).toBe(0); }); \ No newline at end of file