Skip to content

Commit

Permalink
test(perform-backmerge.test.ts): add tests for fast forward mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fruit-ninja authored and saitho committed May 11, 2023
1 parent 5632581 commit ca8feff
Showing 1 changed file with 186 additions and 9 deletions.
195 changes: 186 additions & 9 deletions src/perform-backmerge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ describe("perform-backmerge", () => {
verify(mockedGit.fetch(context.options!.repositoryUrl)).once();

verify(mockedGit.checkout('develop')).once();
verify(mockedGit.merge('master', 'none')).once();
verify(mockedGit.merge('master', 'none', 'none')).once();

verify(mockedGit.push('my-repo', 'develop', false)).once();
});

it("checkout mode ours", async () => {
it("merge mode theirs", async () => {
const mockedGit = mock(Git);
const mockedLogger = mock(NullLogger);
when(mockedGit.checkout(anyString())).thenResolve();
Expand All @@ -292,14 +292,14 @@ describe("perform-backmerge", () => {
when(mockedGit.merge(anyString(), anyString())).thenResolve();
when(mockedGit.push(anyString(), anyString(), anything())).thenResolve();

const context = {logger: instance(mockedLogger), branch: {name: 'master'}, options: {repositoryUrl: 'my-repo'}} as Context;
const context = {logger: instance(mockedLogger), branch: {name: 'master'}, options: {repositoryUrl: 'my-repo'}} as Context

await performBackmerge(
instance(mockedGit),
{
backmergeBranches: ['develop'],
backmergeStrategy: 'merge',
mergeMode: 'ours'
mergeMode: 'theirs'
},
context
);
Expand All @@ -309,12 +309,12 @@ describe("perform-backmerge", () => {
verify(mockedGit.fetch(context.options!.repositoryUrl)).once();

verify(mockedGit.checkout('develop')).once();
verify(mockedGit.merge('master', 'ours')).once();
verify(mockedGit.merge('master', 'theirs', 'none')).once();

verify(mockedGit.push('my-repo', 'develop', false)).once();
});

it("merge mode theirs", async () => {
it("merge mode theirs - fast forward default", async () => {
const mockedGit = mock(Git);
const mockedLogger = mock(NullLogger);
when(mockedGit.checkout(anyString())).thenResolve();
Expand All @@ -333,7 +333,78 @@ describe("perform-backmerge", () => {
{
backmergeBranches: ['develop'],
backmergeStrategy: 'merge',
mergeMode: 'theirs'
mergeMode: 'theirs',
fastForwardMode: 'ff'
},
context
);
verify(mockedLogger.log('Performing back-merge into develop branch "develop".')).once();
verify(mockedGit.checkout('master')).once();
verify(mockedGit.configFetchAllRemotes()).once();
verify(mockedGit.fetch(context.options!.repositoryUrl)).once();

verify(mockedGit.checkout('develop')).once();
verify(mockedGit.merge('master', 'theirs', 'ff')).once();

verify(mockedGit.push('my-repo', 'develop', false)).once();
});

it("merge mode theirs - no fast forward", async () => {
const mockedGit = mock(Git);
const mockedLogger = mock(NullLogger);
when(mockedGit.checkout(anyString())).thenResolve();
when(mockedGit.configFetchAllRemotes()).thenResolve();
when(mockedGit.getModifiedFiles())
.thenReturn(new Promise<string[]>(resolve => resolve([])));
when(mockedGit.fetch()).thenResolve();
when(mockedGit.commit(anyString())).thenResolve();
when(mockedGit.merge(anyString(), anyString())).thenResolve();
when(mockedGit.push(anyString(), anyString(), anything())).thenResolve();

const context = {logger: instance(mockedLogger), branch: {name: 'master'}, options: {repositoryUrl: 'my-repo'}} as Context

await performBackmerge(
instance(mockedGit),
{
backmergeBranches: ['develop'],
backmergeStrategy: 'merge',
mergeMode: 'theirs',
fastForwardMode: 'no-ff'
},
context
);
verify(mockedLogger.log('Performing back-merge into develop branch "develop".')).once();
verify(mockedGit.checkout('master')).once();
verify(mockedGit.configFetchAllRemotes()).once();
verify(mockedGit.fetch(context.options!.repositoryUrl)).once();

verify(mockedGit.checkout('develop')).once();
verify(mockedGit.merge('master', 'theirs', 'no-ff')).once();

verify(mockedGit.push('my-repo', 'develop', false)).once();
});

it("merge mode theirs - fast forward only", async () => {
const mockedGit = mock(Git);
const mockedLogger = mock(NullLogger);
when(mockedGit.checkout(anyString())).thenResolve();
when(mockedGit.configFetchAllRemotes()).thenResolve();
when(mockedGit.getModifiedFiles())
.thenReturn(new Promise<string[]>(resolve => resolve([])));
when(mockedGit.fetch()).thenResolve();
when(mockedGit.commit(anyString())).thenResolve();
when(mockedGit.merge(anyString(), anyString())).thenResolve();
when(mockedGit.push(anyString(), anyString(), anything())).thenResolve();

const context = {logger: instance(mockedLogger), branch: {name: 'master'}, options: {repositoryUrl: 'my-repo'}} as Context

await performBackmerge(
instance(mockedGit),
{
backmergeBranches: ['develop'],
backmergeStrategy: 'merge',
mergeMode: 'theirs',
fastForwardMode: 'ff-only'
},
context
);
Expand All @@ -343,7 +414,7 @@ describe("perform-backmerge", () => {
verify(mockedGit.fetch(context.options!.repositoryUrl)).once();

verify(mockedGit.checkout('develop')).once();
verify(mockedGit.merge('master', 'theirs')).once();
verify(mockedGit.merge('master', 'theirs', 'ff-only')).once();

verify(mockedGit.push('my-repo', 'develop', false)).once();
});
Expand Down Expand Up @@ -377,11 +448,117 @@ describe("perform-backmerge", () => {
verify(mockedGit.fetch(context.options!.repositoryUrl)).once();

verify(mockedGit.checkout('develop')).once();
verify(mockedGit.merge('master', 'ours')).once();
verify(mockedGit.merge('master', 'ours', 'none')).once();

verify(mockedGit.push('my-repo', 'develop', false)).once();
});

it("merge mode ours - fast forward default", async () => {
const mockedGit = mock(Git);
const mockedLogger = mock(NullLogger);
when(mockedGit.checkout(anyString())).thenResolve();
when(mockedGit.configFetchAllRemotes()).thenResolve();
when(mockedGit.getModifiedFiles())
.thenReturn(new Promise<string[]>(resolve => resolve([])));
when(mockedGit.fetch()).thenResolve();
when(mockedGit.commit(anyString())).thenResolve();
when(mockedGit.merge(anyString(), anyString())).thenResolve();
when(mockedGit.push(anyString(), anyString(), anything())).thenResolve();

const context = {logger: instance(mockedLogger), branch: {name: 'master'}, options: {repositoryUrl: 'my-repo'}} as Context

await performBackmerge(
instance(mockedGit),
{
backmergeBranches: ['develop'],
backmergeStrategy: 'merge',
mergeMode: 'ours',
fastForwardMode: 'ff'
},
context
);
verify(mockedLogger.log('Performing back-merge into develop branch "develop".')).once();
verify(mockedGit.checkout('master')).once();
verify(mockedGit.configFetchAllRemotes()).once();
verify(mockedGit.fetch(context.options!.repositoryUrl)).once();

verify(mockedGit.checkout('develop')).once();
verify(mockedGit.merge('master', 'ours', 'ff')).once();

verify(mockedGit.push('my-repo', 'develop', false)).once();
});

it("merge mode ours - no fast forward", async () => {
const mockedGit = mock(Git);
const mockedLogger = mock(NullLogger);
when(mockedGit.checkout(anyString())).thenResolve();
when(mockedGit.configFetchAllRemotes()).thenResolve();
when(mockedGit.getModifiedFiles())
.thenReturn(new Promise<string[]>(resolve => resolve([])));
when(mockedGit.fetch()).thenResolve();
when(mockedGit.commit(anyString())).thenResolve();
when(mockedGit.merge(anyString(), anyString())).thenResolve();
when(mockedGit.push(anyString(), anyString(), anything())).thenResolve();

const context = {logger: instance(mockedLogger), branch: {name: 'master'}, options: {repositoryUrl: 'my-repo'}} as Context

await performBackmerge(
instance(mockedGit),
{
backmergeBranches: ['develop'],
backmergeStrategy: 'merge',
mergeMode: 'ours',
fastForwardMode: 'no-ff'
},
context
);
verify(mockedLogger.log('Performing back-merge into develop branch "develop".')).once();
verify(mockedGit.checkout('master')).once();
verify(mockedGit.configFetchAllRemotes()).once();
verify(mockedGit.fetch(context.options!.repositoryUrl)).once();

verify(mockedGit.checkout('develop')).once();
verify(mockedGit.merge('master', 'ours', 'no-ff')).once();

verify(mockedGit.push('my-repo', 'develop', false)).once();
});

it("merge mode ours - fast forward only", async () => {
const mockedGit = mock(Git);
const mockedLogger = mock(NullLogger);
when(mockedGit.checkout(anyString())).thenResolve();
when(mockedGit.configFetchAllRemotes()).thenResolve();
when(mockedGit.getModifiedFiles())
.thenReturn(new Promise<string[]>(resolve => resolve([])));
when(mockedGit.fetch()).thenResolve();
when(mockedGit.commit(anyString())).thenResolve();
when(mockedGit.merge(anyString(), anyString())).thenResolve();
when(mockedGit.push(anyString(), anyString(), anything())).thenResolve();

const context = {logger: instance(mockedLogger), branch: {name: 'master'}, options: {repositoryUrl: 'my-repo'}} as Context

await performBackmerge(
instance(mockedGit),
{
backmergeBranches: ['develop'],
backmergeStrategy: 'merge',
mergeMode: 'ours',
fastForwardMode: 'ff-only'
},
context
);
verify(mockedLogger.log('Performing back-merge into develop branch "develop".')).once();
verify(mockedGit.checkout('master')).once();
verify(mockedGit.configFetchAllRemotes()).once();
verify(mockedGit.fetch(context.options!.repositoryUrl)).once();

verify(mockedGit.checkout('develop')).once();
verify(mockedGit.merge('master', 'ours', 'ff-only')).once();

verify(mockedGit.push('my-repo', 'develop', false)).once();
});
});

describe("perform-backmerge to multiple branches", () => {
it("works with correct configuration", (done) => {
const mockedGit = mock(Git);
Expand Down

0 comments on commit ca8feff

Please sign in to comment.