also check CI env var
This commit is contained in:
parent
ce788a6a1f
commit
5d2da71fb8
|
|
@ -156,8 +156,15 @@ Examples:
|
|||
function getOnlyChangedArg(input: string | boolean | undefined): string | undefined {
|
||||
if (typeof input === 'string')
|
||||
return input;
|
||||
if (input === true)
|
||||
return process.env.GITHUB_BASE_REF ?? process.env['Build.PullRequest.TargetBranch'] ?? 'HEAD';
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ test.describe('should be smart about PR base reference from CI', () => {
|
|||
`,
|
||||
});
|
||||
git('commit -a -m update');
|
||||
const result = await runInlineTest({}, { 'only-changed': true }, { [envVar]: 'HEAD~1' });
|
||||
const result = await runInlineTest({}, { 'only-changed': true }, { CI: 'true', [envVar]: 'HEAD~1' });
|
||||
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.failed).toBe(1);
|
||||
|
|
@ -120,7 +120,23 @@ test.describe('should be smart about PR base reference from CI', () => {
|
|||
}
|
||||
|
||||
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 }) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue