Skip to content

Commit

Permalink
test(workers): Refactor snapshot tests (#12542)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Nov 7, 2021
1 parent 84704c6 commit 6224af5
Show file tree
Hide file tree
Showing 27 changed files with 235 additions and 383 deletions.
Expand Up @@ -59,15 +59,3 @@ These updates are awaiting their schedule. Click on a checkbox to get an update
"
`;

exports[`workers/repository/dependency-dashboard readDashboardBody() reads dashboard body 1`] = `
Object {
"dependencyDashboardChecks": Object {
"branchName1": "approve",
},
"dependencyDashboardIssue": 1,
"dependencyDashboardRebaseAllOpen": true,
"dependencyDashboardTitle": "Dependency Dashboard",
"prCreation": "approval",
}
`;
3 changes: 0 additions & 3 deletions lib/workers/repository/__snapshots__/index.spec.ts.snap

This file was deleted.

11 changes: 9 additions & 2 deletions lib/workers/repository/dependency-dashboard.spec.ts
Expand Up @@ -53,8 +53,15 @@ describe('workers/repository/dependency-dashboard', () => {
'\n\n - [x] <!-- rebase-all-open-prs -->',
});
await dependencyDashboard.readDashboardBody(conf);
// FIXME: explicit assert condition
expect(conf).toMatchSnapshot();
expect(conf).toEqual({
dependencyDashboardChecks: {
branchName1: 'approve',
},
dependencyDashboardIssue: 1,
dependencyDashboardRebaseAllOpen: true,
dependencyDashboardTitle: 'Dependency Dashboard',
prCreation: 'approval',
});
});
});

Expand Down

This file was deleted.

Expand Up @@ -33,20 +33,3 @@ Array [
},
]
`;

exports[`workers/repository/extract/manager-files getManagerPackageFiles() returns files with extractPackageFile 1`] = `
Array [
Object {
"deps": Array [
Object {
"depIndex": 0,
},
Object {
"depIndex": 1,
"replaceString": "abc",
},
],
"packageFile": "Dockerfile",
},
]
`;
3 changes: 1 addition & 2 deletions lib/workers/repository/extract/index.spec.ts
Expand Up @@ -27,8 +27,7 @@ describe('workers/repository/extract/index', () => {
config.enabledManagers = ['npm'];
managerFiles.getManagerPackageFiles.mockResolvedValue([{} as never]);
const res = await extractAllDependencies(config);
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toEqual({ npm: [{}] });
});

it('warns if no packages found for a enabled manager', async () => {
Expand Down
24 changes: 20 additions & 4 deletions lib/workers/repository/extract/manager-files.spec.ts
Expand Up @@ -47,8 +47,12 @@ describe('workers/repository/extract/manager-files', () => {
deps: [{}, { replaceString: 'abc' }],
})) as never;
const res = await getManagerPackageFiles(managerConfig);
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toEqual([
{
packageFile: 'Dockerfile',
deps: [{ depIndex: 0 }, { depIndex: 1, replaceString: 'abc' }],
},
]);
});
it('returns files with extractAllPackageFiles', async () => {
const managerConfig = {
Expand All @@ -61,8 +65,20 @@ describe('workers/repository/extract/manager-files', () => {
'{"dependencies":{"chalk":"2.0.0"}}'
);
const res = await getManagerPackageFiles(managerConfig);
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
packageFile: 'package.json',
packageJsonType: 'app',
deps: [
{
currentValue: '2.0.0',
datasource: 'npm',
depName: 'chalk',
depType: 'dependencies',
},
],
},
]);
});
});
});
3 changes: 1 addition & 2 deletions lib/workers/repository/index.spec.ts
Expand Up @@ -23,8 +23,7 @@ describe('workers/repository/index', () => {
it('runs', async () => {
process.extractDependencies.mockResolvedValue(mock<ExtractResult>());
const res = await renovateRepository(config);
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toBeUndefined();
});
});
});
3 changes: 0 additions & 3 deletions lib/workers/repository/init/__snapshots__/index.spec.ts.snap

This file was deleted.

76 changes: 0 additions & 76 deletions lib/workers/repository/init/__snapshots__/merge.spec.ts.snap

This file was deleted.

3 changes: 1 addition & 2 deletions lib/workers/repository/init/index.spec.ts
Expand Up @@ -38,8 +38,7 @@ describe('workers/repository/init/index', () => {
merge.mergeRenovateConfig.mockResolvedValueOnce({});
secrets.applySecretsToConfig.mockReturnValueOnce({} as never);
const renovateConfig = await initRepo({});
// FIXME: explicit assert condition
expect(renovateConfig).toMatchSnapshot();
expect(renovateConfig).toEqual({});
});
it('warns on unsupported options', async () => {
apis.initApis.mockResolvedValue({} as never);
Expand Down
81 changes: 51 additions & 30 deletions lib/workers/repository/init/merge.spec.ts
Expand Up @@ -41,8 +41,7 @@ describe('workers/repository/init/merge', () => {
it('returns config if not found', async () => {
git.getFileList.mockResolvedValue(['package.json']);
fs.readLocalFile.mockResolvedValue('{}');
// FIXME: explicit assert condition
expect(await detectRepoFileConfig()).toMatchSnapshot();
expect(await detectRepoFileConfig()).toEqual({});
});
it('uses package.json config if found', async () => {
git.getFileList.mockResolvedValue(['package.json']);
Expand All @@ -54,9 +53,14 @@ describe('workers/repository/init/merge', () => {
});
fs.readLocalFile.mockResolvedValue(pJson);
platform.getJsonFile.mockResolvedValueOnce(pJson);
// FIXME: explicit assert condition
expect(await detectRepoFileConfig()).toMatchSnapshot();
expect(await detectRepoFileConfig()).toMatchSnapshot();
expect(await detectRepoFileConfig()).toEqual({
configFileName: 'package.json',
configFileParsed: { prHourlyLimit: 10 },
});
expect(await detectRepoFileConfig()).toEqual({
configFileName: 'package.json',
configFileParsed: undefined,
});
});
it('massages package.json renovate string', async () => {
git.getFileList.mockResolvedValue(['package.json']);
Expand All @@ -66,64 +70,82 @@ describe('workers/repository/init/merge', () => {
});
fs.readLocalFile.mockResolvedValue(pJson);
platform.getJsonFile.mockResolvedValueOnce(pJson);
expect(await detectRepoFileConfig()).toMatchInlineSnapshot(`
Object {
"configFileName": "package.json",
"configFileParsed": Object {
"extends": Array [
"github>renovatebot/renovate",
],
},
}
`);
expect(await detectRepoFileConfig()).toEqual({
configFileName: 'package.json',
configFileParsed: { extends: ['github>renovatebot/renovate'] },
});
});
it('returns error if cannot parse', async () => {
git.getFileList.mockResolvedValue(['package.json', 'renovate.json']);
fs.readLocalFile.mockResolvedValue('cannot parse');
// FIXME: explicit assert condition
expect(await detectRepoFileConfig()).toMatchSnapshot();
expect(await detectRepoFileConfig()).toEqual({
configFileName: 'renovate.json',
configFileParseError: {
validationError: 'Invalid JSON (parsing failed)',
validationMessage: 'Syntax error near cannot par',
},
});
});
it('throws error if duplicate keys', async () => {
git.getFileList.mockResolvedValue(['package.json', '.renovaterc']);
fs.readLocalFile.mockResolvedValue(
'{ "enabled": true, "enabled": false }'
);
// FIXME: explicit assert condition
expect(await detectRepoFileConfig()).toMatchSnapshot();
expect(await detectRepoFileConfig()).toEqual({
configFileName: '.renovaterc',
configFileParseError: {
validationError: 'Duplicate keys in JSON',
validationMessage:
'"Syntax error: duplicated keys \\"enabled\\" near \\": false }"',
},
});
});
it('finds and parse renovate.json5', async () => {
git.getFileList.mockResolvedValue(['package.json', 'renovate.json5']);
fs.readLocalFile.mockResolvedValue(`{
// this is json5 format
}`);
// FIXME: explicit assert condition
expect(await detectRepoFileConfig()).toMatchSnapshot();
expect(await detectRepoFileConfig()).toEqual({
configFileName: 'renovate.json5',
configFileParsed: {},
});
});
it('finds .github/renovate.json', async () => {
git.getFileList.mockResolvedValue([
'package.json',
'.github/renovate.json',
]);
fs.readLocalFile.mockResolvedValue('{}');
// FIXME: explicit assert condition
expect(await detectRepoFileConfig()).toMatchSnapshot();
expect(await detectRepoFileConfig()).toEqual({
configFileName: '.github/renovate.json',
configFileParsed: {},
});
});
it('finds .gitlab/renovate.json', async () => {
git.getFileList.mockResolvedValue([
'package.json',
'.gitlab/renovate.json',
]);
fs.readLocalFile.mockResolvedValue('{}');
// FIXME: explicit assert condition
expect(await detectRepoFileConfig()).toMatchSnapshot();
expect(await detectRepoFileConfig()).toEqual({
configFileName: '.gitlab/renovate.json',
configFileParsed: {},
});
});
it('finds .renovaterc.json', async () => {
git.getFileList.mockResolvedValue(['package.json', '.renovaterc.json']);
fs.readLocalFile.mockResolvedValue('{}');
platform.getJsonFile.mockResolvedValueOnce('{"something":"new"}');
// FIXME: explicit assert condition
expect(await detectRepoFileConfig()).toMatchSnapshot();
expect(await detectRepoFileConfig()).toMatchSnapshot();
expect(await detectRepoFileConfig()).toEqual({
configFileName: '.renovaterc.json',
configFileParsed: {},
});
expect(await detectRepoFileConfig()).toMatchInlineSnapshot(`
Object {
"configFileName": ".renovaterc.json",
"configFileParsed": "{\\"something\\":\\"new\\"}",
}
`);
});
});
describe('checkForRepoConfigError', () => {
Expand Down Expand Up @@ -158,8 +180,7 @@ describe('workers/repository/init/merge', () => {
e = err;
}
expect(e).toBeDefined();
// FIXME: explicit assert condition
expect(e).toMatchSnapshot();
expect(e.toString()).toEqual('Error: config-validation');
});
it('migrates nested config', async () => {
git.getFileList.mockResolvedValue(['renovate.json']);
Expand Down
12 changes: 10 additions & 2 deletions lib/workers/repository/init/vulnerability.spec.ts
Expand Up @@ -289,8 +289,16 @@ describe('workers/repository/init/vulnerability', () => {
const res = await detectVulnerabilityAlerts(config);
expect(res.packageRules).toMatchSnapshot();
expect(res.packageRules).toHaveLength(3);
// FIXME: explicit assert condition
expect(res.remediations).toMatchSnapshot();
expect(res.remediations).toMatchSnapshot({
'backend/package-lock.json': [
{
currentVersion: '1.8.2',
datasource: 'npm',
depName: 'electron',
newVersion: '1.8.3',
},
],
});
});
});
});

This file was deleted.

0 comments on commit 6224af5

Please sign in to comment.