UNPKG

@atlaskit/build-utils

Version:

Collection of utilities to used during the release process of Atlaskit

82 lines (70 loc) 2.47 kB
// @flow const fs = require('fs'); const os = require('os'); const path = require('path'); const { branch, checkout, commit, getBaseBranch, merge, } = require('./../../git'); const { cleanUp, createTmpRemoteRepository, createTmpLocalRepository, } = require('./_utils.git'); let tmpRemotePath = ''; let tmpLocalPath = ''; beforeAll(async () => { tmpRemotePath = fs.mkdtempSync(path.join(os.tmpdir(), 'git-origin-')); await createTmpRemoteRepository({ cwd: tmpRemotePath }); }); beforeEach(async () => { tmpLocalPath = fs.mkdtempSync(path.join(os.tmpdir(), 'git-local-')); await createTmpLocalRepository(tmpRemotePath, { cwd: tmpLocalPath }); }); afterEach(async () => { cleanUp(tmpLocalPath); }); afterAll(() => { cleanUp(tmpRemotePath); }); describe('getBaseBranch >', () => { test('Master should return master as a parent', async () => { const parent = await getBaseBranch('HEAD', { cwd: tmpLocalPath }); expect(parent).toBe('master'); }); test('Develop should return develop as a parent', async () => { const parent = await getBaseBranch('origin/develop', { cwd: tmpLocalPath }); expect(parent).toBe('develop'); }); test('A branch tipped off develop should return develop as a parent', async () => { await checkout('develop', { cwd: tmpLocalPath }); await branch('from-develop', { cwd: tmpLocalPath }); await commit('Initial commit for develop temp origin', { cwd: tmpLocalPath, }); const parent = await getBaseBranch('HEAD', { cwd: tmpLocalPath }); expect(parent).toBe('develop'); }); test('A branch tipped off master should return master as a parent', async () => { await checkout('master', { cwd: tmpLocalPath }); await branch('from-master', { cwd: tmpLocalPath }); await commit('Initial commit for from-master temp origin', { cwd: tmpLocalPath, }); const parent = await getBaseBranch('HEAD', { cwd: tmpLocalPath }); expect(parent).toBe('master'); }); test('A branch tipped off develop and you merge master in should return develop as a parent', async () => { await checkout('develop', { cwd: tmpLocalPath }); await branch('from-develop', { cwd: tmpLocalPath }); await commit('Initial commit for develop temp origin', { cwd: tmpLocalPath, }); await merge('master', { cwd: tmpLocalPath }); const parent = await getBaseBranch('HEAD', { cwd: tmpLocalPath }); expect(parent).toBe('develop'); }); });