test: Refactor more snapshot test (#11313)

This commit is contained in:
Sergei Zharinov 2021-08-18 09:49:27 +03:00 committed by GitHub
parent 5f4b9f9a3a
commit b21439fb75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 331 additions and 270 deletions

View file

@ -276,7 +276,6 @@ describe('manager/composer/artifacts', () => {
fs.writeLocalFile.mockImplementationOnce(() => {
throw new Error('not found');
});
// FIXME: explicit assert condition
expect(
await composer.updateArtifacts({
packageFileName: 'composer.json',
@ -284,17 +283,16 @@ describe('manager/composer/artifacts', () => {
newPackageFileContent: '{}',
config,
})
).toMatchSnapshot();
).toMatchSnapshot([{ artifactError: { lockFile: 'composer.lock' } }]);
});
it('catches unmet requirements errors', async () => {
const stderr =
'fooYour requirements could not be resolved to an installable set of packages.bar';
fs.readLocalFile.mockResolvedValueOnce('{}');
fs.writeLocalFile.mockImplementationOnce(() => {
throw new Error(
'fooYour requirements could not be resolved to an installable set of packages.bar'
);
throw new Error(stderr);
});
// FIXME: explicit assert condition
expect(
await composer.updateArtifacts({
packageFileName: 'composer.json',
@ -302,7 +300,9 @@ describe('manager/composer/artifacts', () => {
newPackageFileContent: '{}',
config,
})
).toMatchSnapshot();
).toMatchSnapshot([
{ artifactError: { lockFile: 'composer.lock', stderr } },
]);
});
it('throws for disk space', async () => {

View file

@ -24,8 +24,8 @@ describe('manager/composer/extract', () => {
});
it('extracts dependencies with no lock file', async () => {
const res = await extractPackageFile(requirements1, packageFile);
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res.deps).toHaveLength(32);
});
it('extracts registryUrls', async () => {
const res = await extractPackageFile(requirements2, packageFile);
@ -51,8 +51,8 @@ describe('manager/composer/extract', () => {
it('extracts dependencies with lock file', async () => {
fs.readLocalFile.mockResolvedValue('some content');
const res = await extractPackageFile(requirements1, packageFile);
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res.deps).toHaveLength(32);
});
});
});

View file

@ -1,8 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`manager/deps-edn/extract extractPackageFile 1`] = `
Object {
"deps": Array [
Array [
Object {
"currentValue": "0.1.2",
"datasource": "clojure",
@ -75,6 +74,5 @@ Object {
"depName": "com.datomic:datomic-free",
"registryUrls": Array [],
},
],
}
]
`;

View file

@ -5,7 +5,56 @@ const depsEdn = loadFixture('deps.edn');
describe('manager/deps-edn/extract', () => {
it('extractPackageFile', () => {
// FIXME: explicit assert condition
expect(extractPackageFile(depsEdn)).toMatchSnapshot();
const { deps } = extractPackageFile(depsEdn);
expect(deps).toMatchSnapshot([
{
depName: 'persistent-sorted-set:persistent-sorted-set',
currentValue: '0.1.2',
},
{
depName: 'org.clojure:clojure',
currentValue: '1.9.0',
},
{
depName: 'org.clojure:clojure',
currentValue: '1.10.0',
},
{
depName: 'org.clojure:clojurescript',
currentValue: '1.10.520',
},
{
depName: 'org.clojure:tools.namespace',
currentValue: '0.2.11',
},
{
depName: 'org.clojure:clojurescript',
currentValue: '1.10.520',
},
{
depName: 'lambdaisland:kaocha',
currentValue: '0.0-389',
},
{
depName: 'lambdaisland:kaocha-cljs',
currentValue: '0.0-21',
},
{
depName: 'cider:cider-nrepl',
currentValue: '0.21.1',
},
{
depName: 'nrepl:nrepl',
currentValue: '0.6.0',
},
{
depName: 'org.clojure:tools.namespace',
currentValue: '0.2.11',
},
{
depName: 'com.datomic:datomic-free',
currentValue: '0.9.5703',
},
]);
});
});

View file

@ -457,9 +457,3 @@ Array [
},
]
`;
exports[`manager/dockerfile/extract getDep() rejects null 1`] = `
Object {
"skipReason": "invalid-value",
}
`;

View file

@ -12,58 +12,113 @@ describe('manager/dockerfile/extract', () => {
});
it('handles naked dep', () => {
const res = extractPackageFile('FROM node\n').deps;
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
autoReplaceStringTemplate:
'{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
currentDigest: undefined,
currentValue: undefined,
datasource: 'docker',
depName: 'node',
depType: 'final',
replaceString: 'node',
},
]);
});
it('is case insensitive', () => {
const res = extractPackageFile('From node\n').deps;
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
currentDigest: undefined,
currentValue: undefined,
depName: 'node',
},
]);
});
it('handles tag', () => {
const res = extractPackageFile('FROM node:8.9.0-alpine\n').deps;
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
currentValue: '8.9.0-alpine',
depName: 'node',
replaceString: 'node:8.9.0-alpine',
},
]);
});
it('handles digest', () => {
const res = extractPackageFile(
'FROM node@sha256:eb85fc5b1198f5e1ec025ea07586bdbbf397e7d82df66c90d7511f533517e063\n'
).deps;
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
currentDigest:
'sha256:eb85fc5b1198f5e1ec025ea07586bdbbf397e7d82df66c90d7511f533517e063',
depName: 'node',
replaceString:
'node@sha256:eb85fc5b1198f5e1ec025ea07586bdbbf397e7d82df66c90d7511f533517e063',
},
]);
});
it('handles tag and digest', () => {
const res = extractPackageFile(
'FROM node:8.9.0@sha256:eb85fc5b1198f5e1ec025ea07586bdbbf397e7d82df66c90d7511f533517e063\n'
).deps;
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
currentDigest:
'sha256:eb85fc5b1198f5e1ec025ea07586bdbbf397e7d82df66c90d7511f533517e063',
currentValue: '8.9.0',
depName: 'node',
replaceString:
'node:8.9.0@sha256:eb85fc5b1198f5e1ec025ea07586bdbbf397e7d82df66c90d7511f533517e063',
},
]);
});
it('handles from as', () => {
const res = extractPackageFile('FROM node:8.9.0-alpine as base\n').deps;
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
currentValue: '8.9.0-alpine',
depName: 'node',
replaceString: 'node:8.9.0-alpine',
},
]);
});
it('handles comments', () => {
const res = extractPackageFile(
'# some comment\n# another\n\nFROM node\n'
).deps;
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
currentDigest: undefined,
currentValue: undefined,
depName: 'node',
},
]);
});
it('handles custom hosts', () => {
const res = extractPackageFile(
'FROM registry2.something.info/node:8\n'
).deps;
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
currentValue: '8',
depName: 'registry2.something.info/node',
replaceString: 'registry2.something.info/node:8',
},
]);
});
it('handles custom hosts and suffix', () => {
const res = extractPackageFile(
'FROM registry2.something.info/node:8-alpine\n'
).deps;
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
currentValue: '8-alpine',
depName: 'registry2.something.info/node',
replaceString: 'registry2.something.info/node:8-alpine',
},
]);
});
it('handles custom hosts with port', () => {
const res = extractPackageFile(
@ -91,22 +146,38 @@ describe('manager/dockerfile/extract', () => {
});
it('handles namespaced images', () => {
const res = extractPackageFile('FROM mynamespace/node:8\n').deps;
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
currentValue: '8',
depName: 'mynamespace/node',
replaceString: 'mynamespace/node:8',
},
]);
});
it('handles custom hosts with namespace', () => {
const res = extractPackageFile(
'FROM registry2.something.info/someaccount/node:8\n'
).deps;
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
currentValue: '8',
datasource: 'docker',
depName: 'registry2.something.info/someaccount/node',
replaceString: 'registry2.something.info/someaccount/node:8',
},
]);
});
it('handles abnormal spacing', () => {
const res = extractPackageFile(
'FROM registry.allmine.info:5005/node:8.7.0\n\n'
).deps;
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
currentValue: '8.7.0',
depName: 'registry.allmine.info:5005/node',
replaceString: 'registry.allmine.info:5005/node:8.7.0',
},
]);
});
it('extracts multiple FROM tags', () => {
const res = extractPackageFile(
@ -130,8 +201,13 @@ describe('manager/dockerfile/extract', () => {
const res = extractPackageFile(
'FROM scratch\nCOPY --from=gcr.io/k8s-skaffold/skaffold:v0.11.0 /usr/bin/skaffold /usr/bin/skaffold\n'
).deps;
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
currentValue: 'v0.11.0',
depName: 'gcr.io/k8s-skaffold/skaffold',
replaceString: 'gcr.io/k8s-skaffold/skaffold:v0.11.0',
},
]);
});
it('skips named multistage COPY --from tags', () => {
const res = extractPackageFile(
@ -171,19 +247,28 @@ describe('manager/dockerfile/extract', () => {
});
it('handles calico/node', () => {
const res = extractPackageFile('FROM calico/node\n').deps;
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
datasource: 'docker',
depName: 'calico/node',
replaceString: 'calico/node',
},
]);
});
it('handles ubuntu', () => {
const res = extractPackageFile('FROM ubuntu:18.04\n').deps;
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
expect(res).toMatchSnapshot([
{
currentValue: '18.04',
depName: 'ubuntu',
versioning: 'ubuntu',
},
]);
});
});
describe('getDep()', () => {
it('rejects null', () => {
// FIXME: explicit assert condition
expect(getDep(null)).toMatchSnapshot();
expect(getDep(null)).toEqual({ skipReason: 'invalid-value' });
});
});
});

View file

@ -3,7 +3,6 @@ import updateArtifacts from './artifacts';
describe('manager/git-submodules/artifact', () => {
describe('updateArtifacts()', () => {
it('returns empty content', () => {
// FIXME: explicit assert condition
expect(
updateArtifacts({
packageFileName: '',
@ -11,10 +10,9 @@ describe('manager/git-submodules/artifact', () => {
newPackageFileContent: '',
config: {},
})
).toMatchSnapshot();
).toMatchSnapshot([{ file: { contents: '', name: '' } }]);
});
it('returns two modules', () => {
// FIXME: explicit assert condition
expect(
updateArtifacts({
packageFileName: '',
@ -22,7 +20,10 @@ describe('manager/git-submodules/artifact', () => {
newPackageFileContent: '',
config: {},
})
).toMatchSnapshot();
).toMatchSnapshot([
{ file: { name: 'renovate' } },
{ file: { name: 'renovate-pro' } },
]);
});
});
});

View file

@ -1,17 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`manager/gomod/artifacts catches errors 1`] = `
Array [
Object {
"artifactError": Object {
"lockFile": "go.sum",
"stderr": "This update totally doesnt work",
},
},
]
`;
exports[`manager/gomod/artifacts catches errors 2`] = `Array []`;
exports[`manager/gomod/artifacts catches errors 1`] = `Array []`;
exports[`manager/gomod/artifacts returns if no go.sum found 1`] = `Array []`;
@ -76,23 +65,6 @@ Array [
`;
exports[`manager/gomod/artifacts skips updating import paths for gopkg.in dependencies 1`] = `
Array [
Object {
"file": Object {
"contents": "New go.sum",
"name": "go.sum",
},
},
Object {
"file": Object {
"contents": "New go.mod",
"name": "go.mod",
},
},
]
`;
exports[`manager/gomod/artifacts skips updating import paths for gopkg.in dependencies 2`] = `
Array [
Object {
"cmd": "go get -d ./...",
@ -173,23 +145,6 @@ Array [
`;
exports[`manager/gomod/artifacts skips updating import paths with gomodUpdateImportPaths on v0 to v1 1`] = `
Array [
Object {
"file": Object {
"contents": "New go.sum",
"name": "go.sum",
},
},
Object {
"file": Object {
"contents": "New go.mod",
"name": "go.mod",
},
},
]
`;
exports[`manager/gomod/artifacts skips updating import paths with gomodUpdateImportPaths on v0 to v1 2`] = `
Array [
Object {
"cmd": "go get -d ./...",
@ -556,29 +511,6 @@ Array [
`;
exports[`manager/gomod/artifacts updates import paths with gomodUpdateImportPaths 1`] = `
Array [
Object {
"file": Object {
"contents": "New go.sum",
"name": "go.sum",
},
},
Object {
"file": Object {
"contents": "New main.go",
"name": "main.go",
},
},
Object {
"file": Object {
"contents": "New go.mod",
"name": "go.mod",
},
},
]
`;
exports[`manager/gomod/artifacts updates import paths with gomodUpdateImportPaths 2`] = `
Array [
Object {
"cmd": "go get -d ./...",
@ -709,29 +641,6 @@ Array [
`;
exports[`manager/gomod/artifacts updates import paths with latest tool version on invalid version constraint 1`] = `
Array [
Object {
"file": Object {
"contents": "New go.sum",
"name": "go.sum",
},
},
Object {
"file": Object {
"contents": "New main.go",
"name": "main.go",
},
},
Object {
"file": Object {
"contents": "New go.mod",
"name": "go.mod",
},
},
]
`;
exports[`manager/gomod/artifacts updates import paths with latest tool version on invalid version constraint 2`] = `
Array [
Object {
"cmd": "go get -d ./...",
@ -862,29 +771,6 @@ Array [
`;
exports[`manager/gomod/artifacts updates import paths with specific tool version from constraint 1`] = `
Array [
Object {
"file": Object {
"contents": "New go.sum",
"name": "go.sum",
},
},
Object {
"file": Object {
"contents": "New main.go",
"name": "main.go",
},
},
Object {
"file": Object {
"contents": "New go.mod",
"name": "go.mod",
},
},
]
`;
exports[`manager/gomod/artifacts updates import paths with specific tool version from constraint 2`] = `
Array [
Object {
"cmd": "go get -d ./...",

View file

@ -243,7 +243,6 @@ describe('manager/gomod/artifacts', () => {
fs.outputFile.mockImplementationOnce(() => {
throw new Error('This update totally doesnt work');
});
// FIXME: explicit assert condition
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -251,7 +250,14 @@ describe('manager/gomod/artifacts', () => {
newPackageFileContent: gomod1,
config,
})
).toMatchSnapshot();
).toEqual([
{
artifactError: {
lockFile: 'go.sum',
stderr: 'This update totally doesnt work',
},
},
]);
expect(execSnapshots).toMatchSnapshot();
});
it('updates import paths with gomodUpdateImportPaths', async () => {
@ -265,7 +271,6 @@ describe('manager/gomod/artifacts', () => {
.mockResolvedValueOnce('New go.sum' as any)
.mockResolvedValueOnce('New main.go' as any)
.mockResolvedValueOnce('New go.mod' as any);
// FIXME: explicit assert condition
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -278,7 +283,11 @@ describe('manager/gomod/artifacts', () => {
postUpdateOptions: ['gomodUpdateImportPaths'],
},
})
).toMatchSnapshot();
).toEqual([
{ file: { contents: 'New go.sum', name: 'go.sum' } },
{ file: { contents: 'New main.go', name: 'main.go' } },
{ file: { contents: 'New go.mod', name: 'go.mod' } },
]);
expect(execSnapshots).toMatchSnapshot();
});
it('skips updating import paths with gomodUpdateImportPaths on v0 to v1', async () => {
@ -291,7 +300,6 @@ describe('manager/gomod/artifacts', () => {
fs.readFile
.mockResolvedValueOnce('New go.sum' as any)
.mockResolvedValueOnce('New go.mod' as any);
// FIXME: explicit assert condition
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -304,7 +312,10 @@ describe('manager/gomod/artifacts', () => {
postUpdateOptions: ['gomodUpdateImportPaths'],
},
})
).toMatchSnapshot();
).toEqual([
{ file: { contents: 'New go.sum', name: 'go.sum' } },
{ file: { contents: 'New go.mod', name: 'go.mod' } },
]);
expect(execSnapshots).toMatchSnapshot();
});
it('updates import paths with specific tool version from constraint', async () => {
@ -318,7 +329,6 @@ describe('manager/gomod/artifacts', () => {
.mockResolvedValueOnce('New go.sum' as any)
.mockResolvedValueOnce('New main.go' as any)
.mockResolvedValueOnce('New go.mod' as any);
// FIXME: explicit assert condition
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -334,7 +344,11 @@ describe('manager/gomod/artifacts', () => {
},
},
})
).toMatchSnapshot();
).toEqual([
{ file: { contents: 'New go.sum', name: 'go.sum' } },
{ file: { contents: 'New main.go', name: 'main.go' } },
{ file: { contents: 'New go.mod', name: 'go.mod' } },
]);
expect(execSnapshots).toMatchSnapshot();
});
it('updates import paths with latest tool version on invalid version constraint', async () => {
@ -348,7 +362,6 @@ describe('manager/gomod/artifacts', () => {
.mockResolvedValueOnce('New go.sum' as any)
.mockResolvedValueOnce('New main.go' as any)
.mockResolvedValueOnce('New go.mod' as any);
// FIXME: explicit assert condition
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -364,7 +377,11 @@ describe('manager/gomod/artifacts', () => {
},
},
})
).toMatchSnapshot();
).toEqual([
{ file: { contents: 'New go.sum', name: 'go.sum' } },
{ file: { contents: 'New main.go', name: 'main.go' } },
{ file: { contents: 'New go.mod', name: 'go.mod' } },
]);
expect(execSnapshots).toMatchSnapshot();
});
it('skips updating import paths for gopkg.in dependencies', async () => {
@ -377,7 +394,6 @@ describe('manager/gomod/artifacts', () => {
fs.readFile
.mockResolvedValueOnce('New go.sum' as any)
.mockResolvedValueOnce('New go.mod' as any);
// FIXME: explicit assert condition
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
@ -390,7 +406,10 @@ describe('manager/gomod/artifacts', () => {
postUpdateOptions: ['gomodUpdateImportPaths'],
},
})
).toMatchSnapshot();
).toEqual([
{ file: { contents: 'New go.sum', name: 'go.sum' } },
{ file: { contents: 'New go.mod', name: 'go.mod' } },
]);
expect(execSnapshots).toMatchSnapshot();
});
});

View file

@ -62,9 +62,13 @@ describe('manager/helm-requirements/extract', () => {
stable: 'https://charts.helm.sh/stable/',
},
});
// FIXME: explicit assert condition
expect(result).not.toBeNull();
expect(result).toMatchSnapshot();
expect(result).toMatchSnapshot({
datasource: 'helm',
deps: [
{ currentValue: '0.9.0', depName: 'redis' },
{ currentValue: '0.8.1', depName: 'postgresql' },
],
});
});
it('parses simple requirements.yaml but skips if necessary fields missing', () => {
fs.readLocalFile.mockResolvedValueOnce(`
@ -132,9 +136,12 @@ describe('manager/helm-requirements/extract', () => {
stable: 'https://charts.helm.sh/stable/',
},
});
// FIXME: explicit assert condition
expect(result).not.toBeNull();
expect(result).toMatchSnapshot();
expect(result).toMatchSnapshot({
deps: [
{ depName: 'redis' },
{ depName: 'postgresql', skipReason: 'local-dependency' },
],
});
});
it('returns null if no dependencies', () => {
fs.readLocalFile.mockResolvedValueOnce(`

View file

@ -28,8 +28,14 @@ describe('manager/helm-values/extract', () => {
});
it('extracts from values.yaml correctly with same structure as "helm create"', () => {
const result = extractPackageFile(helmDefaultChartInitValues);
// FIXME: explicit assert condition
expect(result).toMatchSnapshot();
expect(result).toMatchSnapshot({
deps: [
{
currentValue: '1.16.1',
depName: 'nginx',
},
],
});
});
it('extracts from complex values file correctly"', () => {
const result = extractPackageFile(helmMultiAndNestedImageValues);

View file

@ -81,9 +81,19 @@ describe('manager/helmfile/extract', () => {
stable: 'https://charts.helm.sh/stable',
},
});
// FIXME: explicit assert condition
expect(result).not.toBeNull();
expect(result).toMatchSnapshot();
expect(result).toMatchSnapshot({
datasource: 'helm',
deps: [
{
currentValue: '1.0.0',
skipReason: 'unsupported-chart-type',
},
{
currentValue: '1.0.0',
depName: 'example',
},
],
});
});
it('skip local charts', () => {
@ -179,9 +189,15 @@ describe('manager/helmfile/extract', () => {
stable: 'https://charts.helm.sh/stable',
},
});
// FIXME: explicit assert condition
expect(result).not.toBeNull();
expect(result).toMatchSnapshot();
expect(result).toMatchSnapshot({
datasource: 'helm',
deps: [
{ skipReason: 'local-chart' },
{ depName: 'rabbitmq', currentValue: '7.4.3' },
{ depName: 'kube-prometheus-stack', currentValue: '13.7.2' },
{ depName: 'invalid', skipReason: 'invalid-name' },
],
});
});
});
});