From d747f3ecb1be886fab0f5cb31afb91b503033204 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Sun, 22 Aug 2021 13:48:34 +0300 Subject: [PATCH] test: Explicit checks for some snapshots (#11365) --- .../__snapshots__/extract.spec.ts.snap | 33 --------- lib/manager/gradle-wrapper/extract.spec.ts | 30 ++++++-- .../__snapshots__/artifacts.spec.ts.snap | 33 +++++++++ lib/manager/helmv3/artifacts.spec.ts | 40 ++++++----- lib/manager/leiningen/extract.spec.ts | 71 ++++++++++++++++++- .../maven/__snapshots__/extract.spec.ts.snap | 9 --- lib/manager/maven/extract.spec.ts | 65 +++++++++++++++-- lib/manager/maven/index.spec.ts | 60 +++++++++++++++- 8 files changed, 268 insertions(+), 73 deletions(-) diff --git a/lib/manager/gradle-wrapper/__snapshots__/extract.spec.ts.snap b/lib/manager/gradle-wrapper/__snapshots__/extract.spec.ts.snap index b0488517032ba8..a94cb18f3e82cc 100644 --- a/lib/manager/gradle-wrapper/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/gradle-wrapper/__snapshots__/extract.spec.ts.snap @@ -1,27 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`manager/gradle-wrapper/extract extractPackageFile() extracts all version line 1`] = ` -Array [ - Object { - "currentValue": "4.10.3", - "datasource": "gradle-version", - "depName": "gradle", - "versioning": "gradle", - }, -] -`; - -exports[`manager/gradle-wrapper/extract extractPackageFile() extracts bin version line 1`] = ` -Array [ - Object { - "currentValue": "4.8", - "datasource": "gradle-version", - "depName": "gradle", - "versioning": "gradle", - }, -] -`; - exports[`manager/gradle-wrapper/extract extractPackageFile() extracts prerelease version line 1`] = ` Array [ Object { @@ -32,14 +10,3 @@ Array [ }, ] `; - -exports[`manager/gradle-wrapper/extract extractPackageFile() handles whitespace 1`] = ` -Array [ - Object { - "currentValue": "4.10.3", - "datasource": "gradle-version", - "depName": "gradle", - "versioning": "gradle", - }, -] -`; diff --git a/lib/manager/gradle-wrapper/extract.spec.ts b/lib/manager/gradle-wrapper/extract.spec.ts index 88fcc584a77745..8e2ecacea001f5 100644 --- a/lib/manager/gradle-wrapper/extract.spec.ts +++ b/lib/manager/gradle-wrapper/extract.spec.ts @@ -17,14 +17,26 @@ describe('manager/gradle-wrapper/extract', () => { it('extracts bin version line', () => { const res = extractPackageFile(propertiesFile1); - // FIXME: explicit assert condition - expect(res.deps).toMatchSnapshot(); + expect(res.deps).toEqual([ + { + currentValue: '4.8', + datasource: 'gradle-version', + depName: 'gradle', + versioning: 'gradle', + }, + ]); }); it('extracts all version line', () => { const res = extractPackageFile(propertiesFile2); - // FIXME: explicit assert condition - expect(res.deps).toMatchSnapshot(); + expect(res.deps).toEqual([ + { + currentValue: '4.10.3', + datasource: 'gradle-version', + depName: 'gradle', + versioning: 'gradle', + }, + ]); }); it('extracts prerelease version line', () => { @@ -40,8 +52,14 @@ describe('manager/gradle-wrapper/extract', () => { it('handles whitespace', () => { const res = extractPackageFile(whitespacePropertiesFile); - // FIXME: explicit assert condition - expect(res.deps).toMatchSnapshot(); + expect(res.deps).toEqual([ + { + currentValue: '4.10.3', + datasource: 'gradle-version', + depName: 'gradle', + versioning: 'gradle', + }, + ]); }); }); }); diff --git a/lib/manager/helmv3/__snapshots__/artifacts.spec.ts.snap b/lib/manager/helmv3/__snapshots__/artifacts.spec.ts.snap index fa3a80d86b31f3..0388f42d24794e 100644 --- a/lib/manager/helmv3/__snapshots__/artifacts.spec.ts.snap +++ b/lib/manager/helmv3/__snapshots__/artifacts.spec.ts.snap @@ -35,6 +35,17 @@ Array [ `; exports[`manager/helmv3/artifacts returns updated Chart.lock 1`] = ` +Array [ + Object { + "file": Object { + "contents": "New Chart.lock", + "name": "Chart.lock", + }, + }, +] +`; + +exports[`manager/helmv3/artifacts returns updated Chart.lock 2`] = ` Array [ Object { "cmd": "helm dependency update ''", @@ -58,6 +69,17 @@ Array [ `; exports[`manager/helmv3/artifacts returns updated Chart.lock for lockfile maintenance 1`] = ` +Array [ + Object { + "file": Object { + "contents": "New Chart.lock", + "name": "Chart.lock", + }, + }, +] +`; + +exports[`manager/helmv3/artifacts returns updated Chart.lock for lockfile maintenance 2`] = ` Array [ Object { "cmd": "helm dependency update ''", @@ -81,6 +103,17 @@ Array [ `; exports[`manager/helmv3/artifacts returns updated Chart.lock with docker 1`] = ` +Array [ + Object { + "file": Object { + "contents": "New Chart.lock", + "name": "Chart.lock", + }, + }, +] +`; + +exports[`manager/helmv3/artifacts returns updated Chart.lock with docker 2`] = ` Array [ Object { "cmd": "docker pull renovate/helm", diff --git a/lib/manager/helmv3/artifacts.spec.ts b/lib/manager/helmv3/artifacts.spec.ts index 152b778cd2758b..7a2bea14b2467f 100644 --- a/lib/manager/helmv3/artifacts.spec.ts +++ b/lib/manager/helmv3/artifacts.spec.ts @@ -2,7 +2,7 @@ import { exec as _exec } from 'child_process'; import _fs from 'fs-extra'; import { join } from 'upath'; import { envMock, mockExecAll } from '../../../test/exec-util'; -import { git, mocked } from '../../../test/util'; +import { mocked } from '../../../test/util'; import { setGlobalConfig } from '../../config/global'; import type { RepoGlobalConfig } from '../../config/types'; import * as docker from '../../util/exec/docker'; @@ -13,7 +13,6 @@ import * as helmv3 from './artifacts'; jest.mock('fs-extra'); jest.mock('child_process'); jest.mock('../../util/exec/env'); -jest.mock('../../util/git'); jest.mock('../../util/http'); const fs: jest.Mocked = _fs as any; @@ -75,11 +74,10 @@ describe('manager/helmv3/artifacts', () => { expect(execSnapshots).toMatchSnapshot(); }); it('returns updated Chart.lock', async () => { - git.getFile.mockResolvedValueOnce('Old Chart.lock'); + fs.readFile.mockResolvedValueOnce('Old Chart.lock' as never); const execSnapshots = mockExecAll(exec); - fs.readFile.mockResolvedValueOnce('New Chart.lock' as any); + fs.readFile.mockResolvedValueOnce('New Chart.lock' as never); const updatedDeps = [{ depName: 'dep1' }]; - // FIXME: explicit assert condition expect( await helmv3.updateArtifacts({ packageFileName: 'Chart.yaml', @@ -87,15 +85,16 @@ describe('manager/helmv3/artifacts', () => { newPackageFileContent: '{}', config, }) - ).not.toBeNull(); + ).toMatchSnapshot([ + { file: { contents: 'New Chart.lock', name: 'Chart.lock' } }, + ]); expect(execSnapshots).toMatchSnapshot(); }); it('returns updated Chart.lock for lockfile maintenance', async () => { - git.getFile.mockResolvedValueOnce('Old Chart.lock'); + fs.readFile.mockResolvedValueOnce('Old Chart.lock' as never); const execSnapshots = mockExecAll(exec); - fs.readFile.mockResolvedValueOnce('New Chart.lock' as any); - // FIXME: explicit assert condition + fs.readFile.mockResolvedValueOnce('New Chart.lock' as never); expect( await helmv3.updateArtifacts({ packageFileName: 'Chart.yaml', @@ -103,17 +102,18 @@ describe('manager/helmv3/artifacts', () => { newPackageFileContent: '{}', config: { ...config, updateType: 'lockFileMaintenance' }, }) - ).not.toBeNull(); + ).toMatchSnapshot([ + { file: { contents: 'New Chart.lock', name: 'Chart.lock' } }, + ]); expect(execSnapshots).toMatchSnapshot(); }); it('returns updated Chart.lock with docker', async () => { setGlobalConfig({ ...adminConfig, binarySource: 'docker' }); - git.getFile.mockResolvedValueOnce('Old Chart.lock'); + fs.readFile.mockResolvedValueOnce('Old Chart.lock' as never); const execSnapshots = mockExecAll(exec); - fs.readFile.mockResolvedValueOnce('New Chart.lock' as any); + fs.readFile.mockResolvedValueOnce('New Chart.lock' as never); const updatedDeps = [{ depName: 'dep1' }]; - // FIXME: explicit assert condition expect( await helmv3.updateArtifacts({ packageFileName: 'Chart.yaml', @@ -121,7 +121,9 @@ describe('manager/helmv3/artifacts', () => { newPackageFileContent: '{}', config, }) - ).not.toBeNull(); + ).toMatchSnapshot([ + { file: { contents: 'New Chart.lock', name: 'Chart.lock' } }, + ]); expect(execSnapshots).toMatchSnapshot(); }); it('catches errors', async () => { @@ -130,7 +132,6 @@ describe('manager/helmv3/artifacts', () => { throw new Error('not found'); }); const updatedDeps = [{ depName: 'dep1' }]; - // FIXME: explicit assert condition expect( await helmv3.updateArtifacts({ packageFileName: 'Chart.yaml', @@ -138,6 +139,13 @@ describe('manager/helmv3/artifacts', () => { newPackageFileContent: '{}', config, }) - ).toMatchSnapshot(); + ).toMatchSnapshot([ + { + artifactError: { + lockFile: 'Chart.lock', + stderr: 'not found', + }, + }, + ]); }); }); diff --git a/lib/manager/leiningen/extract.spec.ts b/lib/manager/leiningen/extract.spec.ts index d32d9af17bc4a3..9b8d48df9075cb 100644 --- a/lib/manager/leiningen/extract.spec.ts +++ b/lib/manager/leiningen/extract.spec.ts @@ -53,8 +53,75 @@ describe('manager/leiningen/extract', () => { ]); }); it('extractPackageFile', () => { - // FIXME: explicit assert condition - expect(extractPackageFile(leinProjectClj)).toMatchSnapshot(); + expect(extractPackageFile(leinProjectClj)).toMatchSnapshot({ + deps: [ + { depName: 'org.clojure:clojure', currentValue: '1.3.0' }, + { depName: 'org.jclouds:jclouds', currentValue: '1.0' }, + { depName: 'net.sf.ehcache:ehcache', currentValue: '2.3.1' }, + { depName: 'log4j:log4j', currentValue: '1.2.15' }, + { depName: 'net.3scale:3scale-api', currentValue: '3.0.2' }, + { depName: 'org.lwjgl.lwjgl:lwjgl', currentValue: '2.8.5' }, + { depName: 'org.lwjgl.lwjgl:lwjgl-platform', currentValue: '2.8.5' }, + { depName: 'org.clojure:clojure', currentValue: '1.4.0' }, + { depName: 'org.clojure:clojure', currentValue: '1.5.0' }, + { depName: 'clj-stacktrace:clj-stacktrace', currentValue: '0.2.4' }, + { + depName: 'clj-time:clj-time', + currentValue: '0.12.0', + depType: 'managed-dependencies', + }, + { + depName: 'me.raynes:fs', + currentValue: '1.4.6', + depType: 'managed-dependencies', + }, + { + depName: 'lein-pprint:lein-pprint', + currentValue: '1.1.1', + depType: 'plugins', + }, + { + depName: 'lein-assoc:lein-assoc', + currentValue: '0.1.0', + depType: 'plugins', + }, + { + depName: 's3-wagon-private:s3-wagon-private', + currentValue: '1.1.1', + depType: 'plugins', + }, + { + depName: 'lein-foo:lein-foo', + currentValue: '0.0.1', + depType: 'plugins', + }, + { + depName: 'lein-bar:lein-bar', + currentValue: '0.0.1', + depType: 'plugins', + }, + { + depName: 'cider:cider-nrepl', + currentValue: '0.7.1', + depType: 'plugins', + }, + { + depName: 'com.theoryinpractise:clojure-maven-plugin', + currentValue: '1.3.13', + depType: 'pom-plugins', + }, + { + depName: 'org.apache.tomcat.maven:tomcat7-maven-plugin', + currentValue: '2.1', + depType: 'pom-plugins', + }, + { + depName: 'com.google.appengine:appengine-maven-plugin', + currentValue: '1.9.68', + depType: 'pom-plugins', + }, + ], + }); }); it('extractVariables', () => { expect(extractVariables('(def foo "1")')).toEqual({ foo: '1' }); diff --git a/lib/manager/maven/__snapshots__/extract.spec.ts.snap b/lib/manager/maven/__snapshots__/extract.spec.ts.snap index 6bae8e26b7386f..424b9319f1528b 100644 --- a/lib/manager/maven/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/maven/__snapshots__/extract.spec.ts.snap @@ -166,12 +166,3 @@ Object { "packageFile": null, } `; - -exports[`manager/maven/extract extractDependencies tries minimum manifests 1`] = ` -Object { - "datasource": "maven", - "deps": Array [], - "mavenProps": Object {}, - "packageFile": null, -} -`; diff --git a/lib/manager/maven/extract.spec.ts b/lib/manager/maven/extract.spec.ts index 13955a2a613769..84961fc53878a1 100644 --- a/lib/manager/maven/extract.spec.ts +++ b/lib/manager/maven/extract.spec.ts @@ -16,13 +16,70 @@ describe('manager/maven/extract', () => { it('extract dependencies from any XML position', () => { const res = extractPackage(simpleContent); - // FIXME: explicit assert condition - expect(res).toMatchSnapshot(); + expect(res).toMatchSnapshot({ + deps: [ + { depName: 'org.example:parent', currentValue: '42' }, + { depName: 'org.example:foo', currentValue: '0.0.1' }, + { depName: 'org.example:bar', currentValue: '1.0.0' }, + { + depName: 'org.apache.maven.plugins:maven-release-plugin', + currentValue: '2.4.2', + }, + { + depName: 'org.apache.maven.scm:maven-scm-provider-gitexe', + currentValue: '1.8.1', + }, + { + depName: 'org.example:${artifact-id-placeholder}', + currentValue: '0.0.1', + }, + { depName: '${group-id-placeholder}:baz', currentValue: '0.0.1' }, + { depName: '${quuxGroup}:${quuxId}', currentValue: '${quuxVersion}' }, + { + depName: '${quuxGroup}:${quuxId}-test', + currentValue: '${quuxVersion}', + }, + { + depName: 'org.example:quuz', + currentValue: '1.2.3', + depType: 'test', + }, + { depName: 'org.example:quuuz', currentValue: "it's not a version" }, + { depName: 'org.example:hard-range', currentValue: '[1.0.0]' }, + { + depName: 'org.example:profile-artifact', + currentValue: '${profile-placeholder}', + }, + { + depName: 'org.apache.maven.plugins:maven-checkstyle-plugin', + currentValue: '2.17', + }, + ], + mavenProps: { + quuxGroup: { + packageFile: null, + val: 'org.example', + }, + quuxId: { + packageFile: null, + val: 'quux', + }, + quuxVersion: { + packageFile: null, + val: '1.2.3.4', + }, + }, + packageFile: null, + }); }); it('tries minimum manifests', () => { const res = extractPackage(minimumContent); - // FIXME: explicit assert condition - expect(res).toMatchSnapshot(); + expect(res).toEqual({ + datasource: 'maven', + deps: [], + mavenProps: {}, + packageFile: null, + }); }); }); }); diff --git a/lib/manager/maven/index.spec.ts b/lib/manager/maven/index.spec.ts index df1ee2d402d40a..31da0fd898b48a 100644 --- a/lib/manager/maven/index.spec.ts +++ b/lib/manager/maven/index.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-template-curly-in-string */ import { fs, loadFixture } from '../../../test/util'; import type { PackageDependency, PackageFile } from '../types'; import { extractPackage, resolveParents } from './extract'; @@ -37,8 +38,62 @@ describe('manager/maven/index', () => { p.parent = p.parent.replace(/\\/g, '/'); } } - // FIXME: explicit assert condition - expect(packages).toMatchSnapshot(); + expect(packages).toMatchSnapshot([ + { + deps: [ + { depName: 'org.example:parent', currentValue: '42' }, + { depName: 'org.example:foo', currentValue: '0.0.1' }, + { depName: 'org.example:bar', currentValue: '1.0.0' }, + { + depName: 'org.apache.maven.plugins:maven-release-plugin', + currentValue: '2.4.2', + }, + { + depName: 'org.apache.maven.scm:maven-scm-provider-gitexe', + currentValue: '1.8.1', + }, + { + depName: 'org.example:${artifact-id-placeholder}', + skipReason: 'name-placeholder', + }, + { + depName: '${group-id-placeholder}:baz', + skipReason: 'name-placeholder', + }, + { + depName: 'org.example:quux', + currentValue: '1.2.3.4', + groupName: 'quuxVersion', + }, + { + depName: 'org.example:quux-test', + currentValue: '1.2.3.4', + groupName: 'quuxVersion', + }, + { + depName: 'org.example:quuz', + currentValue: '1.2.3', + depType: 'test', + }, + { + depName: 'org.example:quuuz', + currentValue: "it's not a version", + }, + { depName: 'org.example:hard-range', currentValue: '[1.0.0]' }, + { + depName: 'org.example:profile-artifact', + currentValue: '${profile-placeholder}', + skipReason: 'version-placeholder', + }, + { + depName: 'org.apache.maven.plugins:maven-checkstyle-plugin', + currentValue: '2.17', + }, + ], + packageFile: 'random.pom.xml', + parent: '../pom.xml', + }, + ]); }); }); @@ -103,7 +158,6 @@ describe('manager/maven/index', () => { expect(depUrls).toEqual(urls); }); }); - // FIXME: explicit assert condition expect(packages).toMatchSnapshot(); });