From 75f39c2d96e8f44f39b679fff87aab19cf5d11f5 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Fri, 16 Aug 2024 16:42:26 +0200 Subject: [PATCH] fix(only-changed): exit successfully if there were no changes --- packages/playwright/src/program.ts | 2 +- tests/playwright-test/only-changed.spec.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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