diff --git a/node-src/git/getCommitAndBranch.test.ts b/node-src/git/getCommitAndBranch.test.ts index 07f40cc60..4e1ac288a 100644 --- a/node-src/git/getCommitAndBranch.test.ts +++ b/node-src/git/getCommitAndBranch.test.ts @@ -87,11 +87,19 @@ describe('getCommitAndBranch', () => { expect(info).toMatchObject({ branch: 'master' }); }); - it('throws when there is only one commit', async () => { + it('throws when there is only one commit, CI', async () => { + envCi.mockReturnValue({ isCi: true }); hasPreviousCommit.mockResolvedValue(false); await expect(getCommitAndBranch({ log })).rejects.toThrow('Found only one commit'); }); + it('does NOT throw when there is only one commit, non-CI', async () => { + envCi.mockReturnValue({ isCi: false }); + hasPreviousCommit.mockResolvedValue(false); + const info = await getCommitAndBranch({ log }); + expect(info).toMatchObject({}); + }); + describe('with branchName', () => { it('uses provided branchName as branch', async () => { const info = await getCommitAndBranch({ log }, { branchName: 'foobar' }); diff --git a/node-src/git/getCommitAndBranch.ts b/node-src/git/getCommitAndBranch.ts index f6a4cc63e..4f20ac369 100644 --- a/node-src/git/getCommitAndBranch.ts +++ b/node-src/git/getCommitAndBranch.ts @@ -50,6 +50,7 @@ export default async function getCommitAndBranch( CHROMATIC_PULL_REQUEST_SHA, CHROMATIC_SLUG, } = process.env; + const { isCi, service, prBranch, branch: ciBranch, commit: ciCommit, slug: ciSlug } = envCi(); const isFromEnvVariable = CHROMATIC_SHA && CHROMATIC_BRANCH; // Our GitHub Action also sets these const isTravisPrBuild = TRAVIS_EVENT_TYPE === 'pull_request'; @@ -57,7 +58,12 @@ export default async function getCommitAndBranch( const isGitHubPrBuild = GITHUB_EVENT_NAME === 'pull_request'; if (!(await hasPreviousCommit())) { - throw new Error(gitOneCommit(isGitHubAction)); + const message = gitOneCommit(isGitHubAction); + if (isCi) { + throw new Error(message); + } else { + log.warn(message); + } } if (isFromEnvVariable) { @@ -117,7 +123,6 @@ export default async function getCommitAndBranch( slug = GITHUB_REPOSITORY; } - const { isCi, service, prBranch, branch: ciBranch, commit: ciCommit, slug: ciSlug } = envCi(); const ciService = process.env.CHROMATIC_ACTION ? 'chromaui/action' : service; slug = slug || ciSlug; diff --git a/package.json b/package.json index 33658a53c..4a81c9db5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chromatic", - "version": "7.0.0", + "version": "7.1.0-canary.4", "description": "Automate visual testing across browsers. Gather UI feedback. Versioned documentation.", "keywords": [ "storybook-addon",