From a5d7ca17ae6b55d5f76e40c8b4a374d8689c9702 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Thu, 18 Jul 2024 10:10:29 +0200 Subject: [PATCH] remove CI smartypants --- packages/playwright/src/program.ts | 17 +--------- tests/playwright-test/only-changed.spec.ts | 39 ---------------------- 2 files changed, 1 insertion(+), 55 deletions(-) diff --git a/packages/playwright/src/program.ts b/packages/playwright/src/program.ts index 98de1401e0..fde44aae91 100644 --- a/packages/playwright/src/program.ts +++ b/packages/playwright/src/program.ts @@ -153,21 +153,6 @@ Examples: $ npx playwright merge-reports playwright-report`); } -function getOnlyChangedArg(input: string | boolean | undefined): string | undefined { - if (typeof input === 'string') - return input; - if (input === true) { - if (process.env.CI) { - const baseRef = process.env.GITHUB_BASE_REF ?? process.env.BITBUCKET_BRANCH ?? process.env['Build.PullRequest.TargetBranch']; - if (!baseRef) - throw new Error('You specified --only-changed in a CI environment, but the base reference can not be inferred. Please specify it explicitly, e.g. by setting --only-changed=main'); - return baseRef; - } - return 'HEAD'; - } -} - - async function runTests(args: string[], opts: { [key: string]: any }) { await startProfiling(); const cliOverrides = overridesFromOptions(opts); @@ -179,7 +164,7 @@ async function runTests(args: string[], opts: { [key: string]: any }) { args, grep: opts.grep as string | undefined, grepInvert: opts.grepInvert as string | undefined, - onlyChanged: getOnlyChangedArg(opts.onlyChanged), + onlyChanged: opts.onlyChanged === true ? 'HEAD' : opts.onlyChanged, project: opts.project || undefined, headed: opts.headed, reporter: Array.isArray(opts.reporter) ? opts.reporter : opts.reporter ? [opts.reporter] : undefined, diff --git a/tests/playwright-test/only-changed.spec.ts b/tests/playwright-test/only-changed.spec.ts index 283756294c..4d1e71749b 100644 --- a/tests/playwright-test/only-changed.spec.ts +++ b/tests/playwright-test/only-changed.spec.ts @@ -102,45 +102,6 @@ test('should diff based on base commit', async ({ runInlineTest, setupRepository expect(result.output).toContain('b.spec.ts'); }); -test.describe('should be smart about PR base reference from CI', () => { - function testCIEnvironment(name: string, envVar: string) { - test(name, async ({ runInlineTest, setupRepository, writeFiles }) => { - const git = await setupRepository(); - await writeFiles({ - 'b.spec.ts': ` - import { test, expect } from '@playwright/test'; - test('fails', () => { expect(1).toBe(3); }); - `, - }); - git('commit -a -m update'); - const result = await runInlineTest({}, { 'only-changed': true }, { CI: 'true', [envVar]: 'HEAD~1' }); - - expect(result.exitCode).toBe(1); - expect(result.failed).toBe(1); - expect(result.output).toContain('b.spec.ts'); - }); - } - - testCIEnvironment('Github Actions', 'GITHUB_BASE_REF'); - testCIEnvironment('Bitbucket', 'BITBUCKET_BRANCH'); - testCIEnvironment('Azure DevOps', 'Build.PullRequest.TargetBranch'); - - test("throws error if ref isn't available", async ({ runInlineTest, setupRepository, writeFiles }) => { - const git = await setupRepository(); - await writeFiles({ - 'b.spec.ts': ` - import { test, expect } from '@playwright/test'; - test('fails', () => { expect(1).toBe(3); }); - `, - }); - git('commit -a -m update'); - const result = await runInlineTest({}, { 'only-changed': true }, { CI: 'true' }); - - expect(result.exitCode).toBe(1); - expect(result.output).toContain('You specified --only-changed in a CI environment, but the base reference can not be inferred.'); - }); -}); - test('should understand dependency structure', async ({ runInlineTest, setupRepository, writeFiles }) => { await setupRepository(); await writeFiles({