2020-07-04 12:28:49 +00:00
|
|
|
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';
|
2020-05-07 08:23:45 +00:00
|
|
|
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);
|
2018-05-09 06:03:59 +00:00
|
|
|
|
2020-03-05 20:57:24 +00:00
|
|
|
jest.mock('../../manager/composer');
|
|
|
|
jest.mock('../../manager/npm');
|
|
|
|
jest.mock('../../manager/git-submodules');
|
2020-07-04 12:28:49 +00:00
|
|
|
jest.mock('../../util/git');
|
2020-03-05 20:57:24 +00:00
|
|
|
jest.mock('./auto-replace');
|
2019-07-25 06:17:19 +00:00
|
|
|
|
2018-05-09 06:03:59 +00:00
|
|
|
describe('workers/branch/get-updated', () => {
|
|
|
|
describe('getUpdatedPackageFiles()', () => {
|
2020-05-07 08:23:45 +00:00
|
|
|
let config: BranchConfig;
|
2018-05-09 06:03:59 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
config = {
|
|
|
|
...defaultConfig,
|
|
|
|
upgrades: [],
|
2020-05-07 08:23:45 +00:00
|
|
|
} as never;
|
2018-05-09 06:03:59 +00:00
|
|
|
npm.updateDependency = jest.fn();
|
2020-07-04 12:28:49 +00:00
|
|
|
git.getFile.mockResolvedValueOnce('existing content');
|
2018-05-09 06:03:59 +00:00
|
|
|
});
|
2020-02-22 05:06:10 +00:00
|
|
|
it('handles autoreplace base updated', async () => {
|
2020-05-07 08:23:45 +00:00
|
|
|
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 () => {
|
2020-05-07 08:23:45 +00:00
|
|
|
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 () => {
|
2020-05-07 08:23:45 +00:00
|
|
|
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 () => {
|
2020-05-15 10:45:03 +00:00
|
|
|
config.reuseExistingBranch = true;
|
2020-05-07 08:23:45 +00:00
|
|
|
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();
|
|
|
|
});
|
2018-05-09 06:03:59 +00:00
|
|
|
it('handles empty', async () => {
|
|
|
|
const res = await getUpdatedPackageFiles(config);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('handles null content', async () => {
|
2020-05-15 10:45:03 +00:00
|
|
|
config.reuseExistingBranch = true;
|
2018-05-09 06:03:59 +00:00
|
|
|
config.upgrades.push({
|
2020-02-04 09:37:24 +00:00
|
|
|
manager: 'npm',
|
2020-05-07 08:23:45 +00:00
|
|
|
} as never);
|
2019-04-19 20:04:37 +00:00
|
|
|
await expect(getUpdatedPackageFiles(config)).rejects.toThrow();
|
2018-05-09 06:03:59 +00:00
|
|
|
});
|
|
|
|
it('handles content change', async () => {
|
2020-05-15 10:45:03 +00:00
|
|
|
config.reuseExistingBranch = true;
|
2018-05-09 06:03:59 +00:00
|
|
|
config.upgrades.push({
|
2020-02-04 09:37:24 +00:00
|
|
|
manager: 'npm',
|
2020-05-07 08:23:45 +00:00
|
|
|
} as never);
|
2018-05-09 06:03:59 +00:00
|
|
|
npm.updateDependency.mockReturnValue('some new content');
|
|
|
|
const res = await getUpdatedPackageFiles(config);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
2018-07-19 07:14:34 +00:00
|
|
|
it('handles lock files', async () => {
|
2020-05-15 10:45:03 +00:00
|
|
|
config.reuseExistingBranch = true;
|
2018-07-19 07:14:34 +00:00
|
|
|
config.upgrades.push({
|
2020-02-04 09:37:24 +00:00
|
|
|
manager: 'composer',
|
2020-05-07 08:23:45 +00:00
|
|
|
branchName: undefined,
|
2018-07-19 07:14:34 +00:00
|
|
|
});
|
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([
|
2019-02-08 13:50:06 +00:00
|
|
|
{
|
|
|
|
file: {
|
|
|
|
name: 'composer.json',
|
|
|
|
contents: 'some contents',
|
|
|
|
},
|
2018-10-01 14:29:50 +00:00
|
|
|
},
|
2019-02-08 13:50:06 +00:00
|
|
|
]);
|
2018-07-19 07:14:34 +00:00
|
|
|
const res = await getUpdatedPackageFiles(config);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
2019-06-11 13:06:29 +00:00
|
|
|
it('handles lockFileMaintenance', async () => {
|
|
|
|
config.upgrades.push({
|
2020-02-04 09:37:24 +00:00
|
|
|
manager: 'composer',
|
2019-06-11 13:06:29 +00:00
|
|
|
updateType: 'lockFileMaintenance',
|
2020-05-07 08:23:45 +00:00
|
|
|
} as never);
|
2019-12-09 11:42:55 +00:00
|
|
|
composer.updateArtifacts.mockResolvedValueOnce([
|
2019-06-11 13:06:29 +00:00
|
|
|
{
|
|
|
|
file: {
|
|
|
|
name: 'composer.json',
|
|
|
|
contents: 'some contents',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
const res = await getUpdatedPackageFiles(config);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('handles lockFileMaintenance error', async () => {
|
|
|
|
config.upgrades.push({
|
2020-02-04 09:37:24 +00:00
|
|
|
manager: 'composer',
|
2019-06-11 13:06:29 +00:00
|
|
|
updateType: 'lockFileMaintenance',
|
2020-05-07 08:23:45 +00:00
|
|
|
} as never);
|
2019-12-09 11:42:55 +00:00
|
|
|
composer.updateArtifacts.mockResolvedValueOnce([
|
2019-06-11 13:06:29 +00:00
|
|
|
{
|
|
|
|
artifactError: {
|
2019-12-09 11:42:55 +00:00
|
|
|
lockFile: 'composer.lock',
|
2019-06-11 13:06:29 +00:00
|
|
|
stderr: 'some error',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
const res = await getUpdatedPackageFiles(config);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
2018-10-01 16:15:06 +00:00
|
|
|
it('handles lock file errors', async () => {
|
2020-05-15 10:45:03 +00:00
|
|
|
config.reuseExistingBranch = true;
|
2018-10-01 16:15:06 +00:00
|
|
|
config.upgrades.push({
|
2020-02-04 09:37:24 +00:00
|
|
|
manager: 'composer',
|
2020-05-07 08:23:45 +00:00
|
|
|
branchName: undefined,
|
2018-10-01 16:15:06 +00:00
|
|
|
});
|
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([
|
2019-02-08 13:50:06 +00:00
|
|
|
{
|
|
|
|
artifactError: {
|
2019-12-09 11:42:55 +00:00
|
|
|
lockFile: 'composer.lock',
|
2019-02-08 13:50:06 +00:00
|
|
|
stderr: 'some error',
|
|
|
|
},
|
2018-10-01 16:15:06 +00:00
|
|
|
},
|
2019-02-08 13:50:06 +00:00
|
|
|
]);
|
2018-10-01 16:15:06 +00:00
|
|
|
const res = await getUpdatedPackageFiles(config);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
2019-11-28 19:04:54 +00:00
|
|
|
it('handles git submodules', async () => {
|
|
|
|
config.upgrades.push({
|
2020-02-04 09:37:24 +00:00
|
|
|
manager: 'git-submodules',
|
2020-03-01 07:01:12 +00:00
|
|
|
datasource: datasourceGitSubmodules.id,
|
2020-05-07 08:23:45 +00:00
|
|
|
} as never);
|
2019-12-09 11:42:55 +00:00
|
|
|
gitSubmodules.updateDependency.mockResolvedValueOnce('existing content');
|
2019-11-28 19:04:54 +00:00
|
|
|
const res = await getUpdatedPackageFiles(config);
|
|
|
|
expect(res).toMatchSnapshot();
|
|
|
|
});
|
2018-05-09 06:03:59 +00:00
|
|
|
});
|
|
|
|
});
|