🎨 cleanup

This commit is contained in:
Markus Olsson 2022-05-18 20:35:53 +02:00
parent 6b887a2a64
commit a9f364a5f1

View file

@ -6,91 +6,54 @@ import { ComputedAction } from '../../../src/models/computed-action'
import { parseMergeTreeResult } from '../../../src/lib/git/merge-tree'
import { createReadStream } from 'fs'
const filenameRegex = /merge\-(.*)\-into\-(.*).txt/
const fixturePath = (...pathComponents: string[]) =>
Path.join(__dirname, '../../fixtures/merge-parser/', ...pathComponents)
function loadMergeTreeOutputs(context: string) {
const relativePath = Path.join(
__dirname,
`../../fixtures/merge-parser/${context}/merge-*.txt`
)
return glob.sync(relativePath)
}
const loadMergeTreeOutputs = (context: string) =>
glob.sync(fixturePath(context, 'merge-*.txt'))
function extractBranchNames(path: string): { ours: string; theirs: string } {
const fileName = Path.basename(path)
const match = filenameRegex.exec(fileName)
const match = /merge\-(.*)\-into\-(.*).txt/.exec(Path.basename(path))
if (match == null || match.length !== 3) {
throw new Error(
`Unable to convert filename into branches for test setup: ${fileName}. Please review this test.`
)
if (match && match.length === 3) {
return { ours: match[2], theirs: match[1] }
}
const theirs = match[1]
const ours = match[2]
return { ours, theirs }
throw new Error(`Wrong path for test setup: ${path}`)
}
describe('parseMergeResult', () => {
it('can process a successful merge result', async () => {
const relativePath = Path.join(
__dirname,
'../../fixtures/merge-parser/desktop/valid-merge-master-into-script-upgrade.txt'
const path = fixturePath(
'desktop',
'valid-merge-master-into-script-upgrade.txt'
)
const result = await parseMergeTreeResult(createReadStream(relativePath))
const result = await parseMergeTreeResult(createReadStream(path))
expect(result.kind).toBe(ComputedAction.Clean)
})
it('can report on merge conflicts', async () => {
const relativePath = Path.join(
__dirname,
'../../fixtures/merge-parser/desktop/failed-merge-stale-branch-into-master.txt'
const path = fixturePath(
'desktop',
'failed-merge-stale-branch-into-master.txt'
)
const result = await parseMergeTreeResult(createReadStream(relativePath))
const result = await parseMergeTreeResult(createReadStream(path))
expect(result.kind).toBe(ComputedAction.Conflicts)
expect((result as MergeTreeError).conflictedFiles).toBe(1)
})
describe('desktop/desktop', () => {
const files = loadMergeTreeOutputs('desktop')
const repos = ['desktop/desktop', 'electron/electron', 'microsoft/vscode']
for (const repo of repos) {
describe(repo, () => {
for (const f of loadMergeTreeOutputs(Path.basename(repo))) {
const { ours, theirs } = extractBranchNames(f)
for (const f of files) {
const { ours, theirs } = extractBranchNames(f)
it(`can parse conflicts from merging ${theirs} into ${ours}`, async () => {
const result = await parseMergeTreeResult(createReadStream(f))
expect(result.kind).toBe(ComputedAction.Conflicts)
expect((result as MergeTreeError).conflictedFiles).toBeGreaterThan(0)
})
}
})
describe('electron/electron', () => {
const files = loadMergeTreeOutputs('electron')
for (const f of files) {
const { ours, theirs } = extractBranchNames(f)
it(`can parse conflicts from merging ${theirs} into ${ours}`, async () => {
const result = await parseMergeTreeResult(createReadStream(f))
expect(result.kind).toBe(ComputedAction.Conflicts)
expect((result as MergeTreeError).conflictedFiles).toBeGreaterThan(0)
})
}
})
describe('microsoft/vscode', () => {
const files = loadMergeTreeOutputs('vscode')
for (const f of files) {
const { ours, theirs } = extractBranchNames(f)
it(`can parse conflicts from merging ${theirs} into ${ours}`, async () => {
const result = await parseMergeTreeResult(createReadStream(f))
expect(result.kind).toBe(ComputedAction.Conflicts)
expect((result as MergeTreeError).conflictedFiles).toBeGreaterThan(0)
})
}
})
it(`can parse conflicts from merging ${theirs} into ${ours}`, async () => {
const result = await parseMergeTreeResult(createReadStream(f))
expect(result.kind).toBe(ComputedAction.Conflicts)
expect((result as MergeTreeError).conflictedFiles).toBeGreaterThan(0)
})
}
})
}
})