remove CI smartypants

This commit is contained in:
Simon Knott 2024-07-18 10:10:29 +02:00
parent 6baf0b6009
commit a5d7ca17ae
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 1 additions and 55 deletions

View file

@ -153,21 +153,6 @@ Examples:
$ npx playwright merge-reports playwright-report`); $ 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 }) { async function runTests(args: string[], opts: { [key: string]: any }) {
await startProfiling(); await startProfiling();
const cliOverrides = overridesFromOptions(opts); const cliOverrides = overridesFromOptions(opts);
@ -179,7 +164,7 @@ async function runTests(args: string[], opts: { [key: string]: any }) {
args, args,
grep: opts.grep as string | undefined, grep: opts.grep as string | undefined,
grepInvert: opts.grepInvert as string | undefined, grepInvert: opts.grepInvert as string | undefined,
onlyChanged: getOnlyChangedArg(opts.onlyChanged), onlyChanged: opts.onlyChanged === true ? 'HEAD' : opts.onlyChanged,
project: opts.project || undefined, project: opts.project || undefined,
headed: opts.headed, headed: opts.headed,
reporter: Array.isArray(opts.reporter) ? opts.reporter : opts.reporter ? [opts.reporter] : undefined, reporter: Array.isArray(opts.reporter) ? opts.reporter : opts.reporter ? [opts.reporter] : undefined,

View file

@ -102,45 +102,6 @@ test('should diff based on base commit', async ({ runInlineTest, setupRepository
expect(result.output).toContain('b.spec.ts'); 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 }) => { test('should understand dependency structure', async ({ runInlineTest, setupRepository, writeFiles }) => {
await setupRepository(); await setupRepository();
await writeFiles({ await writeFiles({