2017-06-29 05:29:41 +00:00
|
|
|
const branchWorker = require('../../../lib/workers/branch');
|
|
|
|
const prWorker = require('../../../lib/workers/pr');
|
|
|
|
const npm = require('../../../lib/workers/branch/npm');
|
|
|
|
const yarn = require('../../../lib/workers/branch/yarn');
|
|
|
|
const defaultConfig = require('../../../lib/config/defaults').getConfig();
|
|
|
|
const packageJsonHelper = require('../../../lib/workers/branch/package-json');
|
2017-02-14 07:08:40 +00:00
|
|
|
|
2017-06-29 05:29:41 +00:00
|
|
|
const logger = require('../../_fixtures/logger');
|
2017-06-22 07:03:36 +00:00
|
|
|
|
2017-06-29 05:29:41 +00:00
|
|
|
jest.mock('../../../lib/workers/branch/yarn');
|
|
|
|
jest.mock('../../../lib/workers/branch/package-json');
|
2017-02-14 07:08:40 +00:00
|
|
|
|
|
|
|
describe('workers/branch', () => {
|
|
|
|
describe('getParentBranch(branchName, config)', () => {
|
|
|
|
let config;
|
|
|
|
const branchName = 'foo';
|
|
|
|
beforeEach(() => {
|
|
|
|
config = {
|
|
|
|
api: {
|
|
|
|
branchExists: jest.fn(() => true),
|
2017-06-22 09:56:23 +00:00
|
|
|
deleteBranch: jest.fn(),
|
2017-02-14 07:08:40 +00:00
|
|
|
getBranchPr: jest.fn(),
|
2017-06-08 04:18:21 +00:00
|
|
|
getBranchStatus: jest.fn(),
|
|
|
|
isBranchStale: jest.fn(() => false),
|
2017-02-14 07:08:40 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
it('returns undefined if branch does not exist', async () => {
|
|
|
|
config.api.branchExists.mockReturnValue(false);
|
2017-04-21 08:12:41 +00:00
|
|
|
expect(await branchWorker.getParentBranch(branchName, config)).toBe(
|
2017-04-21 08:25:49 +00:00
|
|
|
undefined
|
2017-04-21 08:12:41 +00:00
|
|
|
);
|
2017-02-14 07:08:40 +00:00
|
|
|
});
|
|
|
|
it('returns branchName if no PR', async () => {
|
|
|
|
config.api.getBranchPr.mockReturnValue(null);
|
2017-04-21 08:12:41 +00:00
|
|
|
expect(await branchWorker.getParentBranch(branchName, config)).toBe(
|
2017-04-21 08:25:49 +00:00
|
|
|
branchName
|
2017-04-21 08:12:41 +00:00
|
|
|
);
|
2017-02-14 07:08:40 +00:00
|
|
|
});
|
2017-06-08 04:18:21 +00:00
|
|
|
it('returns branchName if does not need rebaseing', async () => {
|
2017-02-14 07:08:40 +00:00
|
|
|
config.api.getBranchPr.mockReturnValue({
|
|
|
|
isUnmergeable: false,
|
|
|
|
});
|
2017-04-21 08:12:41 +00:00
|
|
|
expect(await branchWorker.getParentBranch(branchName, config)).toBe(
|
2017-04-21 08:25:49 +00:00
|
|
|
branchName
|
2017-04-21 08:12:41 +00:00
|
|
|
);
|
2017-02-14 07:08:40 +00:00
|
|
|
});
|
2017-06-08 04:18:21 +00:00
|
|
|
it('returns branchName if unmergeable and cannot rebase', async () => {
|
2017-02-14 07:08:40 +00:00
|
|
|
config.api.getBranchPr.mockReturnValue({
|
|
|
|
isUnmergeable: true,
|
|
|
|
canRebase: false,
|
|
|
|
});
|
2017-04-21 08:12:41 +00:00
|
|
|
expect(await branchWorker.getParentBranch(branchName, config)).toBe(
|
2017-04-21 08:25:49 +00:00
|
|
|
branchName
|
2017-04-21 08:12:41 +00:00
|
|
|
);
|
2017-02-14 07:08:40 +00:00
|
|
|
});
|
2017-06-08 04:18:21 +00:00
|
|
|
it('returns undefined if unmergeable and can rebase', async () => {
|
2017-02-14 07:08:40 +00:00
|
|
|
config.api.getBranchPr.mockReturnValue({
|
|
|
|
isUnmergeable: true,
|
|
|
|
canRebase: true,
|
|
|
|
});
|
2017-04-21 08:12:41 +00:00
|
|
|
expect(await branchWorker.getParentBranch(branchName, config)).toBe(
|
2017-04-21 08:25:49 +00:00
|
|
|
undefined
|
2017-04-21 08:12:41 +00:00
|
|
|
);
|
2017-02-14 07:08:40 +00:00
|
|
|
});
|
2017-06-22 09:56:23 +00:00
|
|
|
it('returns undefined if unmergeable and can rebase (gitlab)', async () => {
|
2017-06-28 11:20:31 +00:00
|
|
|
config.isGitLab = true;
|
2017-06-22 09:56:23 +00:00
|
|
|
config.api.getBranchPr.mockReturnValue({
|
|
|
|
isUnmergeable: true,
|
|
|
|
canRebase: true,
|
|
|
|
});
|
|
|
|
expect(await branchWorker.getParentBranch(branchName, config)).toBe(
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
expect(config.api.deleteBranch.mock.calls.length).toBe(1);
|
|
|
|
});
|
2017-06-08 04:18:21 +00:00
|
|
|
it('returns branchName if automerge branch-push and not stale', async () => {
|
|
|
|
config.automergeEnabled = true;
|
|
|
|
config.automergeType = 'branch-push';
|
2017-04-21 08:12:41 +00:00
|
|
|
expect(await branchWorker.getParentBranch(branchName, config)).toBe(
|
2017-04-21 08:25:49 +00:00
|
|
|
branchName
|
2017-04-21 08:12:41 +00:00
|
|
|
);
|
2017-02-14 07:08:40 +00:00
|
|
|
});
|
2017-06-08 04:18:21 +00:00
|
|
|
it('returns undefined if automerge branch-push and stale', async () => {
|
|
|
|
config.automergeEnabled = true;
|
|
|
|
config.automergeType = 'branch-push';
|
|
|
|
config.api.isBranchStale.mockReturnValueOnce(true);
|
2017-04-21 08:12:41 +00:00
|
|
|
expect(await branchWorker.getParentBranch(branchName, config)).toBe(
|
2017-04-21 08:25:49 +00:00
|
|
|
undefined
|
2017-04-21 08:12:41 +00:00
|
|
|
);
|
2017-02-14 07:08:40 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('ensureBranch(config)', () => {
|
|
|
|
let config;
|
|
|
|
beforeEach(() => {
|
|
|
|
packageJsonHelper.setNewValue = jest.fn();
|
|
|
|
branchWorker.getParentBranch = jest.fn();
|
2017-06-29 05:29:41 +00:00
|
|
|
npm.getLockFile = jest.fn();
|
|
|
|
yarn.getLockFile = jest.fn();
|
|
|
|
yarn.maintainLockFile = jest.fn();
|
2017-02-14 07:08:40 +00:00
|
|
|
config = Object.assign({}, defaultConfig);
|
|
|
|
config.api = {};
|
|
|
|
config.api.getFileContent = jest.fn();
|
2017-04-17 04:46:24 +00:00
|
|
|
config.api.branchExists = jest.fn();
|
2017-02-14 07:08:40 +00:00
|
|
|
config.api.commitFilesToBranch = jest.fn();
|
|
|
|
config.api.getFileContent.mockReturnValueOnce('old content');
|
2017-06-08 04:18:21 +00:00
|
|
|
config.api.getBranchStatus = jest.fn();
|
2017-02-14 07:08:40 +00:00
|
|
|
config.depName = 'dummy';
|
|
|
|
config.currentVersion = '1.0.0';
|
|
|
|
config.newVersion = '1.1.0';
|
2017-06-08 04:18:21 +00:00
|
|
|
config.newVersionMajor = 1;
|
2017-06-28 20:33:27 +00:00
|
|
|
config.versions = {};
|
2017-07-02 05:50:46 +00:00
|
|
|
config.upgrades = [Object.assign({}, config)];
|
2017-02-14 07:08:40 +00:00
|
|
|
});
|
|
|
|
it('returns if new content matches old', async () => {
|
|
|
|
branchWorker.getParentBranch.mockReturnValueOnce('dummy branch');
|
|
|
|
packageJsonHelper.setNewValue.mockReturnValueOnce('old content');
|
2017-04-17 04:46:24 +00:00
|
|
|
config.api.branchExists.mockReturnValueOnce(false);
|
2017-07-02 05:50:46 +00:00
|
|
|
expect(await branchWorker.ensureBranch(config)).toBe(false);
|
2017-02-14 07:08:40 +00:00
|
|
|
expect(branchWorker.getParentBranch.mock.calls.length).toBe(1);
|
|
|
|
expect(packageJsonHelper.setNewValue.mock.calls.length).toBe(1);
|
2017-06-29 05:29:41 +00:00
|
|
|
expect(npm.getLockFile.mock.calls.length).toBe(0);
|
|
|
|
expect(yarn.getLockFile.mock.calls.length).toBe(0);
|
2017-02-14 07:08:40 +00:00
|
|
|
});
|
2017-06-02 06:29:36 +00:00
|
|
|
it('commits one file if no yarn lock or package-lock.json found', async () => {
|
2017-02-14 07:08:40 +00:00
|
|
|
branchWorker.getParentBranch.mockReturnValueOnce('dummy branch');
|
|
|
|
packageJsonHelper.setNewValue.mockReturnValueOnce('new content');
|
2017-06-08 04:18:21 +00:00
|
|
|
config.api.branchExists.mockReturnValueOnce(true);
|
2017-07-02 05:50:46 +00:00
|
|
|
expect(await branchWorker.ensureBranch(config)).toBe(true);
|
2017-06-08 04:18:21 +00:00
|
|
|
expect(branchWorker.getParentBranch.mock.calls.length).toBe(1);
|
|
|
|
expect(packageJsonHelper.setNewValue.mock.calls.length).toBe(1);
|
2017-06-29 05:29:41 +00:00
|
|
|
expect(npm.getLockFile.mock.calls.length).toBe(1);
|
|
|
|
expect(yarn.getLockFile.mock.calls.length).toBe(1);
|
2017-06-08 04:18:21 +00:00
|
|
|
expect(config.api.commitFilesToBranch.mock.calls[0][1].length).toBe(1);
|
|
|
|
});
|
|
|
|
it('returns true if automerging pr', async () => {
|
|
|
|
branchWorker.getParentBranch.mockReturnValueOnce('dummy branch');
|
|
|
|
packageJsonHelper.setNewValue.mockReturnValueOnce('new content');
|
|
|
|
config.api.branchExists.mockReturnValueOnce(true);
|
|
|
|
config.automergeEnabled = true;
|
|
|
|
config.automergeType = 'pr';
|
2017-07-02 05:50:46 +00:00
|
|
|
expect(await branchWorker.ensureBranch(config)).toBe(true);
|
2017-06-08 04:18:21 +00:00
|
|
|
expect(branchWorker.getParentBranch.mock.calls.length).toBe(1);
|
|
|
|
expect(packageJsonHelper.setNewValue.mock.calls.length).toBe(1);
|
2017-06-29 05:29:41 +00:00
|
|
|
expect(npm.getLockFile.mock.calls.length).toBe(1);
|
|
|
|
expect(yarn.getLockFile.mock.calls.length).toBe(1);
|
2017-06-08 04:18:21 +00:00
|
|
|
expect(config.api.commitFilesToBranch.mock.calls[0][1].length).toBe(1);
|
|
|
|
});
|
|
|
|
it('automerges successful branches', async () => {
|
|
|
|
branchWorker.getParentBranch.mockReturnValueOnce('dummy branch');
|
|
|
|
packageJsonHelper.setNewValue.mockReturnValueOnce('new content');
|
|
|
|
config.api.branchExists.mockReturnValueOnce(true);
|
|
|
|
config.api.getBranchStatus.mockReturnValueOnce('success');
|
|
|
|
config.api.mergeBranch = jest.fn();
|
|
|
|
config.automergeEnabled = true;
|
|
|
|
config.automergeType = 'branch-push';
|
2017-07-02 05:50:46 +00:00
|
|
|
expect(await branchWorker.ensureBranch(config)).toBe(true);
|
2017-06-08 04:18:21 +00:00
|
|
|
expect(branchWorker.getParentBranch.mock.calls.length).toBe(1);
|
|
|
|
expect(config.api.getBranchStatus.mock.calls.length).toBe(1);
|
|
|
|
expect(config.api.mergeBranch.mock).toMatchSnapshot();
|
|
|
|
expect(packageJsonHelper.setNewValue.mock.calls.length).toBe(1);
|
2017-06-29 05:29:41 +00:00
|
|
|
expect(npm.getLockFile.mock.calls.length).toBe(1);
|
|
|
|
expect(yarn.getLockFile.mock.calls.length).toBe(1);
|
2017-06-08 04:18:21 +00:00
|
|
|
expect(config.api.commitFilesToBranch.mock.calls[0][1].length).toBe(1);
|
|
|
|
});
|
|
|
|
it('skips automerge if status not success', async () => {
|
|
|
|
branchWorker.getParentBranch.mockReturnValueOnce('dummy branch');
|
|
|
|
packageJsonHelper.setNewValue.mockReturnValueOnce('new content');
|
|
|
|
config.api.branchExists.mockReturnValueOnce(true);
|
|
|
|
config.api.getBranchStatus.mockReturnValueOnce('pending');
|
|
|
|
config.api.mergeBranch = jest.fn();
|
|
|
|
config.automergeEnabled = true;
|
|
|
|
config.automergeType = 'branch-push';
|
2017-07-02 05:50:46 +00:00
|
|
|
expect(await branchWorker.ensureBranch(config)).toBe(true);
|
2017-06-08 04:18:21 +00:00
|
|
|
expect(branchWorker.getParentBranch.mock.calls.length).toBe(1);
|
|
|
|
expect(config.api.getBranchStatus.mock.calls.length).toBe(1);
|
|
|
|
expect(config.api.mergeBranch.mock.calls.length).toBe(0);
|
|
|
|
expect(packageJsonHelper.setNewValue.mock.calls.length).toBe(1);
|
2017-06-29 05:29:41 +00:00
|
|
|
expect(npm.getLockFile.mock.calls.length).toBe(1);
|
|
|
|
expect(yarn.getLockFile.mock.calls.length).toBe(1);
|
2017-06-08 04:18:21 +00:00
|
|
|
expect(config.api.commitFilesToBranch.mock.calls[0][1].length).toBe(1);
|
|
|
|
});
|
|
|
|
it('throws if automerge throws', async () => {
|
|
|
|
branchWorker.getParentBranch.mockReturnValueOnce('dummy branch');
|
|
|
|
packageJsonHelper.setNewValue.mockReturnValueOnce('new content');
|
|
|
|
config.api.branchExists.mockReturnValueOnce(true);
|
|
|
|
config.api.getBranchStatus.mockReturnValueOnce('success');
|
|
|
|
config.automergeEnabled = true;
|
|
|
|
config.automergeType = 'branch-push';
|
|
|
|
config.api.mergeBranch = jest.fn(() => {
|
|
|
|
throw new Error('automerge failed');
|
|
|
|
});
|
|
|
|
let e;
|
|
|
|
try {
|
2017-07-02 05:50:46 +00:00
|
|
|
await branchWorker.ensureBranch(config);
|
2017-06-08 04:18:21 +00:00
|
|
|
} catch (err) {
|
|
|
|
e = err;
|
|
|
|
}
|
|
|
|
expect(e).toMatchSnapshot();
|
2017-02-14 07:08:40 +00:00
|
|
|
expect(branchWorker.getParentBranch.mock.calls.length).toBe(1);
|
2017-06-08 04:18:21 +00:00
|
|
|
expect(config.api.getBranchStatus.mock.calls.length).toBe(1);
|
|
|
|
expect(config.api.mergeBranch.mock).toMatchSnapshot();
|
2017-02-14 07:08:40 +00:00
|
|
|
expect(packageJsonHelper.setNewValue.mock.calls.length).toBe(1);
|
2017-06-29 05:29:41 +00:00
|
|
|
expect(npm.getLockFile.mock.calls.length).toBe(1);
|
|
|
|
expect(yarn.getLockFile.mock.calls.length).toBe(1);
|
2017-02-14 07:08:40 +00:00
|
|
|
expect(config.api.commitFilesToBranch.mock.calls[0][1].length).toBe(1);
|
|
|
|
});
|
|
|
|
it('commits two files if yarn lock found', async () => {
|
|
|
|
branchWorker.getParentBranch.mockReturnValueOnce('dummy branch');
|
2017-06-29 05:29:41 +00:00
|
|
|
yarn.getLockFile.mockReturnValueOnce('non null response');
|
2017-02-14 07:08:40 +00:00
|
|
|
packageJsonHelper.setNewValue.mockReturnValueOnce('new content');
|
2017-07-02 05:50:46 +00:00
|
|
|
await branchWorker.ensureBranch(config);
|
2017-02-14 07:08:40 +00:00
|
|
|
expect(branchWorker.getParentBranch.mock.calls.length).toBe(1);
|
|
|
|
expect(packageJsonHelper.setNewValue.mock.calls.length).toBe(1);
|
2017-06-29 05:29:41 +00:00
|
|
|
expect(npm.getLockFile.mock.calls.length).toBe(1);
|
|
|
|
expect(yarn.getLockFile.mock.calls.length).toBe(1);
|
2017-02-14 07:08:40 +00:00
|
|
|
expect(config.api.commitFilesToBranch.mock.calls[0][1].length).toBe(2);
|
|
|
|
});
|
2017-06-02 06:29:36 +00:00
|
|
|
it('commits two files if package lock found', async () => {
|
|
|
|
branchWorker.getParentBranch.mockReturnValueOnce('dummy branch');
|
2017-06-29 05:29:41 +00:00
|
|
|
npm.getLockFile.mockReturnValueOnce('non null response');
|
2017-06-02 06:29:36 +00:00
|
|
|
packageJsonHelper.setNewValue.mockReturnValueOnce('new content');
|
2017-07-02 05:50:46 +00:00
|
|
|
await branchWorker.ensureBranch(config);
|
2017-06-02 06:29:36 +00:00
|
|
|
expect(branchWorker.getParentBranch.mock.calls.length).toBe(1);
|
|
|
|
expect(packageJsonHelper.setNewValue.mock.calls.length).toBe(1);
|
2017-06-29 05:29:41 +00:00
|
|
|
expect(npm.getLockFile.mock.calls.length).toBe(1);
|
|
|
|
expect(yarn.getLockFile.mock.calls.length).toBe(1);
|
2017-06-02 06:29:36 +00:00
|
|
|
expect(config.api.commitFilesToBranch.mock.calls[0][1].length).toBe(2);
|
|
|
|
});
|
|
|
|
it('commits three files if yarn lock and package lock found', async () => {
|
|
|
|
branchWorker.getParentBranch.mockReturnValueOnce('dummy branch');
|
2017-06-29 05:29:41 +00:00
|
|
|
npm.getLockFile.mockReturnValueOnce('non null response');
|
|
|
|
yarn.getLockFile.mockReturnValueOnce('non null response');
|
2017-06-02 06:29:36 +00:00
|
|
|
packageJsonHelper.setNewValue.mockReturnValueOnce('new content');
|
2017-07-02 05:50:46 +00:00
|
|
|
await branchWorker.ensureBranch(config);
|
2017-06-02 06:29:36 +00:00
|
|
|
expect(branchWorker.getParentBranch.mock.calls.length).toBe(1);
|
|
|
|
expect(packageJsonHelper.setNewValue.mock.calls.length).toBe(1);
|
2017-06-29 05:29:41 +00:00
|
|
|
expect(npm.getLockFile.mock.calls.length).toBe(1);
|
|
|
|
expect(yarn.getLockFile.mock.calls.length).toBe(1);
|
2017-06-02 06:29:36 +00:00
|
|
|
expect(config.api.commitFilesToBranch.mock.calls[0][1].length).toBe(3);
|
|
|
|
});
|
2017-06-02 06:06:44 +00:00
|
|
|
it('throws an error if no yarn lock generation possible', async () => {
|
|
|
|
branchWorker.getParentBranch.mockReturnValueOnce('dummy branch');
|
2017-06-29 05:29:41 +00:00
|
|
|
yarn.getLockFile.mockImplementationOnce(() => {
|
2017-06-02 06:06:44 +00:00
|
|
|
throw new Error('yarn not found');
|
|
|
|
});
|
|
|
|
packageJsonHelper.setNewValue.mockReturnValueOnce('new content');
|
|
|
|
let err;
|
|
|
|
try {
|
2017-07-02 05:50:46 +00:00
|
|
|
await branchWorker.ensureBranch(config);
|
2017-06-02 06:06:44 +00:00
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
2017-06-28 20:33:27 +00:00
|
|
|
expect(err.message).toBe('yarn not found');
|
2017-06-02 06:06:44 +00:00
|
|
|
expect(branchWorker.getParentBranch.mock.calls.length).toBe(1);
|
|
|
|
expect(packageJsonHelper.setNewValue.mock.calls.length).toBe(1);
|
2017-06-29 05:29:41 +00:00
|
|
|
expect(yarn.getLockFile.mock.calls.length).toBe(1);
|
|
|
|
expect(npm.getLockFile.mock.calls.length).toBe(0);
|
2017-06-02 06:29:36 +00:00
|
|
|
expect(config.api.commitFilesToBranch.mock.calls.length).toBe(0);
|
|
|
|
});
|
|
|
|
it('throws an error if no package lock generation possible', async () => {
|
|
|
|
branchWorker.getParentBranch.mockReturnValueOnce('dummy branch');
|
2017-06-29 05:29:41 +00:00
|
|
|
npm.getLockFile.mockImplementationOnce(() => {
|
2017-06-02 06:29:36 +00:00
|
|
|
throw new Error('no package lock generated');
|
|
|
|
});
|
|
|
|
packageJsonHelper.setNewValue.mockReturnValueOnce('new content');
|
|
|
|
let err;
|
|
|
|
try {
|
2017-07-02 05:50:46 +00:00
|
|
|
await branchWorker.ensureBranch(config);
|
2017-06-02 06:29:36 +00:00
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
2017-06-28 20:33:27 +00:00
|
|
|
expect(err.message).toBe('no package lock generated');
|
2017-06-02 06:29:36 +00:00
|
|
|
expect(branchWorker.getParentBranch.mock.calls.length).toBe(1);
|
|
|
|
expect(packageJsonHelper.setNewValue.mock.calls.length).toBe(1);
|
2017-06-29 05:29:41 +00:00
|
|
|
expect(yarn.getLockFile.mock.calls.length).toBe(1);
|
|
|
|
expect(npm.getLockFile.mock.calls.length).toBe(1);
|
2017-06-02 06:06:44 +00:00
|
|
|
expect(config.api.commitFilesToBranch.mock.calls.length).toBe(0);
|
|
|
|
});
|
2017-04-20 10:15:46 +00:00
|
|
|
it('maintains lock files if needing updates', async () => {
|
|
|
|
branchWorker.getParentBranch.mockReturnValueOnce('dummy branch');
|
2017-06-29 05:29:41 +00:00
|
|
|
yarn.maintainLockFile.mockReturnValueOnce('non null response');
|
2017-07-05 05:12:25 +00:00
|
|
|
config.upgrades[0].type = 'lockFileMaintenance';
|
2017-07-02 05:50:46 +00:00
|
|
|
await branchWorker.ensureBranch(config);
|
2017-04-20 10:15:46 +00:00
|
|
|
expect(branchWorker.getParentBranch.mock.calls.length).toBe(1);
|
|
|
|
expect(packageJsonHelper.setNewValue.mock.calls.length).toBe(0);
|
2017-06-29 05:29:41 +00:00
|
|
|
expect(yarn.getLockFile.mock.calls.length).toBe(0);
|
|
|
|
expect(npm.getLockFile.mock.calls.length).toBe(0);
|
|
|
|
expect(yarn.maintainLockFile.mock.calls.length).toBe(1);
|
2017-04-20 10:15:46 +00:00
|
|
|
expect(config.api.commitFilesToBranch.mock.calls[0][1].length).toBe(1);
|
|
|
|
});
|
|
|
|
it('skips maintaining lock files if no updates', async () => {
|
|
|
|
branchWorker.getParentBranch.mockReturnValueOnce('dummy branch');
|
2017-07-05 05:12:25 +00:00
|
|
|
config.upgrades[0].type = 'lockFileMaintenance';
|
2017-07-02 05:50:46 +00:00
|
|
|
await branchWorker.ensureBranch(config);
|
2017-04-20 10:15:46 +00:00
|
|
|
expect(branchWorker.getParentBranch.mock.calls.length).toBe(1);
|
|
|
|
expect(packageJsonHelper.setNewValue.mock.calls.length).toBe(0);
|
2017-06-29 05:29:41 +00:00
|
|
|
expect(yarn.getLockFile.mock.calls.length).toBe(0);
|
|
|
|
expect(npm.getLockFile.mock.calls.length).toBe(0);
|
|
|
|
expect(yarn.maintainLockFile.mock.calls.length).toBe(1);
|
2017-04-20 10:15:46 +00:00
|
|
|
expect(config.api.commitFilesToBranch.mock.calls.length).toBe(0);
|
|
|
|
});
|
2017-06-02 06:06:44 +00:00
|
|
|
it('throws error if cannot maintain yarn.lock file', async () => {
|
|
|
|
branchWorker.getParentBranch.mockReturnValueOnce('dummy branch');
|
2017-07-05 05:12:25 +00:00
|
|
|
config.upgrades[0].type = 'lockFileMaintenance';
|
2017-06-29 05:29:41 +00:00
|
|
|
yarn.maintainLockFile.mockImplementationOnce(() => {
|
2017-06-02 06:06:44 +00:00
|
|
|
throw new Error('yarn not found');
|
|
|
|
});
|
|
|
|
let err;
|
|
|
|
try {
|
2017-07-02 05:50:46 +00:00
|
|
|
await branchWorker.ensureBranch(config);
|
2017-06-02 06:06:44 +00:00
|
|
|
} catch (e) {
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
expect(err.message).toBe('Could not maintain yarn.lock file');
|
|
|
|
expect(branchWorker.getParentBranch.mock.calls.length).toBe(1);
|
|
|
|
expect(packageJsonHelper.setNewValue.mock.calls.length).toBe(0);
|
2017-06-29 05:29:41 +00:00
|
|
|
expect(yarn.getLockFile.mock.calls.length).toBe(0);
|
|
|
|
expect(npm.getLockFile.mock.calls.length).toBe(0);
|
|
|
|
expect(yarn.maintainLockFile.mock.calls.length).toBe(1);
|
2017-06-02 06:06:44 +00:00
|
|
|
expect(config.api.commitFilesToBranch.mock.calls.length).toBe(0);
|
|
|
|
});
|
2017-02-14 07:08:40 +00:00
|
|
|
});
|
2017-07-02 04:44:49 +00:00
|
|
|
describe('processBranchUpgrades(upgrades)', () => {
|
2017-06-22 07:03:36 +00:00
|
|
|
let config;
|
|
|
|
beforeEach(() => {
|
|
|
|
config = Object.assign({}, defaultConfig);
|
|
|
|
config.api = {
|
|
|
|
checkForClosedPr: jest.fn(),
|
|
|
|
};
|
2017-06-25 05:36:13 +00:00
|
|
|
config.logger = logger;
|
2017-06-22 19:35:32 +00:00
|
|
|
branchWorker.ensureBranch = jest.fn(() => true);
|
|
|
|
prWorker.ensurePr = jest.fn(() => true);
|
2017-06-22 07:03:36 +00:00
|
|
|
});
|
|
|
|
it('returns immediately if closed PR found', async () => {
|
|
|
|
config.api.checkForClosedPr.mockReturnValue(true);
|
2017-07-02 04:44:49 +00:00
|
|
|
await branchWorker.processBranchUpgrades([config]);
|
2017-06-22 07:03:36 +00:00
|
|
|
expect(branchWorker.ensureBranch.mock.calls.length).toBe(0);
|
|
|
|
});
|
|
|
|
it('does not return immediately if recreateClosed true', async () => {
|
|
|
|
config.api.checkForClosedPr.mockReturnValue(true);
|
|
|
|
config.recreateClosed = true;
|
2017-07-02 04:44:49 +00:00
|
|
|
await branchWorker.processBranchUpgrades([config]);
|
2017-06-22 07:03:36 +00:00
|
|
|
expect(branchWorker.ensureBranch.mock.calls.length).toBe(1);
|
|
|
|
});
|
|
|
|
it('pins', async () => {
|
2017-07-05 05:12:25 +00:00
|
|
|
config.type = 'pin';
|
2017-07-02 04:44:49 +00:00
|
|
|
await branchWorker.processBranchUpgrades([config]);
|
2017-06-22 07:03:36 +00:00
|
|
|
expect(branchWorker.ensureBranch.mock.calls.length).toBe(1);
|
|
|
|
});
|
|
|
|
it('majors', async () => {
|
2017-07-05 05:12:25 +00:00
|
|
|
config.type = 'major';
|
2017-07-02 04:44:49 +00:00
|
|
|
await branchWorker.processBranchUpgrades([config]);
|
2017-06-22 07:03:36 +00:00
|
|
|
expect(branchWorker.ensureBranch.mock.calls.length).toBe(1);
|
|
|
|
});
|
|
|
|
it('minors', async () => {
|
2017-07-05 05:12:25 +00:00
|
|
|
config.type = 'minor';
|
2017-07-02 04:44:49 +00:00
|
|
|
await branchWorker.processBranchUpgrades([config]);
|
2017-06-22 07:03:36 +00:00
|
|
|
expect(branchWorker.ensureBranch.mock.calls.length).toBe(1);
|
|
|
|
});
|
2017-06-29 17:50:26 +00:00
|
|
|
it('handles semantic commits', async () => {
|
2017-07-05 05:12:25 +00:00
|
|
|
config.type = 'minor';
|
2017-06-30 04:04:15 +00:00
|
|
|
config.semanticCommits = true;
|
2017-07-02 04:44:49 +00:00
|
|
|
await branchWorker.processBranchUpgrades([config]);
|
2017-06-29 17:50:26 +00:00
|
|
|
expect(branchWorker.ensureBranch.mock.calls.length).toBe(1);
|
|
|
|
});
|
2017-06-22 07:03:36 +00:00
|
|
|
it('handles errors', async () => {
|
|
|
|
config.api.checkForClosedPr = jest.fn(() => {
|
|
|
|
throw new Error('oops');
|
|
|
|
});
|
2017-07-02 04:44:49 +00:00
|
|
|
await branchWorker.processBranchUpgrades([config]);
|
2017-06-22 07:03:36 +00:00
|
|
|
expect(branchWorker.ensureBranch.mock.calls.length).toBe(0);
|
|
|
|
});
|
|
|
|
});
|
2017-07-02 05:50:46 +00:00
|
|
|
describe('generateConfig(branchUpgrades)', () => {
|
|
|
|
let config;
|
|
|
|
beforeEach(() => {
|
|
|
|
config = Object.assign({}, defaultConfig, { logger });
|
|
|
|
});
|
|
|
|
it('uses group settings', async () => {
|
|
|
|
config.groupName = 'some-group';
|
|
|
|
config.group.branchName = 'some-group-branchname';
|
|
|
|
const branchUpgrades = [config, config];
|
|
|
|
const res = await branchWorker.generateConfig(branchUpgrades);
|
|
|
|
expect(res.branchName).toEqual(config.group.branchName);
|
2017-06-25 05:36:13 +00:00
|
|
|
});
|
|
|
|
});
|
2017-02-14 07:08:40 +00:00
|
|
|
});
|