Skip to content

Commit

Permalink
add more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-titarenko committed Mar 17, 2024
1 parent d55f165 commit b6b8bce
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/merge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,46 @@ describe('merge-e2e', () => {
expect(newDirFiles.length).toBe(2)
})

it('merge subfolders with the same name who have a new parent with the same name', async () => {
// ARRANGE
const { fs, dir } = await makeFsFixture()

// initializing new repo
await init({ fs, dir, defaultBranch: branch1Name })
await commit({ fs, dir, message: 'first commit', author: { name: 'author0' } })
await branch({ fs, dir, ref: branch2Name, checkout: false })

// writing files to the branch1
await fs.mkdir(path.resolve(dir, newDirName))
await fs.mkdir(path.resolve(dir, newDirName, 'sub-folder'))
await fs.writeFile(path.resolve(dir, newDirName, 'sub-folder', 'new-file1.txt'), 'some content 1')
await add({ fs, dir, filepath: path.resolve(newDirName, 'sub-folder', 'new-file1.txt') })
await commit({ fs, dir, message: 'add files', author: { name: 'author1' } })

// writing files to a branch2
await checkout({ fs, dir, ref: branch2Name })
await fs.mkdir(path.resolve(dir, newDirName))
await fs.mkdir(path.resolve(dir, newDirName, 'sub-folder'))
await fs.writeFile(path.resolve(dir, newDirName, 'sub-folder', 'new-file2.txt'), 'some content 2')
await add({ fs, dir, filepath: path.resolve(newDirName, 'sub-folder', 'new-file2.txt') })
await commit({ fs, dir, message: 'add files', author: { name: 'author2' } })

// switching back to the branch1
await checkout({ fs, dir, ref: branch1Name })

// ACT
const m = await merge({ fs, dir, ours: branch1Name, theirs: branch2Name, author: { name: 'author3' } })
await checkout({ fs, dir, ref: branch1Name })

// ASSERT
expect(m.alreadyMerged).toBeFalsy()
expect(m.mergeCommit).toBeTruthy()
const newDirFiles = await fs.readdir(path.resolve(dir, newDirName))
expect(newDirFiles.length).toBe(1)
const newSubDirFiles = await fs.readdir(path.resolve(dir, newDirName, 'sub-folder'))
expect(newSubDirFiles.length).toBe(2)
})

it('merge new folder and file with the same name should fail', async () => {
// ARRANGE
const { fs, dir } = await makeFsFixture()
Expand Down

0 comments on commit b6b8bce

Please sign in to comment.