fix(only-changed): exit successfully if there were no changes (#32197)

Closes https://github.com/microsoft/playwright/issues/32180

I was briefly wondering if we should output a log line a la "no tests
found", but my understanding is that that's the reporters job - so I
didn't change anything in that regard.
This commit is contained in:
Simon Knott 2024-08-22 14:53:00 +02:00 committed by GitHub
parent 7758b330b1
commit 5368fd7ca7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View File

@ -239,7 +239,7 @@ function createLoadTask(mode: 'out-of-process' | 'in-process', options: { filter
testRun.rootSuite = await createRootSuite(testRun, options.failOnLoadErrors ? errors : softErrors, !!options.filterOnly, cliOnlyChangedMatcher);
testRun.failureTracker.onRootSuite(testRun.rootSuite);
// Fail when no tests.
if (options.failOnLoadErrors && !testRun.rootSuite.allTests().length && !testRun.config.cliPassWithNoTests && !testRun.config.config.shard) {
if (options.failOnLoadErrors && !testRun.rootSuite.allTests().length && !testRun.config.cliPassWithNoTests && !testRun.config.config.shard && !testRun.config.cliOnlyChanged) {
if (testRun.config.cliArgs.length) {
throw new Error([
`No tests found.`,

View File

@ -256,10 +256,9 @@ test('should suppport component tests', async ({ runInlineTest, git, writeFiles
const result = await runInlineTest({}, { 'workers': 1, 'only-changed': true });
expect(result.exitCode).toBe(1);
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(0);
expect(result.failed).toBe(0);
expect(result.output).toContain('No tests found');
const result2 = await runInlineTest({
'src/button2.test.tsx': `
@ -437,3 +436,20 @@ test('should work with list mode', async ({ runInlineTest, git, writeFiles }) =>
expect(result.output).toContain('b.spec.ts');
expect(result.output).not.toContain('a.spec.ts');
});
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);
});