renovate/lib/workers/branch/get-updated.spec.ts

156 lines
5.4 KiB
TypeScript
Raw Normal View History

import { defaultConfig, git, mocked } from '../../../test/util';
2020-05-01 16:03:48 +00:00
import * as datasourceGitSubmodules from '../../datasource/git-submodules';
2020-03-05 20:57:24 +00:00
import * as _composer from '../../manager/composer';
import * as _gitSubmodules from '../../manager/git-submodules';
2020-05-01 16:03:48 +00:00
import * as _npm from '../../manager/npm';
import { BranchConfig } from '../common';
2020-03-05 20:57:24 +00:00
import * as _autoReplace from './auto-replace';
import { getUpdatedPackageFiles } from './get-updated';
2019-12-09 11:42:55 +00:00
const composer = mocked(_composer);
const gitSubmodules = mocked(_gitSubmodules);
const npm = mocked(_npm);
2020-02-22 05:06:10 +00:00
const autoReplace = mocked(_autoReplace);
2020-03-05 20:57:24 +00:00
jest.mock('../../manager/composer');
jest.mock('../../manager/npm');
jest.mock('../../manager/git-submodules');
jest.mock('../../util/git');
2020-03-05 20:57:24 +00:00
jest.mock('./auto-replace');
describe('workers/branch/get-updated', () => {
describe('getUpdatedPackageFiles()', () => {
let config: BranchConfig;
beforeEach(() => {
config = {
...defaultConfig,
upgrades: [],
} as never;
npm.updateDependency = jest.fn();
git.getFile.mockResolvedValueOnce('existing content');
});
2020-02-22 05:06:10 +00:00
it('handles autoreplace base updated', async () => {
config.upgrades.push({ manager: 'html', branchName: undefined });
2020-02-22 05:06:10 +00:00
autoReplace.doAutoReplace.mockResolvedValueOnce('updated-file');
const res = await getUpdatedPackageFiles(config);
expect(res).toMatchSnapshot();
});
it('handles autoreplace branch no update', async () => {
config.upgrades.push({ manager: 'html', branchName: undefined });
2020-02-22 05:06:10 +00:00
autoReplace.doAutoReplace.mockResolvedValueOnce('existing content');
const res = await getUpdatedPackageFiles(config);
expect(res).toMatchSnapshot();
});
it('handles autoreplace failure', async () => {
config.upgrades.push({ manager: 'html', branchName: undefined });
2020-02-22 05:06:10 +00:00
autoReplace.doAutoReplace.mockResolvedValueOnce(null);
await expect(getUpdatedPackageFiles(config)).rejects.toThrow();
});
it('handles autoreplace branch needs update', async () => {
config.reuseExistingBranch = true;
config.upgrades.push({ manager: 'html', branchName: undefined });
2020-02-22 05:06:10 +00:00
autoReplace.doAutoReplace.mockResolvedValueOnce(null);
autoReplace.doAutoReplace.mockResolvedValueOnce('updated-file');
const res = await getUpdatedPackageFiles(config);
expect(res).toMatchSnapshot();
});
it('handles empty', async () => {
const res = await getUpdatedPackageFiles(config);
expect(res).toMatchSnapshot();
});
it('handles null content', async () => {
config.reuseExistingBranch = true;
config.upgrades.push({
manager: 'npm',
} as never);
await expect(getUpdatedPackageFiles(config)).rejects.toThrow();
});
it('handles content change', async () => {
config.reuseExistingBranch = true;
config.upgrades.push({
manager: 'npm',
} as never);
npm.updateDependency.mockReturnValue('some new content');
const res = await getUpdatedPackageFiles(config);
expect(res).toMatchSnapshot();
});
it('handles lock files', async () => {
config.reuseExistingBranch = true;
config.upgrades.push({
manager: 'composer',
branchName: undefined,
});
2020-04-08 14:04:43 +00:00
autoReplace.doAutoReplace.mockResolvedValueOnce('some new content');
2019-12-09 11:42:55 +00:00
composer.updateArtifacts.mockResolvedValueOnce([
{
file: {
name: 'composer.json',
contents: 'some contents',
},
},
]);
const res = await getUpdatedPackageFiles(config);
expect(res).toMatchSnapshot();
});
it('handles lockFileMaintenance', async () => {
config.upgrades.push({
manager: 'composer',
updateType: 'lockFileMaintenance',
} as never);
2019-12-09 11:42:55 +00:00
composer.updateArtifacts.mockResolvedValueOnce([
{
file: {
name: 'composer.json',
contents: 'some contents',
},
},
]);
const res = await getUpdatedPackageFiles(config);
expect(res).toMatchSnapshot();
});
it('handles lockFileMaintenance error', async () => {
config.upgrades.push({
manager: 'composer',
updateType: 'lockFileMaintenance',
} as never);
2019-12-09 11:42:55 +00:00
composer.updateArtifacts.mockResolvedValueOnce([
{
artifactError: {
2019-12-09 11:42:55 +00:00
lockFile: 'composer.lock',
stderr: 'some error',
},
},
]);
const res = await getUpdatedPackageFiles(config);
expect(res).toMatchSnapshot();
});
it('handles lock file errors', async () => {
config.reuseExistingBranch = true;
config.upgrades.push({
manager: 'composer',
branchName: undefined,
});
2020-04-08 14:04:43 +00:00
autoReplace.doAutoReplace.mockResolvedValueOnce('some new content');
2019-12-09 11:42:55 +00:00
composer.updateArtifacts.mockResolvedValueOnce([
{
artifactError: {
2019-12-09 11:42:55 +00:00
lockFile: 'composer.lock',
stderr: 'some error',
},
},
]);
const res = await getUpdatedPackageFiles(config);
expect(res).toMatchSnapshot();
});
it('handles git submodules', async () => {
config.upgrades.push({
manager: 'git-submodules',
datasource: datasourceGitSubmodules.id,
} as never);
2019-12-09 11:42:55 +00:00
gitSubmodules.updateDependency.mockResolvedValueOnce('existing content');
const res = await getUpdatedPackageFiles(config);
expect(res).toMatchSnapshot();
});
});
});