diff --git a/lib/workers/branch/__snapshots__/index.spec.ts.snap b/lib/workers/branch/__snapshots__/index.spec.ts.snap new file mode 100644 index 0000000000000000000000000000000000000000..bca87b806f646b203a7538bf7706e4b3c48dfffb --- /dev/null +++ b/lib/workers/branch/__snapshots__/index.spec.ts.snap @@ -0,0 +1,175 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`workers/branch/index processBranch branch pr no rebase (dry run) 1`] = ` +Object { + "result": "pr-edited", +} +`; + +exports[`workers/branch/index processBranch branch pr no schedule (dry run) 1`] = ` +Object { + "result": "done", +} +`; + +exports[`workers/branch/index processBranch branch pr no schedule 1`] = ` +Object { + "result": "done", +} +`; + +exports[`workers/branch/index processBranch branch pr no schedule lockfile (dry run) 1`] = ` +Object { + "result": "done", +} +`; + +exports[`workers/branch/index processBranch closed pr (dry run) 1`] = ` +Object { + "result": "already-existed", +} +`; + +exports[`workers/branch/index processBranch continues branch if branch edited and but PR found 1`] = ` +Object { + "result": "error", +} +`; + +exports[`workers/branch/index processBranch does not skip branch if edited PR found with rebaseLabel 1`] = ` +Object { + "result": "error", +} +`; + +exports[`workers/branch/index processBranch executes post-upgrade tasks if trust is high 1`] = ` +Object { + "result": "done", +} +`; + +exports[`workers/branch/index processBranch executes post-upgrade tasks once when set to branch mode 1`] = ` +Object { + "result": "done", +} +`; + +exports[`workers/branch/index processBranch executes post-upgrade tasks with disabled post-upgrade command templating 1`] = ` +Object { + "result": "done", +} +`; + +exports[`workers/branch/index processBranch executes post-upgrade tasks with multiple dependecy in one branch 1`] = ` +Object { + "result": "done", +} +`; + +exports[`workers/branch/index processBranch returns if branch creation limit exceeded 1`] = ` +Object { + "result": "branch-limit-reached", +} +`; + +exports[`workers/branch/index processBranch returns if branch exists and prCreation set to approval 1`] = ` +Object { + "result": "needs-pr-approval", +} +`; + +exports[`workers/branch/index processBranch returns if branch exists but pending 1`] = ` +Object { + "result": "pending", +} +`; + +exports[`workers/branch/index processBranch returns if branch exists but updated 1`] = ` +Object { + "result": "pending", +} +`; + +exports[`workers/branch/index processBranch returns if commit limit exceeded 1`] = ` +Object { + "result": "commit-limit-reached", +} +`; + +exports[`workers/branch/index processBranch returns if no work 1`] = ` +Object { + "result": "no-work", +} +`; + +exports[`workers/branch/index processBranch returns if pr creation limit exceeded and branch exists 1`] = ` +Object { + "result": "pr-limit-reached", +} +`; + +exports[`workers/branch/index processBranch skips branch for fresh release with stabilityDays 1`] = ` +Object { + "result": "pending", +} +`; + +exports[`workers/branch/index processBranch skips branch if branch edited and and PR found with sha mismatch 1`] = ` +Object { + "result": "pr-edited", +} +`; + +exports[`workers/branch/index processBranch skips branch if branch edited and no PR found 1`] = ` +Object { + "result": "pr-edited", +} +`; + +exports[`workers/branch/index processBranch skips branch if edited PR found 1`] = ` +Object { + "result": "pr-edited", +} +`; + +exports[`workers/branch/index processBranch skips branch if not scheduled and branch does not exist 1`] = ` +Object { + "result": "not-scheduled", +} +`; + +exports[`workers/branch/index processBranch skips branch if not scheduled and not updating out of schedule 1`] = ` +Object { + "result": "not-scheduled", +} +`; + +exports[`workers/branch/index processBranch skips branch if not stabilityDays not met 1`] = ` +Object { + "result": "pending", +} +`; + +exports[`workers/branch/index processBranch skips branch if target branch changed 1`] = ` +Object { + "result": "pr-edited", +} +`; + +exports[`workers/branch/index processBranch swallows branch errors 1`] = ` +Object { + "result": "error", +} +`; + +exports[`workers/branch/index processBranch swallows pr errors 1`] = ` +Object { + "result": "done", +} +`; + +exports[`workers/branch/index processBranch throws and swallows branch errors 1`] = ` +Object { + "result": "pr-created", +} +`; diff --git a/lib/workers/branch/index.spec.ts b/lib/workers/branch/index.spec.ts index 1a3c3a941111a5cc7da5e9cbbcf88d9ac76c2482..a38f6cce331b9940414453eac3466487bd8cb5c5 100644 --- a/lib/workers/branch/index.spec.ts +++ b/lib/workers/branch/index.spec.ts @@ -23,7 +23,7 @@ import type { EnsurePrResult } from '../pr'; import * as _prAutomerge from '../pr/automerge'; import type { Pr } from '../repository/onboarding/branch/check'; import type { BranchConfig, BranchUpgradeConfig } from '../types'; -import { BranchResult, PrResult } from '../types'; +import { PrResult } from '../types'; import * as _automerge from './automerge'; import * as _checkExisting from './check-existing'; import * as _commit from './commit'; @@ -71,6 +71,7 @@ describe(getName(__filename), () => { }; let config: BranchConfig; beforeEach(() => { + git.branchExists.mockReturnValue(false); prWorker.ensurePr = jest.fn(); prAutomerge.checkAutoMerge = jest.fn(); config = { @@ -106,14 +107,14 @@ describe(getName(__filename), () => { it('skips branch if not scheduled and branch does not exist', async () => { schedule.isScheduledNow.mockReturnValueOnce(false); const res = await branchWorker.processBranch(config); - expect(res).toEqual({ result: BranchResult.NotScheduled }); + expect(res).toMatchSnapshot(); }); it('skips branch if not scheduled and not updating out of schedule', async () => { schedule.isScheduledNow.mockReturnValueOnce(false); config.updateNotScheduled = false; git.branchExists.mockReturnValue(true); const res = await branchWorker.processBranch(config); - expect(res).toEqual({ result: BranchResult.NotScheduled }); + expect(res).toMatchSnapshot(); }); it('skips branch for fresh release with stabilityDays', async () => { schedule.isScheduledNow.mockReturnValueOnce(true); @@ -136,7 +137,7 @@ describe(getName(__filename), () => { git.branchExists.mockReturnValue(false); const res = await branchWorker.processBranch(config); - expect(res).toEqual({ result: BranchResult.Pending }); + expect(res).toMatchSnapshot(); }); it('skips branch if not stabilityDays not met', async () => { schedule.isScheduledNow.mockReturnValueOnce(true); @@ -148,7 +149,7 @@ describe(getName(__filename), () => { }, ]; const res = await branchWorker.processBranch(config); - expect(res).toEqual({ result: BranchResult.Pending }); + expect(res).toMatchSnapshot(); }); it('processes branch if not scheduled but updating out of schedule', async () => { schedule.isScheduledNow.mockReturnValueOnce(false); @@ -223,7 +224,7 @@ describe(getName(__filename), () => { } as Pr); git.isBranchModified.mockResolvedValueOnce(true); const res = await branchWorker.processBranch(config); - expect(res).not.toEqual({ result: BranchResult.PrEdited }); + expect(res).toMatchSnapshot(); }); it('skips branch if edited PR found', async () => { schedule.isScheduledNow.mockReturnValueOnce(false); @@ -234,7 +235,7 @@ describe(getName(__filename), () => { } as Pr); git.isBranchModified.mockResolvedValueOnce(true); const res = await branchWorker.processBranch(config); - expect(res).toEqual({ result: BranchResult.PrEdited }); + expect(res).toMatchSnapshot(); }); it('skips branch if target branch changed', async () => { schedule.isScheduledNow.mockReturnValueOnce(false); @@ -246,13 +247,13 @@ describe(getName(__filename), () => { git.isBranchModified.mockResolvedValueOnce(false); config.baseBranch = 'master'; const res = await branchWorker.processBranch(config); - expect(res).toEqual({ result: BranchResult.PrEdited }); + expect(res).toMatchSnapshot(); }); it('skips branch if branch edited and no PR found', async () => { git.branchExists.mockReturnValue(true); git.isBranchModified.mockResolvedValueOnce(true); const res = await branchWorker.processBranch(config); - expect(res).toEqual({ result: BranchResult.PrEdited }); + expect(res).toMatchSnapshot(); }); it('continues branch if branch edited and but PR found', async () => { git.branchExists.mockReturnValue(true); @@ -260,7 +261,7 @@ describe(getName(__filename), () => { git.getBranchCommit.mockReturnValueOnce('abc123'); platform.findPr.mockResolvedValueOnce({ sha: 'abc123' } as any); const res = await branchWorker.processBranch(config); - expect(res).toEqual({ result: BranchResult.Error }); + expect(res).toMatchSnapshot(); }); it('skips branch if branch edited and and PR found with sha mismatch', async () => { git.branchExists.mockReturnValue(true); @@ -268,7 +269,7 @@ describe(getName(__filename), () => { git.getBranchCommit.mockReturnValueOnce('abc123'); platform.findPr.mockResolvedValueOnce({ sha: 'def456' } as any); const res = await branchWorker.processBranch(config); - expect(res).toEqual({ result: BranchResult.PrEdited }); + expect(res).toMatchSnapshot(); }); it('returns if branch creation limit exceeded', async () => { getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ @@ -280,9 +281,7 @@ describe(getName(__filename), () => { }); limits.isLimitReached.mockReturnValueOnce(true); limits.isLimitReached.mockReturnValueOnce(false); - expect(await branchWorker.processBranch(config)).toEqual({ - result: BranchResult.BranchLimitReached, - }); + expect(await branchWorker.processBranch(config)).toMatchSnapshot(); }); it('returns if pr creation limit exceeded and branch exists', async () => { getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ @@ -297,9 +296,7 @@ describe(getName(__filename), () => { prResult: PrResult.LimitReached, }); limits.isLimitReached.mockReturnValue(false); - expect(await branchWorker.processBranch(config)).toEqual({ - result: BranchResult.PrLimitReached, - }); + expect(await branchWorker.processBranch(config)).toMatchSnapshot(); }); it('returns if commit limit exceeded', async () => { getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ @@ -312,9 +309,7 @@ describe(getName(__filename), () => { git.branchExists.mockReturnValue(false); limits.isLimitReached.mockReturnValueOnce(false); limits.isLimitReached.mockReturnValueOnce(true); - expect(await branchWorker.processBranch(config)).toEqual({ - result: BranchResult.CommitLimitReached, - }); + expect(await branchWorker.processBranch(config)).toMatchSnapshot(); }); it('returns if no work', async () => { getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ @@ -326,9 +321,7 @@ describe(getName(__filename), () => { }); git.branchExists.mockReturnValue(false); commit.commitFilesToBranch.mockResolvedValueOnce(null); - expect(await branchWorker.processBranch(config)).toEqual({ - result: BranchResult.NoWork, - }); + expect(await branchWorker.processBranch(config)).toMatchSnapshot(); }); it('returns if branch automerged', async () => { getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ @@ -394,9 +387,7 @@ describe(getName(__filename), () => { prWorker.ensurePr.mockResolvedValueOnce({ prResult: PrResult.AwaitingApproval, }); - expect(await branchWorker.processBranch(config)).toEqual({ - result: BranchResult.NeedsPrApproval, - }); + expect(await branchWorker.processBranch(config)).toMatchSnapshot(); }); it('returns if branch exists but pending', async () => { expect.assertions(1); @@ -413,9 +404,7 @@ describe(getName(__filename), () => { prWorker.ensurePr.mockResolvedValueOnce({ prResult: PrResult.AwaitingNotPending, }); - expect(await branchWorker.processBranch(config)).toEqual({ - result: BranchResult.Pending, - }); + expect(await branchWorker.processBranch(config)).toMatchSnapshot(); }); it('returns if branch exists but updated', async () => { expect.assertions(3); @@ -432,7 +421,7 @@ describe(getName(__filename), () => { requiredStatusChecks: null, prCreation: 'not-pending', }) - ).toEqual({ result: BranchResult.Pending }); + ).toMatchSnapshot(); expect(automerge.tryBranchAutomerge).toHaveBeenCalledTimes(0); expect(prWorker.ensurePr).toHaveBeenCalledTimes(0); @@ -570,7 +559,7 @@ describe(getName(__filename), () => { throw new Error('some error'); }); const processBranchResult = await branchWorker.processBranch(config); - expect(processBranchResult).not.toBeNull(); + expect(processBranchResult).toMatchSnapshot(); }); it('throws and swallows branch errors', async () => { getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ @@ -581,7 +570,7 @@ describe(getName(__filename), () => { updatedArtifacts: [{}], } as WriteExistingFilesResult); const processBranchResult = await branchWorker.processBranch(config); - expect(processBranchResult).not.toBeNull(); + expect(processBranchResult).toMatchSnapshot(); }); it('swallows pr errors', async () => { getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce({ @@ -597,7 +586,7 @@ describe(getName(__filename), () => { throw new Error('some error'); }); const processBranchResult = await branchWorker.processBranch(config); - expect(processBranchResult).not.toBeNull(); + expect(processBranchResult).toMatchSnapshot(); }); it('closed pr (dry run)', async () => { @@ -606,9 +595,7 @@ describe(getName(__filename), () => { state: PrState.Closed, } as Pr); setAdminConfig({ dryRun: true }); - expect(await branchWorker.processBranch(config)).toEqual({ - result: BranchResult.AlreadyExisted, - }); + expect(await branchWorker.processBranch(config)).toMatchSnapshot(); }); it('branch pr no rebase (dry run)', async () => { @@ -618,9 +605,7 @@ describe(getName(__filename), () => { } as Pr); git.isBranchModified.mockResolvedValueOnce(true); setAdminConfig({ dryRun: true }); - expect(await branchWorker.processBranch(config)).toEqual({ - result: BranchResult.PrEdited, - }); + expect(await branchWorker.processBranch(config)).toMatchSnapshot(); }); it('branch pr no schedule lockfile (dry run)', async () => { @@ -649,7 +634,7 @@ describe(getName(__filename), () => { reuseExistingBranch: false, updatedArtifacts: [{ name: '|delete|', contents: 'dummy' }], }) - ).toEqual({ result: BranchResult.Done }); + ).toMatchSnapshot(); }); it('branch pr no schedule (dry run)', async () => { @@ -680,7 +665,7 @@ describe(getName(__filename), () => { ...config, artifactErrors: [{}], }) - ).toEqual({ result: BranchResult.Done }); + ).toMatchSnapshot(); }); it('branch pr no schedule', async () => { @@ -708,7 +693,7 @@ describe(getName(__filename), () => { reuseExistingBranch: false, updatedArtifacts: [{ name: '|delete|', contents: 'dummy' }], }) - ).toEqual({ result: BranchResult.Done }); + ).toMatchSnapshot(); }); it('executes post-upgrade tasks if trust is high', async () => { @@ -776,7 +761,7 @@ describe(getName(__filename), () => { ], }); - expect(result).toEqual({ result: BranchResult.Done }); + expect(result).toMatchSnapshot(); expect(exec.exec).toHaveBeenCalledWith('echo semver', { cwd: '/localDir', }); @@ -924,7 +909,7 @@ describe(getName(__filename), () => { ], }); - expect(result).toEqual({ result: BranchResult.Done }); + expect(result).toMatchSnapshot(); expect(exec.exec).toHaveBeenCalledWith('echo {{{versioning}}}', { cwd: '/localDir', }); @@ -1031,7 +1016,7 @@ describe(getName(__filename), () => { const result = await branchWorker.processBranch(inconfig); - expect(result).toEqual({ result: BranchResult.Done }); + expect(result).toMatchSnapshot(); expect(exec.exec).toHaveBeenNthCalledWith(1, 'echo some-dep-name-1', { cwd: '/localDir', }); @@ -1160,7 +1145,7 @@ describe(getName(__filename), () => { }; const result = await branchWorker.processBranch(inconfig); - expect(result).toEqual({ result: BranchResult.Done }); + expect(result).toMatchSnapshot(); expect(exec.exec).toHaveBeenNthCalledWith(1, 'echo hardcoded-string', { cwd: '/localDir', });