diff --git a/lib/modules/manager/ansible-galaxy/extract.spec.ts b/lib/modules/manager/ansible-galaxy/extract.spec.ts index cc7dc519e70bb917375085c388d041636ce2c97d..0aa97824f98c681b9dc0ac6dbdf0d2d34e288e82 100644 --- a/lib/modules/manager/ansible-galaxy/extract.spec.ts +++ b/lib/modules/manager/ansible-galaxy/extract.spec.ts @@ -1,5 +1,6 @@ import { loadFixture } from '../../../../test/util'; -import { extractPackageFile, getSliceEndNumber } from './extract'; +import { getSliceEndNumber } from './extract'; +import { extractPackageFile } from './'; const yamlFile1 = loadFixture('requirements01.yml'); const yamlFile2 = loadFixture('requirements02.yml'); @@ -16,14 +17,14 @@ describe('modules/manager/ansible-galaxy/extract', () => { it('extracts multiple dependencies from requirements.yml', () => { const res = extractPackageFile(yamlFile1, 'requirements.yml'); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(12); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(12); }); it('extracts dependencies from a not beautified requirements file', () => { const res = extractPackageFile(yamlFile2, 'requirements.yml'); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(2); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(2); }); it('check if an empty file returns null', () => { @@ -38,21 +39,21 @@ describe('modules/manager/ansible-galaxy/extract', () => { it('check collection style requirements file', () => { const res = extractPackageFile(collections1, 'requirements.yml'); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(13); - expect(res.deps.filter((value) => value.skipReason)).toHaveLength(6); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(13); + expect(res?.deps.filter((value) => value.skipReason)).toHaveLength(6); }); it('check collection style requirements file in reverse order and missing empty line', () => { const res = extractPackageFile(collections2, 'requirements.yml'); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(4); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(4); }); it('check galaxy definition file', () => { const res = extractPackageFile(galaxy, 'galaxy.yml'); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(2); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(2); }); }); diff --git a/lib/modules/manager/ansible/extract.spec.ts b/lib/modules/manager/ansible/extract.spec.ts index 4296d8b09d3a2f7c95ceafe9c9768895d4c77605..e7bde92ed9c9fd0f50cf80b3d23ba532e509262d 100644 --- a/lib/modules/manager/ansible/extract.spec.ts +++ b/lib/modules/manager/ansible/extract.spec.ts @@ -1,5 +1,5 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/ansible/extract', () => { describe('extractPackageFile()', () => { @@ -9,14 +9,14 @@ describe('modules/manager/ansible/extract', () => { it('extracts multiple image lines from docker_container', () => { const res = extractPackageFile(Fixtures.get('main1.yaml')); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(9); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(9); }); it('extracts multiple image lines from docker_service', () => { const res = extractPackageFile(Fixtures.get('main2.yaml')); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(4); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(4); }); }); }); diff --git a/lib/modules/manager/argocd/extract.spec.ts b/lib/modules/manager/argocd/extract.spec.ts index 6e11eb5f044ef1e79f892f419e925a008802a1be..ba61d5fc8c8f75e59511ecf286163ca5e8b83873 100644 --- a/lib/modules/manager/argocd/extract.spec.ts +++ b/lib/modules/manager/argocd/extract.spec.ts @@ -1,5 +1,5 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; const validApplication = Fixtures.get('validApplication.yml'); const malformedApplication = Fixtures.get('malformedApplications.yml'); @@ -28,8 +28,8 @@ describe('modules/manager/argocd/extract', () => { it('full test', () => { const result = extractPackageFile(validApplication, 'applications.yml'); expect(result).not.toBeNull(); - expect(result.deps).toBeArrayOfSize(3); - expect(result.deps).toMatchSnapshot(); + expect(result?.deps).toBeArrayOfSize(3); + expect(result?.deps).toMatchSnapshot(); }); it('supports applicationsets', () => { diff --git a/lib/modules/manager/azure-pipelines/extract.spec.ts b/lib/modules/manager/azure-pipelines/extract.spec.ts index 6e9ff77d850c124a97b19ed40669d44baa348584..8bda784ab2c6c378fe8f04ae43a0717beea93532 100644 --- a/lib/modules/manager/azure-pipelines/extract.spec.ts +++ b/lib/modules/manager/azure-pipelines/extract.spec.ts @@ -1,10 +1,10 @@ import { Fixtures } from '../../../../test/fixtures'; import { extractContainer, - extractPackageFile, extractRepository, parseAzurePipelines, } from './extract'; +import { extractPackageFile } from '.'; const azurePipelines = Fixtures.get('azure-pipelines.yaml'); @@ -95,8 +95,8 @@ describe('modules/manager/azure-pipelines/extract', () => { it('extracts dependencies', () => { const res = extractPackageFile(azurePipelines, 'some-file'); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(3); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(3); }); it('should return null when there is no dependency found', () => { diff --git a/lib/modules/manager/azure-pipelines/types.ts b/lib/modules/manager/azure-pipelines/types.ts index 708638e2006cc166ef9a2a7bcab6ef433ea89015..ad4335834ac9d8a8195a9d8dcb39b78a1e77cf65 100644 --- a/lib/modules/manager/azure-pipelines/types.ts +++ b/lib/modules/manager/azure-pipelines/types.ts @@ -1,10 +1,10 @@ export interface Container { - image: string; + image?: string | null; } export interface Repository { type: 'git' | 'github' | 'bitbucket'; name: string; - ref: string; + ref?: string | null; } export interface Resources { repositories: Repository[]; diff --git a/lib/modules/manager/batect-wrapper/artifacts.spec.ts b/lib/modules/manager/batect-wrapper/artifacts.spec.ts index 510f9647b133c9a991b03d781249df61e335de14..6b501fd432a981e2be3b76535d96bb825f1c45c4 100644 --- a/lib/modules/manager/batect-wrapper/artifacts.spec.ts +++ b/lib/modules/manager/batect-wrapper/artifacts.spec.ts @@ -1,6 +1,6 @@ import * as httpMock from '../../../../test/http-mock'; import type { UpdateArtifact } from '../types'; -import { updateArtifacts } from './artifacts'; +import { updateArtifacts } from '.'; const defaultTo = '1.2.3'; const newUnixWrapperContent = `Unix wrapper script for ${defaultTo}`; diff --git a/lib/modules/manager/batect-wrapper/extract.spec.ts b/lib/modules/manager/batect-wrapper/extract.spec.ts index 23572bd6148db8f418b8590a5b0d66510d741ee0..2e8fb2ef8eed4f40957ae6ead16633420596ef6c 100644 --- a/lib/modules/manager/batect-wrapper/extract.spec.ts +++ b/lib/modules/manager/batect-wrapper/extract.spec.ts @@ -2,7 +2,7 @@ import { Fixtures } from '../../../../test/fixtures'; import { GithubReleasesDatasource } from '../../datasource/github-releases'; import { id as semverVersioning } from '../../versioning/semver'; import type { PackageDependency } from '../types'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/batect-wrapper/extract', () => { describe('extractPackageFile()', () => { diff --git a/lib/modules/manager/batect/extract.spec.ts b/lib/modules/manager/batect/extract.spec.ts index 2522a8c7807994c9ed15c98a881f9bc60a30bf9e..3cc1f50465445f2b51e1ba67b70ac1a70cbd801c 100644 --- a/lib/modules/manager/batect/extract.spec.ts +++ b/lib/modules/manager/batect/extract.spec.ts @@ -5,7 +5,7 @@ import { id as dockerVersioning } from '../../versioning/docker'; import { id as semverVersioning } from '../../versioning/semver'; import { getDep } from '../dockerfile/extract'; import type { ExtractConfig, PackageDependency } from '../types'; -import { extractAllPackageFiles } from './extract'; +import { extractAllPackageFiles } from '.'; const fixturesDir = 'lib/modules/manager/batect/__fixtures__'; @@ -76,8 +76,10 @@ describe('modules/manager/batect/extract', () => { `${fixturesDir}/valid/batect.yml`, ]); + // TODO: #7154 expect( - result.sort((a, b) => a.packageFile.localeCompare(b.packageFile)) + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + result?.sort((a, b) => a.packageFile!.localeCompare(b.packageFile!)) ).toEqual([ { packageFile: `${fixturesDir}/valid/another-include.yml`, diff --git a/lib/modules/manager/bazel/extract.spec.ts b/lib/modules/manager/bazel/extract.spec.ts index c7fc036dc5ca3184abe85de298c62ce54768359f..dc3605204dcadd78c375ef27a9588dbfa1a380fe 100644 --- a/lib/modules/manager/bazel/extract.spec.ts +++ b/lib/modules/manager/bazel/extract.spec.ts @@ -1,5 +1,5 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/bazel/extract', () => { describe('extractPackageFile()', () => { @@ -15,13 +15,13 @@ describe('modules/manager/bazel/extract', () => { it('extracts multiple types of dependencies', () => { const res = extractPackageFile(Fixtures.get('WORKSPACE1')); - expect(res.deps).toHaveLength(14); - expect(res.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(14); + expect(res?.deps).toMatchSnapshot(); }); it('extracts github tags', () => { const res = extractPackageFile(Fixtures.get('WORKSPACE2')); - expect(res.deps).toMatchSnapshot([ + expect(res?.deps).toMatchSnapshot([ { packageName: 'lmirosevic/GBDeviceInfo' }, { packageName: 'nelhage/rules_boost' }, { packageName: 'lmirosevic/GBDeviceInfo' }, @@ -31,14 +31,14 @@ describe('modules/manager/bazel/extract', () => { it('handle comments and strings', () => { const res = extractPackageFile(Fixtures.get('WORKSPACE3')); - expect(res.deps).toMatchSnapshot([ + expect(res?.deps).toMatchSnapshot([ { packageName: 'nelhage/rules_boost' }, ]); }); it('extracts dependencies from *.bzl files', () => { const res = extractPackageFile(Fixtures.get('repositories.bzl')); - expect(res.deps).toMatchSnapshot([ + expect(res?.deps).toMatchSnapshot([ { currentDigest: '0356bef3fbbabec5f0e196ecfacdeb6db62d48c0', packageName: 'google/subpar', @@ -62,7 +62,7 @@ describe('modules/manager/bazel/extract', () => { tag="v1.0.0-alpha31.cli-migrations" )` ); - expect(res.deps).toMatchSnapshot([ + expect(res?.deps).toMatchSnapshot([ { currentDigest: 'sha256:a4e8d8c444ca04fe706649e82263c9f4c2a4229bc30d2a64561b5e1d20cc8548', @@ -85,8 +85,8 @@ go_repository( ) ` ); - expect(successStory.deps[0].datasource).toBe('go'); - expect(successStory.deps[0].packageName).toBe( + expect(successStory?.deps[0].datasource).toBe('go'); + expect(successStory?.deps[0].packageName).toBe( 'github.com/test/uuid-fork' ); @@ -100,7 +100,7 @@ go_repository( ) ` ); - expect(badStory.deps[0].skipReason).toBe('unsupported-remote'); + expect(badStory?.deps[0].skipReason).toBe('unsupported-remote'); const gheStory = extractPackageFile( ` @@ -112,7 +112,7 @@ go_repository( ) ` ); - expect(gheStory.deps[0].skipReason).toBe('unsupported-remote'); + expect(gheStory?.deps[0].skipReason).toBe('unsupported-remote'); const gitlabRemote = extractPackageFile( ` @@ -124,7 +124,7 @@ go_repository( ) ` ); - expect(gitlabRemote.deps[0].skipReason).toBe('unsupported-remote'); + expect(gitlabRemote?.deps[0].skipReason).toBe('unsupported-remote'); }); }); }); diff --git a/lib/modules/manager/bazel/update.spec.ts b/lib/modules/manager/bazel/update.spec.ts index 82240d48ac2c94e114eb92db0e0e531b8fb9f25d..2df19ebdbf8970aad447c8f77a9a367f7bbe689c 100644 --- a/lib/modules/manager/bazel/update.spec.ts +++ b/lib/modules/manager/bazel/update.spec.ts @@ -2,7 +2,7 @@ import { Readable } from 'stream'; import * as httpMock from '../../../../test/http-mock'; import { loadFixture } from '../../../../test/util'; import type { UpdateType } from '../../../config/types'; -import { updateDependency } from './update'; +import { updateDependency } from '.'; const content = loadFixture('WORKSPACE1'); const contentContainerPull = loadFixture('container_pull'); @@ -147,7 +147,7 @@ describe('modules/manager/bazel/update', () => { upgrade, }); expect(res).not.toEqual(fileWithBzlExtension); - expect(res.indexOf('0.8.0')).not.toBe(-1); + expect(res?.indexOf('0.8.0')).not.toBe(-1); }); it('updates finds url instead of urls', async () => { @@ -175,7 +175,7 @@ describe('modules/manager/bazel/update', () => { upgrade, }); expect(res).not.toEqual(fileWithBzlExtension); - expect(res.indexOf('0.8.0')).not.toBe(-1); + expect(res?.indexOf('0.8.0')).not.toBe(-1); }); it('returns null if no urls resolve hashes', async () => { @@ -267,8 +267,8 @@ http_archive( upgrade, }); expect(res).not.toEqual(content); - expect(res.indexOf('0.5.0')).toBe(-1); - expect(res.indexOf('0.6.2')).not.toBe(-1); + expect(res?.indexOf('0.5.0')).toBe(-1); + expect(res?.indexOf('0.6.2')).not.toBe(-1); }); }); }); diff --git a/lib/modules/manager/bitbucket-pipelines/extract.spec.ts b/lib/modules/manager/bitbucket-pipelines/extract.spec.ts index eb614e308e7174dec9fd6e17e67bdd4e61f14d83..fe35eb919888a8f2c7857e9f1361246b63dd219f 100644 --- a/lib/modules/manager/bitbucket-pipelines/extract.spec.ts +++ b/lib/modules/manager/bitbucket-pipelines/extract.spec.ts @@ -1,5 +1,5 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/bitbucket-pipelines/extract', () => { describe('extractPackageFile()', () => { @@ -9,7 +9,7 @@ describe('modules/manager/bitbucket-pipelines/extract', () => { it('extracts dependencies', () => { const res = extractPackageFile(Fixtures.get('bitbucket-pipelines.yaml')); - expect(res.deps).toMatchInlineSnapshot(` + expect(res?.deps).toMatchInlineSnapshot(` Array [ Object { "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", @@ -37,7 +37,7 @@ Array [ }, ] `); - expect(res.deps).toHaveLength(3); + expect(res?.deps).toHaveLength(3); }); }); }); diff --git a/lib/modules/manager/buildkite/extract.spec.ts b/lib/modules/manager/buildkite/extract.spec.ts index 5ab5f64322173b203c1c2296a5358d60c4682636..0edd3aada9aa6381edefdb089f85e8f2a592493e 100644 --- a/lib/modules/manager/buildkite/extract.spec.ts +++ b/lib/modules/manager/buildkite/extract.spec.ts @@ -1,6 +1,6 @@ import { Fixtures } from '../../../../test/fixtures'; import type { PackageDependency } from '../types'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/buildkite/extract', () => { describe('extractPackageFile()', () => { @@ -9,31 +9,31 @@ describe('modules/manager/buildkite/extract', () => { }); it('extracts simple single plugin', () => { - const res = extractPackageFile(Fixtures.get('pipeline1.yml')).deps; + const res = extractPackageFile(Fixtures.get('pipeline1.yml'))?.deps; expect(res).toMatchSnapshot(); expect(res).toHaveLength(1); }); it('extracts multiple plugins in same file', () => { - const res = extractPackageFile(Fixtures.get('pipeline2.yml')).deps; + const res = extractPackageFile(Fixtures.get('pipeline2.yml'))?.deps; expect(res).toMatchSnapshot(); expect(res).toHaveLength(2); }); it('adds skipReason', () => { - const res = extractPackageFile(Fixtures.get('pipeline3.yml')).deps; + const res = extractPackageFile(Fixtures.get('pipeline3.yml'))?.deps; expect(res).toMatchSnapshot(); expect(res).toHaveLength(2); }); it('extracts arrays of plugins', () => { - const res = extractPackageFile(Fixtures.get('pipeline4.yml')).deps; + const res = extractPackageFile(Fixtures.get('pipeline4.yml'))?.deps; expect(res).toMatchSnapshot(); expect(res).toHaveLength(4); }); it('extracts git-based plugins', () => { - const res = extractPackageFile(Fixtures.get('pipeline5.yml')).deps; + const res = extractPackageFile(Fixtures.get('pipeline5.yml'))?.deps; expect(res).toMatchSnapshot(); expect(res).toHaveLength(2); }); @@ -45,7 +45,7 @@ describe('modules/manager/buildkite/extract', () => { depName: 'some-org/some-plugin', registryUrls: ['https://github.company.com'], }; - const res = extractPackageFile(Fixtures.get('pipeline6.yml')).deps; + const res = extractPackageFile(Fixtures.get('pipeline6.yml'))?.deps; expect(res).toHaveLength(1); expect(res).toEqual([expectedPackageDependency]); }); diff --git a/lib/modules/manager/bundler/extract.spec.ts b/lib/modules/manager/bundler/extract.spec.ts index df8d1c0aede5ce49ec262bb96c17a8998f546dba..88a592a890c171795d2baca74a0d84b4a7747d83 100644 --- a/lib/modules/manager/bundler/extract.spec.ts +++ b/lib/modules/manager/bundler/extract.spec.ts @@ -1,3 +1,4 @@ +import is from '@sindresorhus/is'; import { fs, loadFixture } from '../../../../test/util'; import { isValid } from '../../versioning/ruby'; import { extractPackageFile } from '.'; @@ -37,23 +38,21 @@ describe('modules/manager/bundler/extract', () => { expect(res).toMatchSnapshot(); // couple of dependency of ruby rails are not present in the lock file. Filter out those before processing expect( - res.deps + res?.deps .filter((dep) => Object.prototype.hasOwnProperty.call(dep, 'lockedVersion') ) .every( - (dep) => - Object.prototype.hasOwnProperty.call(dep, 'lockedVersion') && - isValid(dep.lockedVersion) + (dep) => is.string(dep.lockedVersion) && isValid(dep.lockedVersion) ) ).toBeTrue(); - expect(res.deps).toHaveLength(68); + expect(res?.deps).toHaveLength(68); }); it('parses sourceGroups', async () => { const res = await extractPackageFile(sourceGroupGemfile, 'Gemfile'); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(7); + expect(res?.deps).toHaveLength(7); }); it('parse webpacker Gemfile', async () => { @@ -61,13 +60,11 @@ describe('modules/manager/bundler/extract', () => { const res = await extractPackageFile(webPackerGemfile, 'Gemfile'); expect(res).toMatchSnapshot(); expect( - res.deps.every( - (dep) => - Object.prototype.hasOwnProperty.call(dep, 'lockedVersion') && - isValid(dep.lockedVersion) + res?.deps.every( + (dep) => is.string(dep.lockedVersion) && isValid(dep.lockedVersion) ) ).toBeTrue(); - expect(res.deps).toHaveLength(5); + expect(res?.deps).toHaveLength(5); }); it('parse mastodon Gemfile', async () => { @@ -75,17 +72,15 @@ describe('modules/manager/bundler/extract', () => { const res = await extractPackageFile(mastodonGemfile, 'Gemfile'); expect(res).toMatchSnapshot(); expect( - res.deps + res?.deps .filter((dep) => Object.prototype.hasOwnProperty.call(dep, 'lockedVersion') ) .every( - (dep) => - Object.prototype.hasOwnProperty.call(dep, 'lockedVersion') && - isValid(dep.lockedVersion) + (dep) => is.string(dep.lockedVersion) && isValid(dep.lockedVersion) ) ).toBeTrue(); - expect(res.deps).toHaveLength(125); + expect(res?.deps).toHaveLength(125); }); it('parse Ruby CI Gemfile', async () => { @@ -93,13 +88,11 @@ describe('modules/manager/bundler/extract', () => { const res = await extractPackageFile(rubyCIGemfile, 'Gemfile'); expect(res).toMatchSnapshot(); expect( - res.deps.every( - (dep) => - Object.prototype.hasOwnProperty.call(dep, 'lockedVersion') && - isValid(dep.lockedVersion) + res?.deps.every( + (dep) => is.string(dep.lockedVersion) && isValid(dep.lockedVersion) ) ).toBeTrue(); - expect(res.deps).toHaveLength(14); + expect(res?.deps).toHaveLength(14); }); }); @@ -108,13 +101,11 @@ describe('modules/manager/bundler/extract', () => { const res = await extractPackageFile(gitlabFossGemfile, 'Gemfile'); expect(res).toMatchSnapshot(); expect( - res.deps.every( - (dep) => - Object.prototype.hasOwnProperty.call(dep, 'lockedVersion') && - isValid(dep.lockedVersion) + res?.deps.every( + (dep) => is.string(dep.lockedVersion) && isValid(dep.lockedVersion) ) ).toBeTrue(); - expect(res.deps).toHaveLength(252); + expect(res?.deps).toHaveLength(252); }); it('parse source blocks in Gemfile', async () => { @@ -130,6 +121,6 @@ describe('modules/manager/bundler/extract', () => { 'Gemfile' ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(2); + expect(res?.deps).toHaveLength(2); }); }); diff --git a/lib/modules/manager/cargo/artifacts.spec.ts b/lib/modules/manager/cargo/artifacts.spec.ts index 818e39e45dc4722c007d2f06cdd189269e30d8e8..93c52216107ae91e1d9b83eb867f6fb723764240 100644 --- a/lib/modules/manager/cargo/artifacts.spec.ts +++ b/lib/modules/manager/cargo/artifacts.spec.ts @@ -5,7 +5,7 @@ import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; import * as docker from '../../../util/exec/docker'; import type { UpdateArtifactsConfig } from '../types'; -import * as cargo from './artifacts'; +import * as cargo from '.'; jest.mock('child_process'); jest.mock('../../../util/exec/env'); diff --git a/lib/modules/manager/cargo/extract.spec.ts b/lib/modules/manager/cargo/extract.spec.ts index 896ca48afc3ce2be0cc3ba56d1d4815776e6e3b3..fdbdcc083c0edc82c8b8176fa7c722816c7a1f7b 100644 --- a/lib/modules/manager/cargo/extract.spec.ts +++ b/lib/modules/manager/cargo/extract.spec.ts @@ -5,7 +5,7 @@ import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; import { writeLocalFile } from '../../../util/fs'; import type { ExtractConfig } from '../types'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; const cargo1toml = loadFixture('Cargo.1.toml'); const cargo2toml = loadFixture('Cargo.2.toml'); @@ -66,32 +66,32 @@ describe('modules/manager/cargo/extract', () => { it('extracts multiple dependencies simple', async () => { const res = await extractPackageFile(cargo1toml, 'Cargo.toml', config); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(15); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(15); }); it('extracts multiple dependencies advanced', async () => { const res = await extractPackageFile(cargo2toml, 'Cargo.toml', config); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(18 + 6 + 1); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(18 + 6 + 1); }); it('handles inline tables', async () => { const res = await extractPackageFile(cargo3toml, 'Cargo.toml', config); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(8); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(8); }); it('handles standard tables', async () => { const res = await extractPackageFile(cargo4toml, 'Cargo.toml', config); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(6); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(6); }); it('extracts platform specific dependencies', async () => { const res = await extractPackageFile(cargo5toml, 'Cargo.toml', config); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(4); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(4); }); it('extracts registry urls from .cargo/config.toml', async () => { @@ -99,8 +99,8 @@ describe('modules/manager/cargo/extract', () => { const res = await extractPackageFile(cargo6toml, 'Cargo.toml', { ...config, }); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(3); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(3); }); it('extracts registry urls from .cargo/config (legacy path)', async () => { @@ -108,16 +108,16 @@ describe('modules/manager/cargo/extract', () => { const res = await extractPackageFile(cargo6toml, 'Cargo.toml', { ...config, }); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(3); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(3); }); it('skips unknown registries', async () => { const cargotoml = '[dependencies]\nfoobar = { version = "0.1.0", registry = "not-listed" }'; const res = await extractPackageFile(cargotoml, 'Cargo.toml', config); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(1); }); it('fails to parse cargo config with invalid TOML', async () => { @@ -126,8 +126,8 @@ describe('modules/manager/cargo/extract', () => { const res = await extractPackageFile(cargo6toml, 'Cargo.toml', { ...config, }); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(3); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(3); }); it('ignore cargo config registries with missing index', async () => { @@ -136,8 +136,8 @@ describe('modules/manager/cargo/extract', () => { const res = await extractPackageFile(cargo6toml, 'Cargo.toml', { ...config, }); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(3); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(3); }); it('extracts original package name of renamed dependencies', async () => { @@ -145,9 +145,9 @@ describe('modules/manager/cargo/extract', () => { '[dependencies]\nboolector-solver = { package = "boolector", version = "0.4.0" }'; const res = await extractPackageFile(cargotoml, 'Cargo.toml', config); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); - expect(res.deps[0].packageName).toBe('boolector'); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(1); + expect(res?.deps[0].packageName).toBe('boolector'); }); }); }); diff --git a/lib/modules/manager/circleci/extract.spec.ts b/lib/modules/manager/circleci/extract.spec.ts index b6c6fe1b77de5ea7e37a4f1e68103a1e96486849..7c7f1164936045b8d70961ba88462cc9930ca2bb 100644 --- a/lib/modules/manager/circleci/extract.spec.ts +++ b/lib/modules/manager/circleci/extract.spec.ts @@ -1,5 +1,5 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; const file1 = Fixtures.get('config.yml'); const file2 = Fixtures.get('config2.yml'); @@ -13,13 +13,13 @@ describe('modules/manager/circleci/extract', () => { it('extracts multiple image lines', () => { const res = extractPackageFile(file1); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(4); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(4); }); it('extracts orbs too', () => { const res = extractPackageFile(file2); - expect(res.deps).toMatchSnapshot([ + expect(res?.deps).toMatchSnapshot([ { depName: 'release-workflows', currentValue: '4.1.0', @@ -49,7 +49,7 @@ describe('modules/manager/circleci/extract', () => { it('extracts image without leading dash', () => { const res = extractPackageFile(file3); - expect(res.deps).toMatchSnapshot([ + expect(res?.deps).toMatchSnapshot([ { currentValue: '14.8.0', depName: 'cimg/node' }, ]); }); diff --git a/lib/modules/manager/cloudbuild/extract.spec.ts b/lib/modules/manager/cloudbuild/extract.spec.ts index 20671649164ed236d893bd54f76c37fd711feb1e..bc3e240c5e09663f0f381674b17e884d1561c7d4 100644 --- a/lib/modules/manager/cloudbuild/extract.spec.ts +++ b/lib/modules/manager/cloudbuild/extract.spec.ts @@ -1,5 +1,5 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/cloudbuild/extract', () => { describe('extractPackageFile()', () => { @@ -9,8 +9,8 @@ describe('modules/manager/cloudbuild/extract', () => { it('extracts multiple image lines', () => { const res = extractPackageFile(Fixtures.get('cloudbuild.yml')); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(3); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(3); }); }); }); diff --git a/lib/modules/manager/composer/artifacts.spec.ts b/lib/modules/manager/composer/artifacts.spec.ts index e5899ab9fc9ae2b0aa43e90243096e9f27608deb..673e47c17e780e64e86c5cf010527c7d7070703e 100644 --- a/lib/modules/manager/composer/artifacts.spec.ts +++ b/lib/modules/manager/composer/artifacts.spec.ts @@ -10,7 +10,7 @@ import * as hostRules from '../../../util/host-rules'; import * as _datasource from '../../datasource'; import { PackagistDatasource } from '../../datasource/packagist'; import type { UpdateArtifactsConfig } from '../types'; -import * as composer from './artifacts'; +import * as composer from '.'; jest.mock('child_process'); jest.mock('../../../util/exec/env'); @@ -344,7 +344,7 @@ describe('modules/manager/composer/artifacts', () => { newPackageFileContent: '{}', config: { ...config, - composerIgnorePlatformReqs: null, + composerIgnorePlatformReqs: undefined, }, }) ).not.toBeNull(); diff --git a/lib/modules/manager/composer/extract.spec.ts b/lib/modules/manager/composer/extract.spec.ts index 97375edfd29fb29d858a2387318cc615fddd3855..aeb191389ee02936eab1a98794c252b39fc3b0a5 100644 --- a/lib/modules/manager/composer/extract.spec.ts +++ b/lib/modules/manager/composer/extract.spec.ts @@ -1,5 +1,5 @@ import { fs, loadFixture } from '../../../../test/util'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; jest.mock('../../../util/fs'); @@ -12,7 +12,7 @@ const requirements5Lock = loadFixture('composer5.lock'); describe('modules/manager/composer/extract', () => { describe('extractPackageFile()', () => { - let packageFile; + let packageFile: string; beforeEach(() => { packageFile = 'composer.json'; @@ -29,39 +29,39 @@ describe('modules/manager/composer/extract', () => { it('extracts dependencies with no lock file', async () => { const res = await extractPackageFile(requirements1, packageFile); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(32); + expect(res?.deps).toHaveLength(32); }); it('extracts registryUrls', async () => { const res = await extractPackageFile(requirements2, packageFile); expect(res).toMatchSnapshot(); - expect(res.registryUrls).toHaveLength(1); + expect(res?.registryUrls).toHaveLength(1); }); it('extracts object registryUrls', async () => { const res = await extractPackageFile(requirements3, packageFile); expect(res).toMatchSnapshot(); - expect(res.registryUrls).toHaveLength(1); + expect(res?.registryUrls).toHaveLength(1); }); it('extracts repositories and registryUrls', async () => { const res = await extractPackageFile(requirements4, packageFile); expect(res).toMatchSnapshot(); - expect(res.registryUrls).toHaveLength(3); + expect(res?.registryUrls).toHaveLength(3); }); it('extracts object repositories and registryUrls with lock file', async () => { fs.readLocalFile.mockResolvedValue(requirements5Lock); const res = await extractPackageFile(requirements5, packageFile); expect(res).toMatchSnapshot(); - expect(res.registryUrls).toHaveLength(2); + expect(res?.registryUrls).toHaveLength(2); }); it('extracts dependencies with lock file', async () => { fs.readLocalFile.mockResolvedValue('some content'); const res = await extractPackageFile(requirements1, packageFile); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(32); + expect(res?.deps).toHaveLength(32); }); }); }); diff --git a/lib/modules/manager/deps-edn/extract.spec.ts b/lib/modules/manager/deps-edn/extract.spec.ts index f64246cdebdca617d9f8b66574c953812bd4ce94..5737e3256d72e7b6833eafd1d0228b4af3d62af0 100644 --- a/lib/modules/manager/deps-edn/extract.spec.ts +++ b/lib/modules/manager/deps-edn/extract.spec.ts @@ -1,5 +1,5 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/deps-edn/extract', () => { describe('extractPackageFile', () => { diff --git a/lib/modules/manager/docker-compose/extract.spec.ts b/lib/modules/manager/docker-compose/extract.spec.ts index ebfb2708dadbd175763a9fa340a0153ec123b257..00113e5ae7170a9d98c9a6d70ce870bccd19b652 100644 --- a/lib/modules/manager/docker-compose/extract.spec.ts +++ b/lib/modules/manager/docker-compose/extract.spec.ts @@ -1,5 +1,5 @@ import { loadFixture } from '../../../../test/util'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; const yamlFile1 = loadFixture('docker-compose.1.yml'); const yamlFile3 = loadFixture('docker-compose.3.yml'); @@ -22,25 +22,25 @@ describe('modules/manager/docker-compose/extract', () => { it('extracts multiple image lines for version 1', () => { const res = extractPackageFile(yamlFile1); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(8); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(8); }); it('extracts multiple image lines for version 3', () => { const res = extractPackageFile(yamlFile3); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(8); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(8); }); it('extracts multiple image lines for version 3 without set version key', () => { const res = extractPackageFile(yamlFile3NoVersion); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(8); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(8); }); it('extracts default variable values for version 3', () => { const res = extractPackageFile(yamlFile3DefaultValue); - expect(res.deps).toMatchInlineSnapshot(` + expect(res?.deps).toMatchInlineSnapshot(` Array [ Object { "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", @@ -52,7 +52,7 @@ describe('modules/manager/docker-compose/extract', () => { }, ] `); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toHaveLength(1); }); }); }); diff --git a/lib/modules/manager/dockerfile/extract.spec.ts b/lib/modules/manager/dockerfile/extract.spec.ts index 38f0487483bd4fe2a7944db5825da5612c8c098c..5335b635f653b72c11e3f62534178d0805518f34 100644 --- a/lib/modules/manager/dockerfile/extract.spec.ts +++ b/lib/modules/manager/dockerfile/extract.spec.ts @@ -1,5 +1,6 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile, extractVariables, getDep } from './extract'; +import { extractVariables, getDep } from './extract'; +import { extractPackageFile } from '.'; const d1 = Fixtures.get('1.Dockerfile'); const d2 = Fixtures.get('2.Dockerfile'); @@ -14,7 +15,7 @@ describe('modules/manager/dockerfile/extract', () => { }); it('handles naked dep', () => { - const res = extractPackageFile('FROM node\n').deps; + const res = extractPackageFile('FROM node\n')?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -31,7 +32,7 @@ describe('modules/manager/dockerfile/extract', () => { }); it('is case insensitive', () => { - const res = extractPackageFile('From node\n').deps; + const res = extractPackageFile('From node\n')?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -48,7 +49,7 @@ describe('modules/manager/dockerfile/extract', () => { }); it('handles tag', () => { - const res = extractPackageFile('FROM node:8.9.0-alpine\n').deps; + const res = extractPackageFile('FROM node:8.9.0-alpine\n')?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -67,7 +68,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles digest', () => { const res = extractPackageFile( 'FROM node@sha256:eb85fc5b1198f5e1ec025ea07586bdbbf397e7d82df66c90d7511f533517e063\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -86,7 +87,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles tag and digest', () => { const res = extractPackageFile( 'FROM node:8.9.0@sha256:eb85fc5b1198f5e1ec025ea07586bdbbf397e7d82df66c90d7511f533517e063\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -103,7 +104,7 @@ describe('modules/manager/dockerfile/extract', () => { }); it('handles from as', () => { - const res = extractPackageFile('FROM node:8.9.0-alpine as base\n').deps; + const res = extractPackageFile('FROM node:8.9.0-alpine as base\n')?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -122,7 +123,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles comments', () => { const res = extractPackageFile( '# some comment\n# another\n\nFROM node\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -141,7 +142,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles custom hosts', () => { const res = extractPackageFile( 'FROM registry2.something.info/node:8\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -160,7 +161,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles custom hosts and suffix', () => { const res = extractPackageFile( 'FROM registry2.something.info/node:8-alpine\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -179,7 +180,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles custom hosts with port', () => { const res = extractPackageFile( 'FROM registry2.something.info:5005/node:8\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -193,14 +194,14 @@ describe('modules/manager/dockerfile/extract', () => { }, ] `); - expect(res[0].depName).toBe('registry2.something.info:5005/node'); - expect(res[0].currentValue).toBe('8'); + expect(res?.[0].depName).toBe('registry2.something.info:5005/node'); + expect(res?.[0].currentValue).toBe('8'); }); it('handles custom hosts with port without tag', () => { const res = extractPackageFile( 'FROM registry2.something.info:5005/node\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -214,12 +215,12 @@ describe('modules/manager/dockerfile/extract', () => { }, ] `); - expect(res[0].depName).toBe('registry2.something.info:5005/node'); + expect(res?.[0].depName).toBe('registry2.something.info:5005/node'); }); it('handles quay hosts with port', () => { - const res = extractPackageFile('FROM quay.io:1234/node\n').deps; - expect(res[0]).toMatchInlineSnapshot(` + const res = extractPackageFile('FROM quay.io:1234/node\n')?.deps; + expect(res?.[0]).toMatchInlineSnapshot(` Object { "autoReplaceStringTemplate": "{{packageName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}", "currentDigest": undefined, @@ -234,7 +235,7 @@ describe('modules/manager/dockerfile/extract', () => { }); it('handles namespaced images', () => { - const res = extractPackageFile('FROM mynamespace/node:8\n').deps; + const res = extractPackageFile('FROM mynamespace/node:8\n')?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -253,7 +254,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles custom hosts with namespace', () => { const res = extractPackageFile( 'FROM registry2.something.info/someaccount/node:8\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -272,7 +273,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles abnormal spacing', () => { const res = extractPackageFile( 'FROM registry.allmine.info:5005/node:8.7.0\n\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -291,7 +292,7 @@ describe('modules/manager/dockerfile/extract', () => { it('extracts multiple FROM tags', () => { const res = extractPackageFile( 'FROM node:6.12.3 as frontend\n\n# comment\nENV foo=bar\nFROM python:3.6-slim\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -325,7 +326,7 @@ describe('modules/manager/dockerfile/extract', () => { it('skips named multistage FROM tags', () => { const res = extractPackageFile( 'FROM node:6.12.3 as frontend\n\n# comment\nENV foo=bar\nFROM frontend\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -345,7 +346,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles COPY --from', () => { const res = extractPackageFile( 'FROM scratch\nCOPY --from=gcr.io/k8s-skaffold/skaffold:v0.11.0 /usr/bin/skaffold /usr/bin/skaffold\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -364,7 +365,7 @@ describe('modules/manager/dockerfile/extract', () => { it('skips named multistage COPY --from tags', () => { const res = extractPackageFile( 'FROM node:6.12.3 as frontend\n\n# comment\nENV foo=bar\nCOPY --from=frontend /usr/bin/node /usr/bin/node\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -384,7 +385,7 @@ describe('modules/manager/dockerfile/extract', () => { it('skips index reference COPY --from tags', () => { const res = extractPackageFile( 'FROM node:6.12.3 as frontend\n\n# comment\nENV foo=bar\nCOPY --from=0 /usr/bin/node /usr/bin/node\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -404,7 +405,7 @@ describe('modules/manager/dockerfile/extract', () => { it('detects ["stage"] and ["final"] deps of docker multi-stage build.', () => { const res = extractPackageFile( 'FROM node:8.15.1-alpine as skippedfrom\nFROM golang:1.7.3 as builder\n\n# comment\nWORKDIR /go/src/github.com/alexellis/href-counter/\nRUN go get -d -v golang.org/x/net/html \nCOPY app.go .\nRUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .\n\nFROM alpine:latest \nRUN apk --no-cache add ca-certificates\nWORKDIR /root/\nCOPY --from=builder /go/src/github.com/alexellis/href-counter/app .\nCMD ["./app"]\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -437,15 +438,15 @@ describe('modules/manager/dockerfile/extract', () => { ] `); const passed = [ - res[2].depType === 'final', - res[1].depType === 'stage', - res[0].depType === 'stage', + res?.[2].depType === 'final', + res?.[1].depType === 'stage', + res?.[0].depType === 'stage', ].every(Boolean); expect(passed).toBeTrue(); }); it('extracts images on adjacent lines', () => { - const res = extractPackageFile(d1).deps; + const res = extractPackageFile(d1)?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -472,7 +473,7 @@ describe('modules/manager/dockerfile/extract', () => { }); it('extracts images from all sorts of (maybe multiline) FROM and COPY --from statements', () => { - const res = extractPackageFile(d2).deps; + const res = extractPackageFile(d2)?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -562,7 +563,7 @@ describe('modules/manager/dockerfile/extract', () => { }); it('handles calico/node', () => { - const res = extractPackageFile('FROM calico/node\n').deps; + const res = extractPackageFile('FROM calico/node\n')?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -579,7 +580,7 @@ describe('modules/manager/dockerfile/extract', () => { }); it('handles ubuntu', () => { - const res = extractPackageFile('FROM ubuntu:18.04\n').deps; + const res = extractPackageFile('FROM ubuntu:18.04\n')?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -597,7 +598,7 @@ describe('modules/manager/dockerfile/extract', () => { }); it('handles debian with codename', () => { - const res = extractPackageFile('FROM debian:buster\n').deps; + const res = extractPackageFile('FROM debian:buster\n')?.deps; expect(res).toEqual([ { autoReplaceStringTemplate: @@ -614,7 +615,7 @@ describe('modules/manager/dockerfile/extract', () => { }); it('handles debian with prefixes', () => { - const res = extractPackageFile('FROM amd64/debian:10\n').deps; + const res = extractPackageFile('FROM amd64/debian:10\n')?.deps; expect(res).toEqual([ { autoReplaceStringTemplate: @@ -632,7 +633,7 @@ describe('modules/manager/dockerfile/extract', () => { }); it('handles prefixes', () => { - const res = extractPackageFile('FROM amd64/ubuntu:18.04\n').deps; + const res = extractPackageFile('FROM amd64/ubuntu:18.04\n')?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -653,7 +654,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles implausible line continuation', () => { const res = extractPackageFile( 'FROM alpine:3.5\n\nRUN something \\' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -670,7 +671,7 @@ describe('modules/manager/dockerfile/extract', () => { }); it('handles multi-line FROM with space after escape character', () => { - const res = extractPackageFile('FROM \\ \nnginx:1.20\n').deps; + const res = extractPackageFile('FROM \\ \nnginx:1.20\n')?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -687,7 +688,7 @@ describe('modules/manager/dockerfile/extract', () => { }); it('handles FROM without ARG default value', () => { - const res = extractPackageFile('ARG img_base\nFROM $img_base\n').deps; + const res = extractPackageFile('ARG img_base\nFROM $img_base\n')?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -704,7 +705,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles FROM with empty ARG default value', () => { const res = extractPackageFile( 'ARG patch1=""\nARG patch2=\nFROM nginx:1.20${patch1}$patch2\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -723,7 +724,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles FROM with version in ARG value', () => { const res = extractPackageFile( 'ARG\tVARIANT="1.60.0-bullseye"\nFROM\trust:${VARIANT}\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -742,7 +743,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles FROM with version in ARG default value', () => { const res = extractPackageFile( 'ARG IMAGE_VERSION=${IMAGE_VERSION:-ubuntu:xenial}\nfrom ${IMAGE_VERSION} as base\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -762,7 +763,7 @@ describe('modules/manager/dockerfile/extract', () => { const res = extractPackageFile( 'ARG sha_digest=sha256:ab37242e81cbc031b2600eef4440fe87055a05c14b40686df85078cc5086c98f\n' + ' FROM gcr.io/distroless/java17@$sha_digest' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -781,7 +782,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles FROM with overwritten ARG value', () => { const res = extractPackageFile( 'ARG base=nginx:1.19\nFROM $base as stage1\nARG base=nginx:1.20\nFROM --platform=amd64 $base as stage2\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -809,7 +810,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles FROM with multiple ARG values', () => { const res = extractPackageFile( 'ARG CUDA=9.2\nARG LINUX_VERSION ubuntu16.04\nFROM nvidia/cuda:${CUDA}-devel-${LINUX_VERSION}\n' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -831,7 +832,7 @@ describe('modules/manager/dockerfile/extract', () => { }); it('extracts images from multi-line ARG statements', () => { - const res = extractPackageFile(d3).deps; + const res = extractPackageFile(d3)?.deps; expect(res).toEqual([ { autoReplaceStringTemplate: @@ -874,7 +875,7 @@ describe('modules/manager/dockerfile/extract', () => { it('ignores parser directives in wrong order', () => { const res = extractPackageFile( '# dummy\n# escape = `\n\nFROM\\\nnginx:1.20' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -891,7 +892,7 @@ describe('modules/manager/dockerfile/extract', () => { }); it('handles an alternative escape character', () => { - const res = extractPackageFile(d4).deps; + const res = extractPackageFile(d4)?.deps; expect(res).toEqual([ { autoReplaceStringTemplate: @@ -953,7 +954,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles FROM with version in ARG default value and quotes', () => { const res = extractPackageFile( 'ARG REF_NAME=${REF_NAME:-"gcr.io/distroless/static-debian11:nonroot@sha256:abc"}\nfrom ${REF_NAME}' - ).deps; + )?.deps; expect(res).toMatchInlineSnapshot(` Array [ Object { @@ -972,7 +973,7 @@ describe('modules/manager/dockerfile/extract', () => { it('handles version in ARG and digest in FROM with CRLF linefeed', () => { const res = extractPackageFile( 'ARG IMAGE_TAG=14.04\r\n#something unrelated\r\nFROM ubuntu:$IMAGE_TAG@sha256:abc\r\n' - ).deps; + )?.deps; expect(res).toEqual([ { autoReplaceStringTemplate: @@ -998,7 +999,7 @@ describe('modules/manager/dockerfile/extract', () => { 'ARG NODE_IMAGE_TAG="16.14.2-alpine3.14"\n' + 'ARG DUMMY_PREFIX=\n' + 'FROM ${DUMMY_PREFIX}${NODE_IMAGE_HOST}${NODE_IMAGE_NAME}:${NODE_IMAGE_TAG}${NODE_IMAGE_HASH} as yarn\n' - ).deps; + )?.deps; expect(res).toEqual([ { autoReplaceStringTemplate: diff --git a/lib/modules/manager/droneci/extract.spec.ts b/lib/modules/manager/droneci/extract.spec.ts index ca309dc78d10583f04c31bdff93780eeb68c7bd5..97e902236c4e2040d01ef68278e32ed95e3fc75a 100644 --- a/lib/modules/manager/droneci/extract.spec.ts +++ b/lib/modules/manager/droneci/extract.spec.ts @@ -1,6 +1,6 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/droneci/extract', () => { describe('extractPackageFile()', () => { @@ -10,8 +10,8 @@ describe('modules/manager/droneci/extract', () => { it('extracts multiple image lines', () => { const res = extractPackageFile(Fixtures.get('.drone.yml')); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(6); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(6); }); }); }); diff --git a/lib/modules/manager/fingerprint.spec.ts b/lib/modules/manager/fingerprint.spec.ts index bf29986163ac109e6a42645fe6b96198d97c6509..0060c790ecc370d102a1c8bd3d997c3a30da3bfa 100644 --- a/lib/modules/manager/fingerprint.spec.ts +++ b/lib/modules/manager/fingerprint.spec.ts @@ -6,7 +6,7 @@ describe('modules/manager/fingerprint', () => { const regex = regEx(/^[a-f0-9]{64}$/i); const managers = getManagers(); for (const [manager] of managers) { - const managerHash = hashMap.get(manager); + const managerHash = hashMap.get(manager)!; expect(regex.test(managerHash)).toBeTrue(); } }); diff --git a/lib/modules/manager/flux/extract.spec.ts b/lib/modules/manager/flux/extract.spec.ts index ced3bd438be2ef434eaa6b46e968ccf1aaf4364d..adcc6b451c3f2d709a34adf7fb73c0e7f5828b6a 100644 --- a/lib/modules/manager/flux/extract.spec.ts +++ b/lib/modules/manager/flux/extract.spec.ts @@ -55,7 +55,7 @@ describe('modules/manager/flux/extract', () => { `# Flux Version: v0.27.0`, 'clusters/my-cluster/flux-system/gotk-components.yaml' ); - expect(result.deps[0].managerData.components).toBeUndefined(); + expect(result?.deps[0].managerData?.components).toBeUndefined(); }); it('ignores system manifests without a version', () => { @@ -71,7 +71,7 @@ describe('modules/manager/flux/extract', () => { loadFixture('release.yaml'), 'release.yaml' ); - expect(result.deps[0].skipReason).toBe('unknown-registry'); + expect(result?.deps[0].skipReason).toBe('unknown-registry'); }); it('ignores HelmRelease resources without an apiVersion', () => { @@ -93,7 +93,7 @@ kind: HelmRepository `, 'test.yaml' ); - expect(result.deps[0].skipReason).toBe('unknown-registry'); + expect(result?.deps[0].skipReason).toBe('unknown-registry'); }); it('ignores HelmRelease resources without a chart name', () => { @@ -138,7 +138,7 @@ spec: `, 'test.yaml' ); - expect(result.deps[0].skipReason).toBe('unknown-registry'); + expect(result?.deps[0].skipReason).toBe('unknown-registry'); }); it('does not match HelmRelease resources without a sourceRef', () => { @@ -157,7 +157,7 @@ spec: `, 'test.yaml' ); - expect(result.deps[0].skipReason).toBe('unknown-registry'); + expect(result?.deps[0].skipReason).toBe('unknown-registry'); }); it('does not match HelmRelease resources without a namespace', () => { @@ -177,7 +177,7 @@ spec: `, 'test.yaml' ); - expect(result.deps[0].skipReason).toBe('unknown-registry'); + expect(result?.deps[0].skipReason).toBe('unknown-registry'); }); it('ignores HelmRepository resources without a namespace', () => { @@ -191,7 +191,7 @@ metadata: `, 'test.yaml' ); - expect(result.deps[0].skipReason).toBe('unknown-registry'); + expect(result?.deps[0].skipReason).toBe('unknown-registry'); }); it('ignores HelmRepository resources without a URL', () => { @@ -206,7 +206,7 @@ metadata: `, 'test.yaml' ); - expect(result.deps[0].skipReason).toBe('unknown-registry'); + expect(result?.deps[0].skipReason).toBe('unknown-registry'); }); it('ignores resources of an unknown kind', () => { diff --git a/lib/modules/manager/fvm/extract.spec.ts b/lib/modules/manager/fvm/extract.spec.ts index 129f6ead627f702f1b95050fc7d23e6ecbb1b01c..a078fef294d6464ff773e9eb0c05d3a176eb6ba7 100644 --- a/lib/modules/manager/fvm/extract.spec.ts +++ b/lib/modules/manager/fvm/extract.spec.ts @@ -28,7 +28,7 @@ describe('modules/manager/fvm/extract', () => { '{"flutterSdkVersion": "2.10.1", "flavors": {}}', packageFile ); - expect(res.deps).toEqual([ + expect(res?.deps).toEqual([ { currentValue: '2.10.1', datasource: 'flutter-version', @@ -43,7 +43,7 @@ describe('modules/manager/fvm/extract', () => { '{"flutterSdkVersion": "stable", "flavors": {}}', packageFile ); - expect(res.deps).toEqual([ + expect(res?.deps).toEqual([ { currentValue: 'stable', datasource: 'flutter-version', diff --git a/lib/modules/manager/git-submodules/artifact.spec.ts b/lib/modules/manager/git-submodules/artifact.spec.ts index 806db009b7297654d1e8bcf5dbdeffb72cc3f840..a9e90da76f8a73d1c86c05798929e2dad40022c4 100644 --- a/lib/modules/manager/git-submodules/artifact.spec.ts +++ b/lib/modules/manager/git-submodules/artifact.spec.ts @@ -1,4 +1,4 @@ -import updateArtifacts from './artifacts'; +import { updateArtifacts } from '.'; describe('modules/manager/git-submodules/artifact', () => { describe('updateArtifacts()', () => { diff --git a/lib/modules/manager/git-submodules/extract.spec.ts b/lib/modules/manager/git-submodules/extract.spec.ts index fd44c667e35934dfab075d5be997d9bdd33e3333..020c86bee4c623c0c65ba9ab158ad01273f14b40 100644 --- a/lib/modules/manager/git-submodules/extract.spec.ts +++ b/lib/modules/manager/git-submodules/extract.spec.ts @@ -1,10 +1,10 @@ +import is from '@sindresorhus/is'; import { mock } from 'jest-mock-extended'; -import _simpleGit, { Response, SimpleGit } from 'simple-git'; -import { partial } from '../../../../test/util'; +import _simpleGit, { Response, SimpleGit, TaskOptions } from 'simple-git'; import { GlobalConfig } from '../../../config/global'; import * as hostRules from '../../../util/host-rules'; import type { PackageFile } from '../types'; -import extractPackageFile from './extract'; +import { extractPackageFile } from '.'; jest.mock('simple-git'); const simpleGit: jest.Mock<Partial<SimpleGit>> = _simpleGit as never; @@ -18,27 +18,28 @@ describe('modules/manager/git-submodules/extract', () => { simpleGit.mockImplementation((basePath: string) => { const git = Git(basePath); return { - subModule() { - return partial<Response<string>>( - Promise.resolve('4b825dc642cb6eb9a060e54bf8d69288fbee4904') - ); + subModule(): Response<string> { + return Promise.resolve( + '4b825dc642cb6eb9a060e54bf8d69288fbee4904' + ) as Response<string>; }, - raw(options: string | string[]): Response<string> { - if (options.includes('remote.origin.url')) { - return partial<Response<string>>( - Promise.resolve('https://github.com/renovatebot/renovate.git') - ); + raw(options: string | string[] | TaskOptions): Response<string> { + if ( + (is.string(options) || is.array(options, is.string)) && + options.includes('remote.origin.url') + ) { + return Promise.resolve( + 'https://github.com/renovatebot/renovate.git' + ) as Response<string>; } return git.raw(options); }, listRemote(): Response<string> { - return partial<Response<string>>( - Promise.resolve( - 'ref: refs/heads/main HEAD\n5701164b9f5edba1f6ca114c491a564ffb55a964 HEAD' - ) - ); + return Promise.resolve( + 'ref: refs/heads/main HEAD\n5701164b9f5edba1f6ca114c491a564ffb55a964 HEAD' + ) as Response<string>; }, - ...mock<SimpleGit>(), + ...mock<Omit<SimpleGit, 'subModule' | 'raw' | 'listRemote'>>(), }; }); }); @@ -47,18 +48,18 @@ describe('modules/manager/git-submodules/extract', () => { it('extracts submodules', async () => { GlobalConfig.set({ localDir: `${__dirname}/__fixtures__` }); hostRules.add({ matchHost: 'github.com', token: '123test' }); - let res: PackageFile; + let res: PackageFile | null; expect(await extractPackageFile('', '.gitmodules.1', {})).toBeNull(); res = await extractPackageFile('', '.gitmodules.2', {}); - expect(res.deps).toHaveLength(1); - expect(res.deps[0].currentValue).toBe('main'); + expect(res?.deps).toHaveLength(1); + expect(res?.deps[0].currentValue).toBe('main'); res = await extractPackageFile('', '.gitmodules.3', {}); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toHaveLength(1); res = await extractPackageFile('', '.gitmodules.4', {}); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toHaveLength(1); res = await extractPackageFile('', '.gitmodules.5', {}); - expect(res.deps).toHaveLength(3); - expect(res.deps[2].packageName).toBe( + expect(res?.deps).toHaveLength(3); + expect(res?.deps[2].packageName).toBe( 'https://github.com/renovatebot/renovate-config.git' ); }); diff --git a/lib/modules/manager/git-submodules/update.spec.ts b/lib/modules/manager/git-submodules/update.spec.ts index e3b5fb3ff4077663023ee0843eac24d440a10b35..a9ef0700134f89bd504904914995be4de04c9ba2 100644 --- a/lib/modules/manager/git-submodules/update.spec.ts +++ b/lib/modules/manager/git-submodules/update.spec.ts @@ -4,7 +4,7 @@ import { join } from 'upath'; import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; import type { Upgrade } from '../types'; -import updateDependency from './update'; +import { updateDependency } from '.'; jest.mock('simple-git'); const simpleGit: jest.Mock<Partial<SimpleGit>> = _simpleGit as never; @@ -44,10 +44,10 @@ describe('modules/manager/git-submodules/update', () => { it('returns content on update', async () => { simpleGit.mockReturnValue({ submoduleUpdate() { - return Promise.resolve(null) as Response<string>; + return Promise.resolve('') as Response<string>; }, checkout() { - return Promise.resolve(null) as Response<string>; + return Promise.resolve('') as Response<string>; }, }); const update = await updateDependency({ diff --git a/lib/modules/manager/github-actions/extract.spec.ts b/lib/modules/manager/github-actions/extract.spec.ts index 3dde39333118142c7e99352e17b054491843952d..55ce36032ce41588406cc14b340ffbdf8f1b582f 100644 --- a/lib/modules/manager/github-actions/extract.spec.ts +++ b/lib/modules/manager/github-actions/extract.spec.ts @@ -1,5 +1,5 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/github-actions/extract', () => { describe('extractPackageFile()', () => { @@ -9,21 +9,23 @@ describe('modules/manager/github-actions/extract', () => { it('extracts multiple docker image lines from yaml configuration file', () => { const res = extractPackageFile(Fixtures.get('workflow_1.yml')); - expect(res.deps).toMatchSnapshot(); - expect(res.deps.filter((d) => d.datasource === 'docker')).toHaveLength(2); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps.filter((d) => d.datasource === 'docker')).toHaveLength( + 2 + ); }); it('extracts multiple action tag lines from yaml configuration file', () => { const res = extractPackageFile(Fixtures.get('workflow_2.yml')); - expect(res.deps).toMatchSnapshot(); + expect(res?.deps).toMatchSnapshot(); expect( - res.deps.filter((d) => d.datasource === 'github-tags') + res?.deps.filter((d) => d.datasource === 'github-tags') ).toHaveLength(8); }); it('extracts multiple action tag lines with double quotes and comments', () => { const res = extractPackageFile(Fixtures.get('workflow_3.yml')); - expect(res.deps).toMatchSnapshot([ + expect(res?.deps).toMatchSnapshot([ { currentValue: 'v0.13.1', datasource: 'github-tags', @@ -77,7 +79,7 @@ describe('modules/manager/github-actions/extract', () => { uses: "actions/setup-java@v2"`; const res = extractPackageFile(yamlContent); - expect(res.deps).toMatchObject([ + expect(res?.deps).toMatchObject([ { depName: 'actions/setup-node', commitMessageTopic: '{{{depName}}} action', diff --git a/lib/modules/manager/gitlabci-include/extract.spec.ts b/lib/modules/manager/gitlabci-include/extract.spec.ts index 1a384e662a359a9453f818b77fa03e444d8358ea..4cd1c60567b2002cd5c0c8f12f3278acc77e9370 100644 --- a/lib/modules/manager/gitlabci-include/extract.spec.ts +++ b/lib/modules/manager/gitlabci-include/extract.spec.ts @@ -1,6 +1,6 @@ import { loadFixture } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; const yamlFileMultiConfig = loadFixture('gitlab-ci.1.yaml'); const yamlFileSingleConfig = loadFixture('gitlab-ci.2.yaml'); @@ -19,14 +19,14 @@ describe('modules/manager/gitlabci-include/extract', () => { it('extracts single include block', () => { const res = extractPackageFile(yamlFileSingleConfig); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(1); }); it('extracts multiple include blocks', () => { const res = extractPackageFile(yamlFileMultiConfig); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(3); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(3); }); it('normalizes configured endpoints', () => { @@ -38,7 +38,7 @@ describe('modules/manager/gitlabci-include/extract', () => { for (const endpoint of endpoints) { GlobalConfig.set({ platform: 'gitlab', endpoint }); const res = extractPackageFile(yamlFileMultiConfig); - expect(res.deps[0].registryUrls[0]).toBe('http://gitlab.test'); + expect(res?.deps[0].registryUrls).toEqual(['http://gitlab.test']); } }); }); diff --git a/lib/modules/manager/gitlabci/extract.spec.ts b/lib/modules/manager/gitlabci/extract.spec.ts index 16d19ea37b9e593f6e879e58ce9f44a5b5500f64..fb66a99062ed8db6b1a319f6236ca96459c9d446 100644 --- a/lib/modules/manager/gitlabci/extract.spec.ts +++ b/lib/modules/manager/gitlabci/extract.spec.ts @@ -45,7 +45,7 @@ describe('modules/manager/gitlabci/extract', () => { expect(res).toHaveLength(3); const deps: PackageDependency[] = []; - res.forEach((e) => { + res?.forEach((e) => { e.deps.forEach((d) => { deps.push(d); }); @@ -59,7 +59,7 @@ describe('modules/manager/gitlabci/extract', () => { ]); expect(res).toMatchSnapshot(); expect(res).toHaveLength(1); - expect(res[0].deps).toHaveLength(3); + expect(res?.[0].deps).toHaveLength(3); }); it('extracts multiple named services', async () => { @@ -68,7 +68,7 @@ describe('modules/manager/gitlabci/extract', () => { ]); expect(res).toMatchSnapshot(); expect(res).toHaveLength(1); - expect(res[0].deps).toHaveLength(10); + expect(res?.[0].deps).toHaveLength(10); }); it('extracts multiple image lines', async () => { @@ -79,14 +79,16 @@ describe('modules/manager/gitlabci/extract', () => { expect(res).toHaveLength(1); const deps: PackageDependency[] = []; - res.forEach((e) => { + res?.forEach((e) => { e.deps.forEach((d) => { deps.push(d); }); }); expect(deps).toHaveLength(8); - expect(deps.some((dep) => dep.currentValue.includes("'"))).toBeFalse(); + // TODO #7154 + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + expect(deps.some((dep) => dep.currentValue!.includes("'"))).toBeFalse(); }); it('extracts multiple image lines with comments', async () => { @@ -97,7 +99,7 @@ describe('modules/manager/gitlabci/extract', () => { expect(res).toHaveLength(1); const deps: PackageDependency[] = []; - res.forEach((e) => { + res?.forEach((e) => { e.deps.forEach((d) => { deps.push(d); }); @@ -177,7 +179,7 @@ describe('modules/manager/gitlabci/extract', () => { - name: $CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX/other/image1:1.0.0 alias: imagealias1 `); - expect(res.deps).toEqual([ + expect(res?.deps).toEqual([ { autoReplaceStringTemplate: '${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/' + diff --git a/lib/modules/manager/gomod/artifacts.spec.ts b/lib/modules/manager/gomod/artifacts.spec.ts index cae9a08625d78d30f99489e0f37f5807b766dbce..e9e28f0f830d7b02387c784f70af2bd972965b93 100644 --- a/lib/modules/manager/gomod/artifacts.spec.ts +++ b/lib/modules/manager/gomod/artifacts.spec.ts @@ -8,7 +8,7 @@ import * as docker from '../../../util/exec/docker'; import type { StatusResult } from '../../../util/git/types'; import * as _hostRules from '../../../util/host-rules'; import type { UpdateArtifactsConfig } from '../types'; -import * as gomod from './artifacts'; +import * as gomod from '.'; jest.mock('child_process'); jest.mock('../../../util/exec/env'); @@ -89,10 +89,11 @@ describe('modules/manager/gomod/artifacts', () => { it('returns null if unchanged', async () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ - modified: [], + modified: [] as string[], } as StatusResult); expect( @@ -108,7 +109,8 @@ describe('modules/manager/gomod/artifacts', () => { it('returns updated go.sum', async () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], @@ -165,7 +167,8 @@ describe('modules/manager/gomod/artifacts', () => { it('supports docker mode without credentials', async () => { GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], @@ -185,7 +188,8 @@ describe('modules/manager/gomod/artifacts', () => { it('supports global mode', async () => { GlobalConfig.set({ ...adminConfig, binarySource: 'global' }); fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], @@ -208,7 +212,8 @@ describe('modules/manager/gomod/artifacts', () => { token: 'some-token', }); fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], @@ -238,7 +243,8 @@ describe('modules/manager/gomod/artifacts', () => { }, ]); fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], @@ -292,7 +298,8 @@ describe('modules/manager/gomod/artifacts', () => { }, ]); fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], @@ -343,7 +350,8 @@ describe('modules/manager/gomod/artifacts', () => { }, ]); fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], @@ -403,7 +411,8 @@ describe('modules/manager/gomod/artifacts', () => { }, ]); fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], @@ -462,7 +471,8 @@ describe('modules/manager/gomod/artifacts', () => { }, ]); fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], @@ -537,7 +547,8 @@ describe('modules/manager/gomod/artifacts', () => { }, ]); fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], @@ -576,7 +587,8 @@ describe('modules/manager/gomod/artifacts', () => { GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); hostRules.find.mockReturnValueOnce({}); fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], @@ -603,7 +615,8 @@ describe('modules/manager/gomod/artifacts', () => { GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); hostRules.find.mockReturnValueOnce({}); fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], @@ -629,7 +642,8 @@ describe('modules/manager/gomod/artifacts', () => { it('catches errors', async () => { const execSnapshots = mockExecAll(exec); fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename fs.writeLocalFile.mockImplementationOnce(() => { throw new Error('This update totally doesnt work'); }); @@ -653,7 +667,8 @@ describe('modules/manager/gomod/artifacts', () => { it('updates import paths with gomodUpdateImportPaths', async () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum', 'main.go'], @@ -684,7 +699,8 @@ describe('modules/manager/gomod/artifacts', () => { it('skips updating import paths with gomodUpdateImportPaths on v0 to v1', async () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum', 'main.go'], @@ -713,7 +729,8 @@ describe('modules/manager/gomod/artifacts', () => { it('skips gomodTidy without gomodUpdateImportPaths on major update', async () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum', 'main.go'], @@ -740,7 +757,8 @@ describe('modules/manager/gomod/artifacts', () => { it('does not execute go mod tidy when none of gomodTidy and gomodUpdateImportPaths are set', async () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum', 'main.go'], @@ -766,7 +784,8 @@ describe('modules/manager/gomod/artifacts', () => { it('updates import paths with specific tool version from constraint', async () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum', 'main.go'], @@ -800,7 +819,8 @@ describe('modules/manager/gomod/artifacts', () => { it('updates import paths with latest tool version on invalid version constraint', async () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum', 'main.go'], @@ -834,7 +854,8 @@ describe('modules/manager/gomod/artifacts', () => { it('skips updating import paths for gopkg.in dependencies', async () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); - fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + // TODO: #7154 can be null + fs.readLocalFile.mockResolvedValueOnce(null as never); // vendor modules filename const execSnapshots = mockExecAll(exec); git.getRepoStatus.mockResolvedValueOnce({ modified: ['go.sum'], diff --git a/lib/modules/manager/gomod/extract.spec.ts b/lib/modules/manager/gomod/extract.spec.ts index 42d332dfe50c4f835ec68dd5a363859a41188308..9b5f274e510edd7178700b37e28f3ae9dcfb9730 100644 --- a/lib/modules/manager/gomod/extract.spec.ts +++ b/lib/modules/manager/gomod/extract.spec.ts @@ -1,5 +1,5 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; const gomod1 = Fixtures.get('1/go.mod'); const gomod2 = Fixtures.get('2/go.mod'); @@ -12,24 +12,24 @@ describe('modules/manager/gomod/extract', () => { }); it('extracts single-line requires', () => { - const res = extractPackageFile(gomod1).deps; + const res = extractPackageFile(gomod1)?.deps; expect(res).toMatchSnapshot(); expect(res).toHaveLength(8); - expect(res.filter((e) => e.skipReason)).toHaveLength(1); - expect(res.filter((e) => e.depType === 'replace')).toHaveLength(1); + expect(res?.filter((e) => e.skipReason)).toHaveLength(1); + expect(res?.filter((e) => e.depType === 'replace')).toHaveLength(1); }); it('extracts constraints', () => { const res = extractPackageFile(gomod3); expect(res).toMatchSnapshot(); - expect(res.constraints.go).toBe('^1.13'); + expect(res?.constraints?.go).toBe('^1.13'); }); it('extracts multi-line requires', () => { - const res = extractPackageFile(gomod2).deps; + const res = extractPackageFile(gomod2)?.deps; expect(res).toMatchSnapshot(); expect(res).toHaveLength(58); - expect(res.filter((e) => e.skipReason)).toHaveLength(0); + expect(res?.filter((e) => e.skipReason)).toHaveLength(0); }); }); }); diff --git a/lib/modules/manager/gomod/update.spec.ts b/lib/modules/manager/gomod/update.spec.ts index 0142d85ee990a6a77b2b0675e481dde63caf515d..fcb98a41470ca5b38057fe571606a40157a5b33f 100644 --- a/lib/modules/manager/gomod/update.spec.ts +++ b/lib/modules/manager/gomod/update.spec.ts @@ -1,6 +1,6 @@ import { Fixtures } from '../../../../test/fixtures'; import type { UpdateType } from '../../../config/types'; -import { updateDependency } from './update'; +import { updateDependency } from '.'; const gomod1 = Fixtures.get('1/go.mod'); const gomod2 = Fixtures.get('2/go.mod'); @@ -30,6 +30,7 @@ describe('modules/manager/gomod/update', () => { fileContent: gomod1, upgrade: upgrade1, }); + expect(res1).toBeString(); expect(res1).not.toEqual(gomod1); expect(res1).toContain(upgrade1.newValue); const upgrade2 = { @@ -39,7 +40,8 @@ describe('modules/manager/gomod/update', () => { depType: 'require', }; const res2 = updateDependency({ - fileContent: res1, + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + fileContent: res1!, upgrade: upgrade2, }); expect(res2).not.toEqual(res1); @@ -113,7 +115,11 @@ describe('modules/manager/gomod/update', () => { }); it('returns null if error', () => { - const res = updateDependency({ fileContent: null, upgrade: null }); + // TODO: #7154 bad test, uses invalid null to throwing nullref error + const res = updateDependency({ + fileContent: null as never, + upgrade: null as never, + }); expect(res).toBeNull(); }); @@ -302,7 +308,7 @@ describe('modules/manager/gomod/update', () => { it('should return null for replacement', () => { const res = updateDependency({ - fileContent: undefined, + fileContent: '', upgrade: { updateType: 'replacement' }, }); expect(res).toBeNull(); diff --git a/lib/modules/manager/gradle-wrapper/artifacts-real.spec.ts b/lib/modules/manager/gradle-wrapper/artifacts-real.spec.ts index 342cb73c06065af83c7876408bcb33a920bff91a..7f065643807a3abd5846018f71dbc0d1039f3282 100644 --- a/lib/modules/manager/gradle-wrapper/artifacts-real.spec.ts +++ b/lib/modules/manager/gradle-wrapper/artifacts-real.spec.ts @@ -111,7 +111,7 @@ describe('modules/manager/gradle-wrapper/artifacts-real', () => { }); expect(result).toHaveLength(1); - expect(result[0].artifactError).toBeUndefined(); + expect(result?.[0].artifactError).toBeUndefined(); await compareFile( 'gradle/wrapper/gradle-wrapper.properties', @@ -120,9 +120,11 @@ describe('modules/manager/gradle-wrapper/artifacts-real', () => { }); it('up to date', async () => { - git.getRepoStatus.mockResolvedValue({ - modified: [], - } as StatusResult); + git.getRepoStatus.mockResolvedValue( + partial<StatusResult>({ + modified: [], + }) + ); const res = await gradleWrapper.updateArtifacts({ packageFileName: 'gradle/wrapper/gradle-wrapper.properties', @@ -157,10 +159,10 @@ describe('modules/manager/gradle-wrapper/artifacts-real', () => { config, }); - expect(res[0].artifactError.lockFile).toBe( + expect(res?.[0].artifactError?.lockFile).toBe( 'gradle/wrapper/gradle-wrapper.properties' ); - expect(res[0].artifactError.stderr).toBe('failed'); + expect(res?.[0].artifactError?.stderr).toBe('failed'); // 5.6.4 => 5.6.4 (updates execs) - unexpected behavior (looks like a bug in Gradle) for (const file of ['gradle/wrapper/gradle-wrapper.properties']) { @@ -184,11 +186,11 @@ describe('modules/manager/gradle-wrapper/artifacts-real', () => { config, }); - expect(res[0].artifactError.lockFile).toBe( + expect(res?.[0].artifactError?.lockFile).toBe( 'gradle/wrapper/gradle-wrapper.properties' ); - expect(res[0].artifactError.stderr).not.toBeNull(); - expect(res[0].artifactError.stderr).not.toBe(''); + expect(res?.[0].artifactError?.stderr).not.toBeNull(); + expect(res?.[0].artifactError?.stderr).not.toBe(''); // 5.6.4 => 5.6.4 (updates execs) - unexpected behavior (looks like a bug in Gradle) for (const file of ['gradle/wrapper/gradle-wrapper.properties']) { @@ -201,7 +203,7 @@ describe('modules/manager/gradle-wrapper/artifacts-real', () => { const res = await gradleWrapper.updateArtifacts({ packageFileName: 'gradle-wrapper.properties', updatedDeps: [], - newPackageFileContent: undefined, + newPackageFileContent: undefined as never, // TODO #7154 config: {}, }); @@ -240,11 +242,13 @@ describe('modules/manager/gradle-wrapper/artifacts-real', () => { }); expect(result).toHaveLength(1); - expect(result[0].artifactError).toBeUndefined(); + expect(result?.[0].artifactError).toBeUndefined(); expect( await readString( - adminConfig.localDir, + // TODO #7154 + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + adminConfig.localDir!, `gradle/wrapper/gradle-wrapper.properties` ) ).toEqual(newContent); diff --git a/lib/modules/manager/gradle-wrapper/artifacts.spec.ts b/lib/modules/manager/gradle-wrapper/artifacts.spec.ts index 0ae9358128664895708ae34d6de8b14cba9157a9..9551f9d27e6ffd67a23b4d811e3157d6ce705a83 100644 --- a/lib/modules/manager/gradle-wrapper/artifacts.spec.ts +++ b/lib/modules/manager/gradle-wrapper/artifacts.spec.ts @@ -102,7 +102,7 @@ describe('modules/manager/gradle-wrapper/artifacts', () => { const res = await gradleWrapper.updateArtifacts({ packageFileName: 'gradle-wrapper.properties', updatedDeps: [], - newPackageFileContent: undefined, + newPackageFileContent: '', config: {}, }); @@ -155,7 +155,7 @@ describe('modules/manager/gradle-wrapper/artifacts', () => { }); expect(result).toHaveLength(1); - expect(result[0].artifactError).toBeUndefined(); + expect(result?.[0].artifactError).toBeUndefined(); expect(execSnapshots).toMatchSnapshot(); }); diff --git a/lib/modules/manager/gradle-wrapper/extract.spec.ts b/lib/modules/manager/gradle-wrapper/extract.spec.ts index 7d249adef8b695e3e778832351a085c14aea91f6..6d642f77dc361221ea99ee8ec080a631a7dfd797 100644 --- a/lib/modules/manager/gradle-wrapper/extract.spec.ts +++ b/lib/modules/manager/gradle-wrapper/extract.spec.ts @@ -1,5 +1,5 @@ import { loadFixture } from '../../../../test/util'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; const typeBinFileContent = loadFixture('gradle-wrapper-bin.properties'); const typeAllFileContent = loadFixture('gradle-wrapper-all.properties'); @@ -32,7 +32,7 @@ describe('modules/manager/gradle-wrapper/extract', () => { it('extracts version for property file with distribution type "bin" in distributionUrl', () => { const res = extractPackageFile(typeBinFileContent); - expect(res.deps).toEqual([ + expect(res?.deps).toEqual([ { currentValue: '4.8', replaceString: @@ -46,7 +46,7 @@ describe('modules/manager/gradle-wrapper/extract', () => { it('extracts version for property file with distribution type "all" in distributionUrl', () => { const res = extractPackageFile(typeAllFileContent); - expect(res.deps).toEqual([ + expect(res?.deps).toEqual([ { currentValue: '4.10.3', replaceString: @@ -60,7 +60,7 @@ describe('modules/manager/gradle-wrapper/extract', () => { it('extracts version for property file with prerelease version in distributionUrl', () => { const res = extractPackageFile(prereleaseVersionFileContent); - expect(res.deps).toEqual([ + expect(res?.deps).toEqual([ { currentValue: '7.0-milestone-1', replaceString: @@ -74,7 +74,7 @@ describe('modules/manager/gradle-wrapper/extract', () => { it('extracts version for property file with unnecessary whitespace in distributionUrl', () => { const res = extractPackageFile(whitespacePropertiesFile); - expect(res.deps).toEqual([ + expect(res?.deps).toEqual([ { currentValue: '4.10.3', replaceString: @@ -88,7 +88,7 @@ describe('modules/manager/gradle-wrapper/extract', () => { it('extracts version for property file with custom distribution of type "bin" in distributionUrl', () => { const res = extractPackageFile(customTypeBinFileContent); - expect(res.deps).toEqual([ + expect(res?.deps).toEqual([ { currentValue: '1.3.7', replaceString: @@ -102,7 +102,7 @@ describe('modules/manager/gradle-wrapper/extract', () => { it('extracts version for property file with custom distribution of type "all" in distributionUrl', () => { const res = extractPackageFile(customTypeAllFileContent); - expect(res.deps).toEqual([ + expect(res?.deps).toEqual([ { currentValue: '6.6.6', replaceString: diff --git a/lib/modules/manager/gradle-wrapper/util.spec.ts b/lib/modules/manager/gradle-wrapper/util.spec.ts index abdda4ab6e4dac233d4f3a52d67138440bc9898a..108d2dde6f71019498e46aebb720e2fa0995d576 100644 --- a/lib/modules/manager/gradle-wrapper/util.spec.ts +++ b/lib/modules/manager/gradle-wrapper/util.spec.ts @@ -4,12 +4,12 @@ import { extractGradleVersion, getJavaContraint } from './utils'; describe('modules/manager/gradle-wrapper/util', () => { describe('getJavaContraint()', () => { it('return null for global mode', () => { - expect(getJavaContraint(undefined)).toBeNull(); + expect(getJavaContraint('6')).toBeNull(); }); it('return ^11.0.0 for docker mode and undefined gradle', () => { GlobalConfig.set({ binarySource: 'docker' }); - expect(getJavaContraint(undefined)).toBe('^11.0.0'); + expect(getJavaContraint('')).toBe('^11.0.0'); }); it('return ^8.0.0 for docker gradle < 5', () => { @@ -30,7 +30,8 @@ describe('modules/manager/gradle-wrapper/util', () => { describe('extractGradleVersion()', () => { it('works for undefined', () => { - expect(extractGradleVersion(undefined)).toBeNull(); + // TODO #7154 + expect(extractGradleVersion(undefined as never)).toBeNull(); }); }); }); diff --git a/lib/modules/manager/gradle/extract.spec.ts b/lib/modules/manager/gradle/extract.spec.ts index 22f0f5663024122218334569a04b734754573828..88ad473a74ccd3a21962be4658ccbc0f1b9e22aa 100644 --- a/lib/modules/manager/gradle/extract.spec.ts +++ b/lib/modules/manager/gradle/extract.spec.ts @@ -85,7 +85,7 @@ describe('modules/manager/gradle/extract', () => { mockFs({ 'gradle.properties': 'baz=1.2.3', 'build.gradle': 'url "https://example.com"; "foo:bar:$baz@zip"', - 'settings.gradle': null, + 'settings.gradle': null as never, // TODO: #7154 }); const res = await extractAllPackageFiles({} as ExtractConfig, [ diff --git a/lib/modules/manager/gradle/parser.spec.ts b/lib/modules/manager/gradle/parser.spec.ts index 156b5f8de93ac983868747015f35d9cce7cb8f28..e518d26c857188778ebff43053f8def429d65de8 100644 --- a/lib/modules/manager/gradle/parser.spec.ts +++ b/lib/modules/manager/gradle/parser.spec.ts @@ -140,7 +140,9 @@ describe('modules/manager/gradle/parser', () => { const { deps } = parseGradle(content); const [res] = deps; const idx = content - .slice(res.managerData.fileReplacePosition) + // TODO #7154 + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + .slice(res.managerData!.fileReplacePosition) .indexOf('1.2.3'); expect(idx).toBe(0); }); @@ -149,7 +151,9 @@ describe('modules/manager/gradle/parser', () => { const content = Fixtures.get('build.gradle.example1'); const { deps } = parseGradle(content, {}, 'build.gradle'); const replacementIndices = deps.map(({ managerData, currentValue }) => - content.slice(managerData.fileReplacePosition).indexOf(currentValue) + // TODO #7154 + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + content.slice(managerData!.fileReplacePosition).indexOf(currentValue!) ); expect(replacementIndices.every((idx) => idx === 0)).toBeTrue(); expect(deps).toMatchSnapshot(); diff --git a/lib/modules/manager/gradle/tokenizer.spec.ts b/lib/modules/manager/gradle/tokenizer.spec.ts index ff5cd3519aab5caaa6fe5a804642afbc71677ea6..1095e7f659608365cc589cba385f0a20bda394ad 100644 --- a/lib/modules/manager/gradle/tokenizer.spec.ts +++ b/lib/modules/manager/gradle/tokenizer.spec.ts @@ -1,7 +1,7 @@ import { TokenType } from './common'; import { extractRawTokens, tokenize } from './tokenizer'; -function tokenTypes(input): string[] { +function tokenTypes(input: string): string[] { return extractRawTokens(input).map((token) => token.type); } diff --git a/lib/modules/manager/gradle/update.spec.ts b/lib/modules/manager/gradle/update.spec.ts index 7a652f40f1dc264bea3de67948f80ebe36671bed..37433305245e62432bb2e1e6ccac565668bb21b1 100644 --- a/lib/modules/manager/gradle/update.spec.ts +++ b/lib/modules/manager/gradle/update.spec.ts @@ -78,7 +78,7 @@ describe('modules/manager/gradle/update', () => { it('should return null for replacement', () => { const res = updateDependency({ - fileContent: undefined, + fileContent: '', upgrade: { updateType: 'replacement' }, }); expect(res).toBeNull(); diff --git a/lib/modules/manager/gradle/utils.spec.ts b/lib/modules/manager/gradle/utils.spec.ts index 54be14d032618d1b8d4947b5bf69bbbf98d1fe35..fb67a13b482e6ec2b3cf39b93cbcce59fc06cbd6 100644 --- a/lib/modules/manager/gradle/utils.spec.ts +++ b/lib/modules/manager/gradle/utils.spec.ts @@ -1,4 +1,5 @@ import { TokenType } from './common'; +import type { VariableRegistry } from './types'; import { getVars, interpolateString, @@ -176,7 +177,7 @@ describe('modules/manager/gradle/utils', () => { }); it('getVars', () => { - const registry = { + const registry: VariableRegistry = { [toAbsolutePath('/foo')]: { foo: { key: 'foo', value: 'FOO' } as never, bar: { key: 'bar', value: 'BAR' } as never, diff --git a/lib/modules/manager/gradle/utils.ts b/lib/modules/manager/gradle/utils.ts index a3c1febfae35c1c669d6e6c57ac05df42b1610f6..bcaad4c15ecef4e6fcc04a9f857b1bce6f4b0590 100644 --- a/lib/modules/manager/gradle/utils.ts +++ b/lib/modules/manager/gradle/utils.ts @@ -17,7 +17,9 @@ const versionLikeRegex = regEx('^(?<version>[-.\\[\\](),a-zA-Z0-9+]+)'); // Extracts version-like and range-like strings // from the beginning of input -export function versionLikeSubstring(input: string): string | null { +export function versionLikeSubstring( + input: string | null | undefined +): string | null { const match = input ? versionLikeRegex.exec(input) : null; return match?.groups?.version ?? null; } diff --git a/lib/modules/manager/helm-requirements/extract.spec.ts b/lib/modules/manager/helm-requirements/extract.spec.ts index ad90c0c4387e09add0f4b577b683b3397f53816d..ebb9748a1916e4fbf87d6f4157a995ce0e579db3 100644 --- a/lib/modules/manager/helm-requirements/extract.spec.ts +++ b/lib/modules/manager/helm-requirements/extract.spec.ts @@ -1,5 +1,5 @@ import { fs } from '../../../../test/util'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; jest.mock('../../../util/fs'); @@ -31,9 +31,9 @@ describe('modules/manager/helm-requirements/extract', () => { }, }); expect(result).not.toBeNull(); - expect(typeof result.deps[0]?.currentValue).toBe('string'); + expect(result?.deps[0]?.currentValue).toBeString(); expect(result).toMatchSnapshot(); - expect(result.deps.every((dep) => dep.skipReason)).toBe(true); + expect(result?.deps.every((dep) => dep.skipReason)).toBe(true); }); it('skips invalid registry urls', () => { @@ -63,7 +63,7 @@ describe('modules/manager/helm-requirements/extract', () => { }); expect(result).not.toBeNull(); expect(result).toMatchSnapshot(); - expect(result.deps.every((dep) => dep.skipReason)).toBe(true); + expect(result?.deps.every((dep) => dep.skipReason)).toBe(true); }); it('parses simple requirements.yaml correctly', () => { @@ -140,7 +140,7 @@ describe('modules/manager/helm-requirements/extract', () => { }); expect(result).not.toBeNull(); expect(result).toMatchSnapshot(); - expect(result.deps.every((dep) => dep.skipReason)).toBe(false); + expect(result?.deps.every((dep) => dep.skipReason)).toBe(false); }); it('skips local dependencies', () => { diff --git a/lib/modules/manager/helm-values/extract.spec.ts b/lib/modules/manager/helm-values/extract.spec.ts index 9ab2ef5afc872ebf382d908a24ce7c7b89703281..9ba7962e3bb05baa6025406a2026bfb28414f323 100644 --- a/lib/modules/manager/helm-values/extract.spec.ts +++ b/lib/modules/manager/helm-values/extract.spec.ts @@ -1,5 +1,5 @@ import { loadFixture } from '../../../../test/util'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; const helmDefaultChartInitValues = loadFixture( 'default_chart_init_values.yaml' @@ -25,11 +25,6 @@ describe('modules/manager/helm-values/extract', () => { expect(result).toBeNull(); }); - it('returns null for no file content', () => { - const result = extractPackageFile(null); - expect(result).toBeNull(); - }); - it('extracts from values.yaml correctly with same structure as "helm create"', () => { const result = extractPackageFile(helmDefaultChartInitValues); expect(result).toMatchSnapshot({ @@ -45,7 +40,7 @@ describe('modules/manager/helm-values/extract', () => { it('extracts from complex values file correctly"', () => { const result = extractPackageFile(helmMultiAndNestedImageValues); expect(result).toMatchSnapshot(); - expect(result.deps).toHaveLength(5); + expect(result?.deps).toHaveLength(5); }); }); }); diff --git a/lib/modules/manager/helmfile/extract.spec.ts b/lib/modules/manager/helmfile/extract.spec.ts index 89f4560a2b546e5097bff042e3c0f3deb7053d9c..e304e919d5bef701f65bf8f2dd6c88007b2983cc 100644 --- a/lib/modules/manager/helmfile/extract.spec.ts +++ b/lib/modules/manager/helmfile/extract.spec.ts @@ -57,7 +57,7 @@ describe('modules/manager/helmfile/extract', () => { }); expect(result).not.toBeNull(); expect(result).toMatchSnapshot(); - expect(result.deps.every((dep) => dep.skipReason)).toBeTruthy(); + expect(result?.deps.every((dep) => dep.skipReason)).toBeTruthy(); }); it('skip templetized release with invalid characters', () => { @@ -112,7 +112,7 @@ describe('modules/manager/helmfile/extract', () => { }); expect(result).not.toBeNull(); expect(result).toMatchSnapshot(); - expect(result.deps.every((dep) => dep.skipReason)).toBeTruthy(); + expect(result?.deps.every((dep) => dep.skipReason)).toBeTruthy(); }); it('skip chart with unknown repository', () => { @@ -133,7 +133,7 @@ describe('modules/manager/helmfile/extract', () => { }); expect(result).not.toBeNull(); expect(result).toMatchSnapshot(); - expect(result.deps.every((dep) => dep.skipReason)).toBeTruthy(); + expect(result?.deps.every((dep) => dep.skipReason)).toBeTruthy(); }); it('skip chart with special character in the name', () => { @@ -157,7 +157,7 @@ describe('modules/manager/helmfile/extract', () => { }); expect(result).not.toBeNull(); expect(result).toMatchSnapshot(); - expect(result.deps.every((dep) => dep.skipReason)).toBeTruthy(); + expect(result?.deps.every((dep) => dep.skipReason)).toBeTruthy(); }); it('skip chart that does not have specified version', () => { @@ -177,7 +177,7 @@ describe('modules/manager/helmfile/extract', () => { }); expect(result).not.toBeNull(); expect(result).toMatchSnapshot(); - expect(result.deps.every((dep) => dep.skipReason)).toBeTruthy(); + expect(result?.deps.every((dep) => dep.skipReason)).toBeTruthy(); }); it('parses multidoc yaml', () => { diff --git a/lib/modules/manager/helmsman/extract.spec.ts b/lib/modules/manager/helmsman/extract.spec.ts index 26bc93fa0bc09386abe50142bec59b6eef696337..b291909823df1824ded38fa4d97a6ec1cef96d45 100644 --- a/lib/modules/manager/helmsman/extract.spec.ts +++ b/lib/modules/manager/helmsman/extract.spec.ts @@ -24,8 +24,8 @@ describe('modules/manager/helmsman/extract', () => { const fileName = 'helmsman.yaml'; const result = extractPackageFile(multiDepFile, fileName, {}); expect(result).not.toBeNull(); - expect(result.deps).toHaveLength(10); - expect(result.deps.filter((value) => value.skipReason)).toHaveLength(5); + expect(result?.deps).toHaveLength(10); + expect(result?.deps.filter((value) => value.skipReason)).toHaveLength(5); expect(result).toMatchSnapshot(); }); }); diff --git a/lib/modules/manager/helmv3/artifacts.spec.ts b/lib/modules/manager/helmv3/artifacts.spec.ts index f23943b10bcb86c95192a65f3dc847d74012814f..2d6fb9fa72ba9a00e16e6cd2414ff90bb098d595 100644 --- a/lib/modules/manager/helmv3/artifacts.spec.ts +++ b/lib/modules/manager/helmv3/artifacts.spec.ts @@ -8,7 +8,7 @@ import * as docker from '../../../util/exec/docker'; import * as hostRules from '../../../util/host-rules'; import * as _datasource from '../../datasource'; import type { UpdateArtifactsConfig } from '../types'; -import * as helmv3 from './artifacts'; +import * as helmv3 from '.'; jest.mock('child_process'); jest.mock('../../datasource'); diff --git a/lib/modules/manager/helmv3/extract.spec.ts b/lib/modules/manager/helmv3/extract.spec.ts index f97a2fd37142cecb9c4cb4b28499eade3c91dc5f..cc9d2d2025ad1f82326f492a9488260a976eec25 100644 --- a/lib/modules/manager/helmv3/extract.spec.ts +++ b/lib/modules/manager/helmv3/extract.spec.ts @@ -1,6 +1,6 @@ import { fs } from '../../../../test/util'; import { DockerDatasource } from '../../datasource/docker'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; jest.mock('../../../util/fs'); @@ -36,7 +36,7 @@ describe('modules/manager/helmv3/extract', () => { }); expect(result).not.toBeNull(); expect(result).toMatchSnapshot(); - expect(result.deps.every((dep) => dep.skipReason)).toBe(true); + expect(result?.deps.every((dep) => dep.skipReason)).toBe(true); }); it('parses simple Chart.yaml correctly', async () => { @@ -135,7 +135,7 @@ describe('modules/manager/helmv3/extract', () => { }); expect(result).not.toBeNull(); expect(result).toMatchSnapshot(); - expect(result.deps.every((dep) => dep.skipReason)).toBe(false); + expect(result?.deps.every((dep) => dep.skipReason)).toBe(false); }); it("doesn't fail if Chart.yaml is invalid", async () => { diff --git a/lib/modules/manager/helmv3/update.spec.ts b/lib/modules/manager/helmv3/update.spec.ts index 1dc8f0d72767cb56858c92c3c07c04860b0fbd43..c768f853de1fc6a2ba40921ff7c2fcbaaafb5b16 100644 --- a/lib/modules/manager/helmv3/update.spec.ts +++ b/lib/modules/manager/helmv3/update.spec.ts @@ -1,5 +1,5 @@ import { dump } from 'js-yaml'; -import * as helmv3Updater from './update'; +import * as helmv3Updater from '.'; describe('modules/manager/helmv3/update', () => { describe('.bumpPackageVersion()', () => { diff --git a/lib/modules/manager/helmv3/utils.spec.ts b/lib/modules/manager/helmv3/utils.spec.ts index f10244e72dc2a6f00f669eed1280369cefed91a1..05297684081945a87b6dbeba1852a749ae2ab6cb 100644 --- a/lib/modules/manager/helmv3/utils.spec.ts +++ b/lib/modules/manager/helmv3/utils.spec.ts @@ -41,14 +41,16 @@ describe('modules/manager/helmv3/utils', () => { }); it('return repository parameter if repository is null', () => { - const repository = resolveAlias(null, { + // TODO #7154 + const repository = resolveAlias(null as never, { anotherRepository: 'https://charts.helm.sh/stable', }); expect(repository).toBeNull(); }); it('return repository parameter if repository is undefined', () => { - const repository = resolveAlias(undefined, { + // TODO #7154 + const repository = resolveAlias(undefined as never, { anotherRepository: 'https://charts.helm.sh/stable', }); expect(repository).toBeUndefined(); @@ -57,12 +59,14 @@ describe('modules/manager/helmv3/utils', () => { describe('.isAlias()', () => { it('return false if repository is null', () => { - const repository = isAlias(null); + // TODO #7154 + const repository = isAlias(null as never); expect(repository).toBeFalse(); }); it('return false if repository is undefined', () => { - const repository = isAlias(undefined); + // TODO #7154 + const repository = isAlias(undefined as never); expect(repository).toBeFalse(); }); }); diff --git a/lib/modules/manager/homebrew/extract.spec.ts b/lib/modules/manager/homebrew/extract.spec.ts index 6922488ff9b0189e5a772cee92320f834d05f553..b2ed7d15672884f564d3184348b0bf9663369b43 100644 --- a/lib/modules/manager/homebrew/extract.spec.ts +++ b/lib/modules/manager/homebrew/extract.spec.ts @@ -1,5 +1,5 @@ import { loadFixture } from '../../../../test/util'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; const aalib = loadFixture('aalib.rb'); const aap = loadFixture('aap.rb'); @@ -12,35 +12,35 @@ describe('modules/manager/homebrew/extract', () => { it('skips sourceforge dependency 1', () => { const res = extractPackageFile(aalib); expect(res).not.toBeNull(); - expect(res.deps[0].skipReason).toBe('unsupported-url'); + expect(res?.deps[0].skipReason).toBe('unsupported-url'); expect(res).toMatchSnapshot(); }); it('skips sourceforge dependency 2', () => { const res = extractPackageFile(aap); expect(res).not.toBeNull(); - expect(res.deps[0].skipReason).toBe('unsupported-url'); + expect(res?.deps[0].skipReason).toBe('unsupported-url'); expect(res).toMatchSnapshot(); }); it('skips github dependency with wrong format', () => { const res = extractPackageFile(acmetool); expect(res).not.toBeNull(); - expect(res.deps[0].skipReason).toBe('unsupported-url'); + expect(res?.deps[0].skipReason).toBe('unsupported-url'); expect(res).toMatchSnapshot(); }); it('extracts "releases" github dependency', () => { const res = extractPackageFile(aide); expect(res).not.toBeNull(); - expect(res.deps[0].skipReason).toBeUndefined(); + expect(res?.deps[0].skipReason).toBeUndefined(); expect(res).toMatchSnapshot(); }); it('extracts "archive" github dependency', () => { const res = extractPackageFile(ibazel); expect(res).not.toBeNull(); - expect(res.deps[0].skipReason).toBeUndefined(); + expect(res?.deps[0].skipReason).toBeUndefined(); expect(res).toMatchSnapshot(); }); @@ -54,7 +54,7 @@ describe('modules/manager/homebrew/extract', () => { `; const res = extractPackageFile(content); expect(res).not.toBeNull(); - expect(res.deps[0].skipReason).toBeUndefined(); + expect(res?.deps[0].skipReason).toBeUndefined(); expect(res).toMatchSnapshot(); }); @@ -93,7 +93,7 @@ describe('modules/manager/homebrew/extract', () => { `; const res = extractPackageFile(content); expect(res).not.toBeNull(); - expect(res.deps[0].skipReason).toBe('unsupported-url'); + expect(res?.deps[0].skipReason).toBe('unsupported-url'); expect(res).toMatchSnapshot(); }); @@ -138,7 +138,7 @@ describe('modules/manager/homebrew/extract', () => { `; const res = extractPackageFile(content); expect(res).not.toBeNull(); - expect(res.deps[0].skipReason).toBe('invalid-sha256'); + expect(res?.deps[0].skipReason).toBe('invalid-sha256'); expect(res).toMatchSnapshot(); }); @@ -153,7 +153,7 @@ describe('modules/manager/homebrew/extract', () => { `; const res = extractPackageFile(content); expect(res).not.toBeNull(); - expect(res.deps[0].skipReason).toBe('invalid-sha256'); + expect(res?.deps[0].skipReason).toBe('invalid-sha256'); expect(res).toMatchSnapshot(); }); }); diff --git a/lib/modules/manager/homebrew/update.spec.ts b/lib/modules/manager/homebrew/update.spec.ts index a7f8a88ae2a971f52489d8c75fd0702614fbd09c..55ca50f1def7468fe74303af42900aa887bb7ccf 100644 --- a/lib/modules/manager/homebrew/update.spec.ts +++ b/lib/modules/manager/homebrew/update.spec.ts @@ -1,7 +1,7 @@ import { Readable } from 'stream'; import * as httpMock from '../../../../test/http-mock'; import { loadFixture } from '../../../../test/util'; -import { updateDependency } from './update'; +import { updateDependency } from '.'; const aide = loadFixture('aide.rb'); const ibazel = loadFixture('ibazel.rb'); diff --git a/lib/modules/manager/index.spec.ts b/lib/modules/manager/index.spec.ts index 1c646ff8f237ba99c9cda8938bcec39c50b2b7e6..914b2288e082c060ef34519b7851c085b8cf673b 100644 --- a/lib/modules/manager/index.spec.ts +++ b/lib/modules/manager/index.spec.ts @@ -18,7 +18,8 @@ describe('modules/manager/index', () => { it(`has valid supportedDatasources for ${m}`, () => { expect(supportedDatasources).toBeNonEmptyArray(); - supportedDatasources.every((d) => { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + supportedDatasources!.every((d) => { expect(datasources.includes(d)).toBeTrue(); }); }); @@ -62,7 +63,7 @@ describe('modules/manager/index', () => { expect(Array.from(mgrs.keys())).toEqual(Object.keys(loadedMgr)); for (const name of mgrs.keys()) { - const mgr = mgrs.get(name); + const mgr = mgrs.get(name)!; expect(validate(mgr)).toBeTrue(); } }); @@ -110,10 +111,10 @@ describe('modules/manager/index', () => { supportedDatasources: [], }); expect( - manager.extractPackageFile('unknown', null, 'filename', {}) + manager.extractPackageFile('unknown', '', 'filename', {}) ).toBeNull(); expect( - manager.extractPackageFile('dummy', null, 'filename', {}) + manager.extractPackageFile('dummy', '', 'filename', {}) ).toBeNull(); }); @@ -125,7 +126,7 @@ describe('modules/manager/index', () => { }); expect( - manager.extractPackageFile('dummy', null, 'filename', {}) + manager.extractPackageFile('dummy', '', 'filename', {}) ).not.toBeNull(); }); diff --git a/lib/modules/manager/jenkins/extract.spec.ts b/lib/modules/manager/jenkins/extract.spec.ts index 117bb71e90d66602c523a64b7715e71bcf4f2631..165bc1b101e61f7ff5da60921264fc7c762b8735 100644 --- a/lib/modules/manager/jenkins/extract.spec.ts +++ b/lib/modules/manager/jenkins/extract.spec.ts @@ -1,5 +1,5 @@ import { loadFixture } from '../../../../test/util'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; const invalidYamlFile = loadFixture('invalid.yaml'); @@ -28,14 +28,14 @@ describe('modules/manager/jenkins/extract', () => { it('extracts multiple image lines in text format', () => { const res = extractPackageFile(pluginsTextFile, 'path/file.txt'); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(6); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(6); }); it('extracts multiple image lines in yaml format', () => { const res = extractPackageFile(pluginsYamlFile, 'path/file.yml'); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(8); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(8); }); }); }); diff --git a/lib/modules/manager/jsonnet-bundler/artifacts.spec.ts b/lib/modules/manager/jsonnet-bundler/artifacts.spec.ts index e58a5dcc90352fe1a7275e53846e2a3fd0c9cf7d..c6c42160087efd51f3ae92c8254885a56a538454 100644 --- a/lib/modules/manager/jsonnet-bundler/artifacts.spec.ts +++ b/lib/modules/manager/jsonnet-bundler/artifacts.spec.ts @@ -1,6 +1,6 @@ import { join } from 'upath'; import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; -import { env, fs, git } from '../../../../test/util'; +import { env, fs, git, partial } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; import type { StatusResult } from '../../../util/git/types'; @@ -27,7 +27,7 @@ describe('modules/manager/jsonnet-bundler/artifacts', () => { }); it('returns null if jsonnetfile.lock does not exist', async () => { - fs.readLocalFile.mockResolvedValueOnce(null); + fs.readLocalFile.mockResolvedValueOnce(''); expect( await updateArtifacts({ packageFileName: 'jsonnetfile.json', @@ -41,14 +41,16 @@ describe('modules/manager/jsonnet-bundler/artifacts', () => { it('returns null if there are no changes', async () => { fs.readLocalFile.mockResolvedValueOnce('Current jsonnetfile.lock.json'); const execSnapshots = mockExecAll(exec); - git.getRepoStatus.mockResolvedValueOnce({ - modified: [], - not_added: [], - deleted: [], - isClean(): boolean { - return true; - }, - } as StatusResult); + git.getRepoStatus.mockResolvedValueOnce( + partial<StatusResult>({ + modified: [], + not_added: [], + deleted: [], + isClean(): boolean { + return true; + }, + }) + ); expect( await updateArtifacts({ packageFileName: 'jsonnetfile.json', diff --git a/lib/modules/manager/jsonnet-bundler/extract.spec.ts b/lib/modules/manager/jsonnet-bundler/extract.spec.ts index 3c0145c2f0578fbdd1b3a5f3933c18e79c674466..43d69003d5530b9854456570efb35539d6295318 100644 --- a/lib/modules/manager/jsonnet-bundler/extract.spec.ts +++ b/lib/modules/manager/jsonnet-bundler/extract.spec.ts @@ -1,12 +1,12 @@ -import { loadFixture } from '../../../../test/util'; +import { Fixtures } from '../../../../test/fixtures'; import { extractPackageFile } from '.'; -const jsonnetfile = loadFixture('jsonnetfile.json'); -const jsonnetfileWithName = loadFixture('jsonnetfile-with-name.json'); -const jsonnetfileNoDependencies = loadFixture( +const jsonnetfile = Fixtures.get('jsonnetfile.json'); +const jsonnetfileWithName = Fixtures.get('jsonnetfile-with-name.json'); +const jsonnetfileNoDependencies = Fixtures.get( 'jsonnetfile-no-dependencies.json' ); -const jsonnetfileLocalDependencies = loadFixture( +const jsonnetfileLocalDependencies = Fixtures.get( 'jsonnetfile-local-dependencies.json' ); diff --git a/lib/modules/manager/kubernetes/extract.spec.ts b/lib/modules/manager/kubernetes/extract.spec.ts index 2f4117fc14bef6d36e41c09cab142992d0352b3a..6d2231e3e8a58619d3ba8c8d466f898e1b79696d 100644 --- a/lib/modules/manager/kubernetes/extract.spec.ts +++ b/lib/modules/manager/kubernetes/extract.spec.ts @@ -1,10 +1,10 @@ -import { loadFixture } from '../../../../test/util'; -import { extractPackageFile } from './extract'; +import { Fixtures } from '../../../../test/fixtures'; +import { extractPackageFile } from '.'; -const kubernetesImagesFile = loadFixture('kubernetes.yaml'); -const kubernetesConfigMapFile = loadFixture('configmap.yaml'); -const kubernetesArraySyntaxFile = loadFixture('array-syntax.yaml'); -const otherYamlFile = loadFixture('gitlab-ci.yaml'); +const kubernetesImagesFile = Fixtures.get('kubernetes.yaml'); +const kubernetesConfigMapFile = Fixtures.get('configmap.yaml'); +const kubernetesArraySyntaxFile = Fixtures.get('array-syntax.yaml'); +const otherYamlFile = Fixtures.get('gitlab-ci.yaml'); describe('modules/manager/kubernetes/extract', () => { describe('extractPackageFile()', () => { @@ -14,14 +14,14 @@ describe('modules/manager/kubernetes/extract', () => { it('extracts multiple image lines', () => { const res = extractPackageFile(kubernetesImagesFile); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(2); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(2); }); it('extracts image line in a YAML array', () => { const res = extractPackageFile(kubernetesArraySyntaxFile); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(1); }); it('ignores non-Kubernetes YAML files', () => { diff --git a/lib/modules/manager/kustomize/extract.spec.ts b/lib/modules/manager/kustomize/extract.spec.ts index 320adaefe815e94c7ac3737b0c22ca22fcabac93..5e9932aa33840f7d142b9a125c9d084dc415839c 100644 --- a/lib/modules/manager/kustomize/extract.spec.ts +++ b/lib/modules/manager/kustomize/extract.spec.ts @@ -1,4 +1,4 @@ -import { loadFixture } from '../../../../test/util'; +import { Fixtures } from '../../../../test/fixtures'; import { DockerDatasource } from '../../datasource/docker'; import { GitTagsDatasource } from '../../datasource/git-tags'; import { GithubTagsDatasource } from '../../datasource/github-tags'; @@ -11,19 +11,19 @@ import { parseKustomize, } from './extract'; -const kustomizeGitSSHBase = loadFixture('gitSshBase.yaml'); -const kustomizeEmpty = loadFixture('kustomizeEmpty.yaml'); -const kustomizeGitSSHSubdir = loadFixture('gitSubdir.yaml'); -const kustomizeHTTP = loadFixture('kustomizeHttp.yaml'); -const kustomizeWithLocal = loadFixture('kustomizeWithLocal.yaml'); -const nonKustomize = loadFixture('service.yaml'); -const gitImages = loadFixture('gitImages.yaml'); -const kustomizeDepsInResources = loadFixture('depsInResources.yaml'); -const kustomizeComponent = loadFixture('component.yaml'); -const newTag = loadFixture('newTag.yaml'); -const newName = loadFixture('newName.yaml'); -const digest = loadFixture('digest.yaml'); -const kustomizeHelmChart = loadFixture('kustomizeHelmChart.yaml'); +const kustomizeGitSSHBase = Fixtures.get('gitSshBase.yaml'); +const kustomizeEmpty = Fixtures.get('kustomizeEmpty.yaml'); +const kustomizeGitSSHSubdir = Fixtures.get('gitSubdir.yaml'); +const kustomizeHTTP = Fixtures.get('kustomizeHttp.yaml'); +const kustomizeWithLocal = Fixtures.get('kustomizeWithLocal.yaml'); +const nonKustomize = Fixtures.get('service.yaml'); +const gitImages = Fixtures.get('gitImages.yaml'); +const kustomizeDepsInResources = Fixtures.get('depsInResources.yaml'); +const kustomizeComponent = Fixtures.get('component.yaml'); +const newTag = Fixtures.get('newTag.yaml'); +const newName = Fixtures.get('newName.yaml'); +const digest = Fixtures.get('digest.yaml'); +const kustomizeHelmChart = Fixtures.get('kustomizeHelmChart.yaml'); describe('modules/manager/kustomize/extract', () => { it('should successfully parse a valid kustomize file', () => { @@ -51,7 +51,7 @@ describe('modules/manager/kustomize/extract', () => { - github.com/fluxcd/flux/deploy?ref=1.19.0 `); expect(file).not.toBeNull(); - expect(file.kind).toBe('Kustomization'); + expect(file?.kind).toBe('Kustomization'); }); describe('extractBase', () => { @@ -152,9 +152,9 @@ describe('modules/manager/kustomize/extract', () => { describe('extractHelmChart', () => { it('should return null on a null input', () => { const pkg = extractHelmChart({ - name: null, - repo: null, - version: null, + name: '', + repo: '', + version: '', }); expect(pkg).toBeNull(); }); @@ -179,8 +179,8 @@ describe('modules/manager/kustomize/extract', () => { describe('image extraction', () => { it('should return null on a null input', () => { const pkg = extractImage({ - name: null, - newTag: null, + name: '', + newTag: '', }); expect(pkg).toBeNull(); }); @@ -268,38 +268,38 @@ describe('modules/manager/kustomize/extract', () => { it('extracts multiple image lines', () => { const res = extractPackageFile(kustomizeWithLocal); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(2); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(2); }); it('extracts ssh dependency', () => { const res = extractPackageFile(kustomizeGitSSHBase); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(1); }); it('extracts ssh dependency with a subdir', () => { const res = extractPackageFile(kustomizeGitSSHSubdir); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(1); }); it('extracts http dependency', () => { const res = extractPackageFile(kustomizeHTTP); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(2); - expect(res.deps[0].currentValue).toBe('v0.0.1'); - expect(res.deps[1].currentValue).toBe('1.19.0'); - expect(res.deps[1].depName).toBe('fluxcd/flux'); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(2); + expect(res?.deps[0].currentValue).toBe('v0.0.1'); + expect(res?.deps[1].currentValue).toBe('1.19.0'); + expect(res?.deps[1].depName).toBe('fluxcd/flux'); }); it('should extract out image versions', () => { const res = extractPackageFile(gitImages); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(6); - expect(res.deps[0].currentValue).toBe('v0.1.0'); - expect(res.deps[1].currentValue).toBe('v0.0.1'); - expect(res.deps[5].skipReason).toBe('invalid-value'); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(6); + expect(res?.deps[0].currentValue).toBe('v0.1.0'); + expect(res?.deps[1].currentValue).toBe('v0.0.1'); + expect(res?.deps[5].skipReason).toBe('invalid-value'); }); it('ignores non-Kubernetes empty files', () => { @@ -313,33 +313,33 @@ describe('modules/manager/kustomize/extract', () => { it('should extract bases resources and components from their respective blocks', () => { const res = extractPackageFile(kustomizeDepsInResources); expect(res).not.toBeNull(); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(3); - expect(res.deps[0].currentValue).toBe('v0.0.1'); - expect(res.deps[1].currentValue).toBe('1.19.0'); - expect(res.deps[2].currentValue).toBe('1.18.0'); - expect(res.deps[0].depName).toBe('moredhel/remote-kustomize'); - expect(res.deps[1].depName).toBe('fluxcd/flux'); - expect(res.deps[2].depName).toBe('fluxcd/flux'); - expect(res.deps[0].depType).toBe('Kustomization'); - expect(res.deps[1].depType).toBe('Kustomization'); - expect(res.deps[2].depType).toBe('Kustomization'); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(3); + expect(res?.deps[0].currentValue).toBe('v0.0.1'); + expect(res?.deps[1].currentValue).toBe('1.19.0'); + expect(res?.deps[2].currentValue).toBe('1.18.0'); + expect(res?.deps[0].depName).toBe('moredhel/remote-kustomize'); + expect(res?.deps[1].depName).toBe('fluxcd/flux'); + expect(res?.deps[2].depName).toBe('fluxcd/flux'); + expect(res?.deps[0].depType).toBe('Kustomization'); + expect(res?.deps[1].depType).toBe('Kustomization'); + expect(res?.deps[2].depType).toBe('Kustomization'); }); it('should extract dependencies when kind is Component', () => { const res = extractPackageFile(kustomizeComponent); expect(res).not.toBeNull(); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(3); - expect(res.deps[0].currentValue).toBe('1.19.0'); - expect(res.deps[1].currentValue).toBe('1.18.0'); - expect(res.deps[2].currentValue).toBe('v0.1.0'); - expect(res.deps[0].depName).toBe('fluxcd/flux'); - expect(res.deps[1].depName).toBe('fluxcd/flux'); - expect(res.deps[2].depName).toBe('node'); - expect(res.deps[0].depType).toBe('Component'); - expect(res.deps[1].depType).toBe('Component'); - expect(res.deps[2].depType).toBe('Component'); + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(3); + expect(res?.deps[0].currentValue).toBe('1.19.0'); + expect(res?.deps[1].currentValue).toBe('1.18.0'); + expect(res?.deps[2].currentValue).toBe('v0.1.0'); + expect(res?.deps[0].depName).toBe('fluxcd/flux'); + expect(res?.deps[1].depName).toBe('fluxcd/flux'); + expect(res?.deps[2].depName).toBe('node'); + expect(res?.deps[0].depType).toBe('Component'); + expect(res?.deps[1].depType).toBe('Component'); + expect(res?.deps[2].depType).toBe('Component'); }); const postgresDigest = diff --git a/lib/modules/manager/leiningen/extract.spec.ts b/lib/modules/manager/leiningen/extract.spec.ts index f4bb40db7c714f1c47f969c18cf570e8c9d0bda7..9ef40825c6b884dd4da4a9def88b80cf280e4501 100644 --- a/lib/modules/manager/leiningen/extract.spec.ts +++ b/lib/modules/manager/leiningen/extract.spec.ts @@ -1,11 +1,7 @@ import { Fixtures } from '../../../../test/fixtures'; import { ClojureDatasource } from '../../datasource/clojure'; -import { - extractFromVectors, - extractPackageFile, - extractVariables, - trimAtKey, -} from './extract'; +import { extractFromVectors, extractVariables, trimAtKey } from './extract'; +import { extractPackageFile } from '.'; const leinProjectClj = Fixtures.get(`project.clj`); diff --git a/lib/modules/manager/maven/extract.spec.ts b/lib/modules/manager/maven/extract.spec.ts index 5d26683b3d014c3dfc2b33c07bb118f4f69c2962..28b22bd0adfa5ceaff73575f63abded56f7c11d3 100644 --- a/lib/modules/manager/maven/extract.spec.ts +++ b/lib/modules/manager/maven/extract.spec.ts @@ -11,7 +11,7 @@ const complexSettingsContent = Fixtures.get(`complex.settings.xml`); describe('modules/manager/maven/extract', () => { describe('extractDependencies', () => { it('returns null for invalid XML', () => { - expect(extractPackage(undefined)).toBeNull(); + expect(extractPackage('')).toBeNull(); expect(extractPackage('invalid xml content')).toBeNull(); expect(extractPackage('<foobar></foobar>')).toBeNull(); expect(extractPackage('<project></project>')).toBeNull(); @@ -143,7 +143,7 @@ describe('modules/manager/maven/extract', () => { describe('extractRegistries', () => { it('returns null for invalid XML', () => { - expect(extractRegistries(undefined)).toBeEmptyArray(); + expect(extractRegistries('')).toBeEmptyArray(); expect(extractRegistries('invalid xml content')).toBeEmptyArray(); expect(extractRegistries('<foobar></foobar>')).toBeEmptyArray(); expect(extractRegistries('<settings></settings>')).toBeEmptyArray(); diff --git a/lib/modules/manager/maven/index.spec.ts b/lib/modules/manager/maven/index.spec.ts index 592c74da21bb8e6822f3f99a619b52e380e76278..f397c0594f4dfc37e63111b220d3da3b5f64ce8c 100644 --- a/lib/modules/manager/maven/index.spec.ts +++ b/lib/modules/manager/maven/index.spec.ts @@ -1,15 +1,18 @@ -import { fs, loadFixture } from '../../../../test/util'; +// TODO #7154 +/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ +import { Fixtures } from '../../../../test/fixtures'; +import { fs } from '../../../../test/util'; import type { PackageDependency, PackageFile } from '../types'; import { extractPackage, resolveParents } from './extract'; import { extractAllPackageFiles, updateDependency } from '.'; jest.mock('../../../util/fs'); -const pomContent = loadFixture('simple.pom.xml'); -const pomParent = loadFixture('parent.pom.xml'); -const pomChild = loadFixture('child.pom.xml'); -const origContent = loadFixture('grouping.pom.xml'); -const settingsContent = loadFixture('mirror.settings.xml'); +const pomContent = Fixtures.get('simple.pom.xml'); +const pomParent = Fixtures.get('parent.pom.xml'); +const pomChild = Fixtures.get('child.pom.xml'); +const origContent = Fixtures.get('grouping.pom.xml'); +const settingsContent = Fixtures.get('mirror.settings.xml'); function selectDep(deps: PackageDependency[], name = 'org.example:quuz') { return deps.find((dep) => dep.depName === name); @@ -18,7 +21,7 @@ function selectDep(deps: PackageDependency[], name = 'org.example:quuz') { describe('modules/manager/maven/index', () => { describe('extractAllPackageFiles', () => { it('should return empty if package has no content', async () => { - fs.readLocalFile.mockResolvedValueOnce(null); + fs.readLocalFile.mockResolvedValueOnce(''); const res = await extractAllPackageFiles({}, ['random.pom.xml']); expect(res).toBeEmptyArray(); }); @@ -44,7 +47,7 @@ describe('modules/manager/maven/index', () => { ]; for (const pkg of packages) { for (const dep of pkg.deps) { - const depUrls = [...dep.registryUrls]; + const depUrls = [...dep.registryUrls!]; expect(depUrls).toEqual(urls); } } @@ -137,16 +140,16 @@ describe('modules/manager/maven/index', () => { it('should update an existing dependency', () => { const newValue = '9.9.9.9-final'; - const { deps } = extractPackage(pomContent); + const { deps } = extractPackage(pomContent)!; const dep = selectDep(deps); const upgrade = { ...dep, newValue }; const updatedContent = updateDependency({ fileContent: pomContent, upgrade, - }); - const updatedDep = selectDep(extractPackage(updatedContent).deps); + })!; + const updatedDep = selectDep(extractPackage(updatedContent)!.deps); - expect(updatedDep.currentValue).toEqual(newValue); + expect(updatedDep?.currentValue).toEqual(newValue); }); it('should update existing dependency defined via properties', () => { @@ -155,8 +158,8 @@ describe('modules/manager/maven/index', () => { const newValue = '9.9.9.9-final'; const packages = resolveParents([ - extractPackage(pomParent, 'parent.pom.xml'), - extractPackage(pomChild, 'child.pom.xml'), + extractPackage(pomParent, 'parent.pom.xml')!, + extractPackage(pomChild, 'child.pom.xml')!, ]); const [{ deps }] = packages; const dep = deps.find(finder); @@ -164,20 +167,20 @@ describe('modules/manager/maven/index', () => { const updatedContent = updateDependency({ fileContent: pomParent, upgrade, - }); + })!; const [updatedPkg] = resolveParents([ - extractPackage(updatedContent, 'parent.pom.xml'), - extractPackage(pomChild, 'child.pom.xml'), + extractPackage(updatedContent, 'parent.pom.xml')!, + extractPackage(pomChild, 'child.pom.xml')!, ]); const updatedDep = updatedPkg.deps.find(finder); - expect(updatedDep.registryUrls).toContain('http://example.com/'); - expect(updatedDep.currentValue).toEqual(newValue); + expect(updatedDep?.registryUrls).toContain('http://example.com/'); + expect(updatedDep?.currentValue).toEqual(newValue); }); it('should apply props recursively', () => { const [{ deps }] = resolveParents([ - extractPackage(loadFixture('recursive_props.pom.xml')), + extractPackage(Fixtures.get('recursive_props.pom.xml'))!, ]); expect(deps).toMatchObject([ { @@ -189,7 +192,7 @@ describe('modules/manager/maven/index', () => { it('should detect props infinitely recursing props', () => { const [{ deps }] = resolveParents([ - extractPackage(loadFixture('infinite_recursive_props.pom.xml')), + extractPackage(Fixtures.get('infinite_recursive_props.pom.xml'))!, ]); expect(deps).toMatchObject([ { @@ -220,7 +223,7 @@ describe('modules/manager/maven/index', () => { ]); packages.forEach(({ deps }) => { deps.forEach(({ registryUrls }) => { - const depUrls = new Set([...registryUrls]); + const depUrls = new Set([...registryUrls!]); expect(depUrls).toEqual(urls); }); }); @@ -230,7 +233,7 @@ describe('modules/manager/maven/index', () => { it('should not touch content if new and old versions are equal', () => { const newValue = '1.2.3'; - const { deps } = extractPackage(pomContent); + const { deps } = extractPackage(pomContent)!; const dep = selectDep(deps); const upgrade = { ...dep, newValue }; const updatedContent = updateDependency({ @@ -266,7 +269,7 @@ describe('modules/manager/maven/index', () => { const updatedByPrevious = updateDependency({ fileContent: origContent, upgrade: upgrade1, - }); + })!; expect( updateDependency({ @@ -301,7 +304,7 @@ describe('modules/manager/maven/index', () => { const currentValue = '1.2.2'; const newValue = '1.2.4'; - const { deps } = extractPackage(pomContent); + const { deps } = extractPackage(pomContent)!; const dep = selectDep(deps); const upgrade = { ...dep, currentValue, newValue }; const updatedContent = updateDependency({ @@ -317,13 +320,13 @@ describe('modules/manager/maven/index', () => { const select = (depSet: PackageFile) => selectDep(depSet.deps, 'org.example:hard-range'); const oldContent = extractPackage(pomContent); - const dep = select(oldContent); + const dep = select(oldContent!); const upgrade = { ...dep, newValue }; const newContent = extractPackage( - updateDependency({ fileContent: pomContent, upgrade }) + updateDependency({ fileContent: pomContent, upgrade })! ); - const newDep = select(newContent); - expect(newDep.currentValue).toEqual(newValue); + const newDep = select(newContent!); + expect(newDep?.currentValue).toEqual(newValue); }); it('should preserve ranges', () => { @@ -331,7 +334,7 @@ describe('modules/manager/maven/index', () => { const select = (depSet: PackageFile) => depSet?.deps ? selectDep(depSet.deps, 'org.example:hard-range') : null; const oldContent = extractPackage(pomContent); - const dep = select(oldContent); + const dep = select(oldContent!); expect(dep).not.toBeNull(); const upgrade = { ...dep, newValue }; expect(updateDependency({ fileContent: pomContent, upgrade })).toEqual( @@ -341,7 +344,7 @@ describe('modules/manager/maven/index', () => { it('should return null for replacement', () => { const res = updateDependency({ - fileContent: undefined, + fileContent: '', upgrade: { updateType: 'replacement' }, }); expect(res).toBeNull(); diff --git a/lib/modules/manager/maven/update.spec.ts b/lib/modules/manager/maven/update.spec.ts index 44ffb59aba614ca8cf1574d7c54d4a9b642b572e..247b41d617587c9457da7ad5760e606f9b7d4f4b 100644 --- a/lib/modules/manager/maven/update.spec.ts +++ b/lib/modules/manager/maven/update.spec.ts @@ -1,6 +1,8 @@ +// TODO #7154 +/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ import { XmlDocument } from 'xmldoc'; import { Fixtures } from '../../../../test/fixtures'; -import * as pomUpdater from './update'; +import * as pomUpdater from '.'; const simpleContent = Fixtures.get(`simple.pom.xml`); const minimumContent = Fixtures.get(`minimum.pom.xml`); @@ -14,7 +16,7 @@ describe('modules/manager/maven/update', () => { 'patch' ); - const project = new XmlDocument(bumpedContent); + const project = new XmlDocument(bumpedContent!); expect(project.valueWithPath('version')).toBe('0.0.2'); }); @@ -25,7 +27,7 @@ describe('modules/manager/maven/update', () => { 'patch' ); const { bumpedContent: bumpedContent2 } = pomUpdater.bumpPackageVersion( - bumpedContent, + bumpedContent!, '0.0.1', 'patch' ); @@ -40,7 +42,7 @@ describe('modules/manager/maven/update', () => { 'patch' ); - const project = new XmlDocument(bumpedContent); + const project = new XmlDocument(bumpedContent!); expect(project.valueWithPath('version')).toBe('1'); }); diff --git a/lib/modules/manager/metadata.spec.ts b/lib/modules/manager/metadata.spec.ts index 50b9e369356c1a788272b4f64a054c7616286c79..71a66590d8e9b2b5a552480571b97d694eb3cfd5 100644 --- a/lib/modules/manager/metadata.spec.ts +++ b/lib/modules/manager/metadata.spec.ts @@ -9,14 +9,15 @@ describe('modules/manager/metadata', () => { .sort(); test.each(managerList)('%s has readme with no h1 or h2', async (manager) => { - let readme: string; + let readme: string | undefined; try { readme = await fs.readFile(`${__dirname}/${manager}/readme.md`, 'utf8'); } catch (err) { // do nothing } expect(readme).toBeDefined(); - const lines = readme.split('\n'); + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + const lines = readme!.split('\n'); let isCode = false; const res: string[] = []; diff --git a/lib/modules/manager/meteor/extract.spec.ts b/lib/modules/manager/meteor/extract.spec.ts index 608e15e9fe449e5fca4e94b66871d6d4c08757ec..cc7b0e01f6f8921c378735f04e6d9b4e6ee0137a 100644 --- a/lib/modules/manager/meteor/extract.spec.ts +++ b/lib/modules/manager/meteor/extract.spec.ts @@ -1,5 +1,5 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; const input01Content = Fixtures.get('package-1.js'); @@ -13,7 +13,7 @@ describe('modules/manager/meteor/extract', () => { it('returns results', () => { const res = extractPackageFile(input01Content); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(6); + expect(res?.deps).toHaveLength(6); }); }); }); diff --git a/lib/modules/manager/mix/artifacts.spec.ts b/lib/modules/manager/mix/artifacts.spec.ts index c8e890856b964227b5b9ec597d6b3a294e9c44c1..27f7dd88747aeff84d3539a7635d78b31e39671a 100644 --- a/lib/modules/manager/mix/artifacts.spec.ts +++ b/lib/modules/manager/mix/artifacts.spec.ts @@ -131,7 +131,9 @@ describe('modules/manager/mix/artifacts', () => { expect(result).toMatchSnapshot(); expect(execSnapshots).toMatchSnapshot(); - const [updateResult] = result; + // TODO #7154 + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + const [updateResult] = result!; expect(updateResult).toEqual({ file: { type: 'addition', path: 'mix.lock', contents: 'New mix.lock' }, }); diff --git a/lib/modules/manager/mix/extract.spec.ts b/lib/modules/manager/mix/extract.spec.ts index c2a99b1c04a21cb8f9112cdb3a83877c372e5878..530b2267aa358af0d56a1c724fdf1bebe3b009af 100644 --- a/lib/modules/manager/mix/extract.spec.ts +++ b/lib/modules/manager/mix/extract.spec.ts @@ -9,8 +9,8 @@ describe('modules/manager/mix/extract', () => { describe('extractPackageFile()', () => { it('returns empty for invalid dependency file', async () => { - const { deps } = await extractPackageFile('nothing here', 'mix.exs'); - expect(deps).toBeEmpty(); + const res = await extractPackageFile('nothing here', 'mix.exs'); + expect(res?.deps).toBeEmpty(); }); it('extracts all dependencies', async () => { diff --git a/lib/modules/manager/npm/extract/pnpm.spec.ts b/lib/modules/manager/npm/extract/pnpm.spec.ts index ff034ea3ad6e3444674b5c18d02230b74fe4e186..f391cd7aaaea3822b79a9907efe360064794177b 100644 --- a/lib/modules/manager/npm/extract/pnpm.spec.ts +++ b/lib/modules/manager/npm/extract/pnpm.spec.ts @@ -191,7 +191,7 @@ describe('modules/manager/npm/extract/pnpm', () => { packageFiles.find( (packageFile) => packageFile.packageFile === 'not-matching/b/package.json' - ).pnpmShrinkwrap + )?.pnpmShrinkwrap ).toBeUndefined(); }); }); diff --git a/lib/modules/manager/npm/utils.spec.ts b/lib/modules/manager/npm/utils.spec.ts index c5c7d813368abd51af74910c440e634de5452e85..e7d8af6ec13169ebd86eaac885e8a8f48f721c72 100644 --- a/lib/modules/manager/npm/utils.spec.ts +++ b/lib/modules/manager/npm/utils.spec.ts @@ -1,11 +1,11 @@ -import { loadFixture } from '../../../../test/util'; +import { Fixtures } from '../../../../test/fixtures'; import type { LockFile } from './types'; import { composeLockFile, parseLockFile } from './utils'; describe('modules/manager/npm/utils', () => { describe('parseLockFile', () => { it('parses lockfile string into an object', () => { - const lockFile = loadFixture('lockfile-parsing/package-lock.json'); + const lockFile = Fixtures.get('lockfile-parsing/package-lock.json'); const parseLockFileResult = parseLockFile(lockFile); expect(parseLockFileResult).toStrictEqual({ detectedIndent: ' ', @@ -55,9 +55,11 @@ describe('modules/manager/npm/utils', () => { }); it('adds trailing newline to match npms behaviour and avoid diffs', () => { - const lockFile = loadFixture('lockfile-parsing/package-lock.json'); + const lockFile = Fixtures.get('lockfile-parsing/package-lock.json'); const { detectedIndent, lockFileParsed } = parseLockFile(lockFile); - const lockFileComposed = composeLockFile(lockFileParsed, detectedIndent); + // TODO #7154 + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + const lockFileComposed = composeLockFile(lockFileParsed!, detectedIndent); expect(lockFileComposed).toBe(lockFile); }); }); diff --git a/lib/modules/manager/nuget/extract.spec.ts b/lib/modules/manager/nuget/extract.spec.ts index 95089eab3c341deb82b06cc1fca2e60cf4f45732..5c666ccda637f6b28ae8e84ca96a1ec034f4d2b2 100644 --- a/lib/modules/manager/nuget/extract.spec.ts +++ b/lib/modules/manager/nuget/extract.spec.ts @@ -1,5 +1,5 @@ import upath from 'upath'; -import { loadFixture } from '../../../../test/util'; +import { Fixtures } from '../../../../test/fixtures'; import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; import type { ExtractConfig } from '../types'; @@ -30,7 +30,7 @@ describe('modules/manager/nuget/extract', () => { it('extracts package version dependency', async () => { const packageFile = 'with-centralized-package-versions/Directory.Packages.props'; - const sample = loadFixture(packageFile); + const sample = Fixtures.get(packageFile); const res = await extractPackageFile(sample, packageFile, config); expect(res?.deps).toMatchSnapshot(); expect(res?.deps).toHaveLength(1); @@ -38,7 +38,7 @@ describe('modules/manager/nuget/extract', () => { it('extracts all dependencies', async () => { const packageFile = 'sample.csproj'; - const sample = loadFixture(packageFile); + const sample = Fixtures.get(packageFile); const res = await extractPackageFile(sample, packageFile, config); expect(res?.deps).toMatchSnapshot(); expect(res?.deps).toHaveLength(17); @@ -46,7 +46,7 @@ describe('modules/manager/nuget/extract', () => { it('extracts all dependencies from global packages file', async () => { const packageFile = 'packages.props'; - const sample = loadFixture(packageFile); + const sample = Fixtures.get(packageFile); const res = await extractPackageFile(sample, packageFile, config); expect(res?.deps).toMatchSnapshot(); expect(res?.deps).toHaveLength(17); @@ -54,7 +54,7 @@ describe('modules/manager/nuget/extract', () => { it('considers NuGet.config', async () => { const packageFile = 'with-config-file/with-config-file.csproj'; - const contents = loadFixture(packageFile); + const contents = Fixtures.get(packageFile); expect(await extractPackageFile(contents, packageFile, config)).toEqual({ deps: [ { @@ -74,7 +74,7 @@ describe('modules/manager/nuget/extract', () => { it('considers lower-case nuget.config', async () => { const packageFile = 'with-lower-case-config-file/with-lower-case-config-file.csproj'; - const contents = loadFixture(packageFile); + const contents = Fixtures.get(packageFile); expect(await extractPackageFile(contents, packageFile, config)).toEqual({ deps: [ { @@ -94,7 +94,7 @@ describe('modules/manager/nuget/extract', () => { it('considers pascal-case NuGet.Config', async () => { const packageFile = 'with-pascal-case-config-file/with-pascal-case-config-file.csproj'; - const contents = loadFixture(packageFile); + const contents = Fixtures.get(packageFile); expect(await extractPackageFile(contents, packageFile, config)).toEqual({ deps: [ { @@ -114,7 +114,7 @@ describe('modules/manager/nuget/extract', () => { it('handles malformed NuGet.config', async () => { const packageFile = 'with-malformed-config-file/with-malformed-config-file.csproj'; - const contents = loadFixture(packageFile); + const contents = Fixtures.get(packageFile); expect(await extractPackageFile(contents, packageFile, config)).toEqual({ deps: [ { @@ -130,7 +130,7 @@ describe('modules/manager/nuget/extract', () => { it('handles NuGet.config without package sources', async () => { const packageFile = 'without-package-sources/without-package-sources.csproj'; - const contents = loadFixture(packageFile); + const contents = Fixtures.get(packageFile); expect(await extractPackageFile(contents, packageFile, config)).toEqual({ deps: [ { @@ -145,7 +145,7 @@ describe('modules/manager/nuget/extract', () => { it('handles NuGet.config with whitespaces in package source keys', async () => { const packageFile = 'with-whitespaces/with-whitespaces.csproj'; - const contents = loadFixture(packageFile); + const contents = Fixtures.get(packageFile); expect(await extractPackageFile(contents, packageFile, config)).toEqual({ deps: [ { @@ -165,7 +165,7 @@ describe('modules/manager/nuget/extract', () => { it('ignores local feed in NuGet.config', async () => { const packageFile = 'with-local-feed-in-config-file/with-local-feed-in-config-file.csproj'; - const contents = loadFixture(packageFile); + const contents = Fixtures.get(packageFile); expect(await extractPackageFile(contents, packageFile, config)).toEqual({ deps: [ { @@ -181,9 +181,9 @@ describe('modules/manager/nuget/extract', () => { it('extracts registry URLs independently', async () => { const packageFile = 'multiple-package-files/one/one.csproj'; - const contents = loadFixture(packageFile); + const contents = Fixtures.get(packageFile); const otherPackageFile = 'multiple-package-files/two/two.csproj'; - const otherContents = loadFixture(otherPackageFile); + const otherContents = Fixtures.get(otherPackageFile); expect(await extractPackageFile(contents, packageFile, config)).toEqual({ deps: [ { @@ -218,7 +218,7 @@ describe('modules/manager/nuget/extract', () => { it('extracts msbuild-sdks from global.json', async () => { const packageFile = 'msbuild-sdk-files/global.json'; - const contents = loadFixture(packageFile); + const contents = Fixtures.get(packageFile); expect( await extractPackageFile(contents, packageFile, config) ).toMatchObject({ @@ -241,7 +241,7 @@ describe('modules/manager/nuget/extract', () => { it('extracts dotnet-sdk from global.json', async () => { const packageFile = 'msbuild-sdk-files/global.1.json'; - const contents = loadFixture(packageFile); + const contents = Fixtures.get(packageFile); expect( await extractPackageFile(contents, 'global.json', config) ).toMatchObject({ @@ -258,7 +258,7 @@ describe('modules/manager/nuget/extract', () => { it('handles malformed global.json', async () => { const packageFile = 'msbuild-sdk-files/invalid-json/global.json'; - const contents = loadFixture(packageFile); + const contents = Fixtures.get(packageFile); expect( await extractPackageFile(contents, packageFile, config) ).toBeNull(); @@ -266,7 +266,7 @@ describe('modules/manager/nuget/extract', () => { it('handles not-a-nuget global.json', async () => { const packageFile = 'msbuild-sdk-files/not-nuget/global.json'; - const contents = loadFixture(packageFile); + const contents = Fixtures.get(packageFile); expect( await extractPackageFile(contents, packageFile, config) ).toBeNull(); @@ -274,7 +274,7 @@ describe('modules/manager/nuget/extract', () => { describe('.config/dotnet-tools.json', () => { const packageFile = '.config/dotnet-tools.json'; - const contents = loadFixture('dotnet-tools.json'); + const contents = Fixtures.get('dotnet-tools.json'); it('works', async () => { expect(await extractPackageFile(contents, packageFile, config)).toEqual( diff --git a/lib/modules/manager/nvm/extract.spec.ts b/lib/modules/manager/nvm/extract.spec.ts index 2f98f18c07decd070d77db2b8f4dc80991c52880..85b94329c2bd35a5ab63bf285f0fdf5e0f167cbf 100644 --- a/lib/modules/manager/nvm/extract.spec.ts +++ b/lib/modules/manager/nvm/extract.spec.ts @@ -1,4 +1,4 @@ -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/nvm/extract', () => { describe('extractPackageFile()', () => { diff --git a/lib/modules/manager/pip-compile/artifacts.spec.ts b/lib/modules/manager/pip-compile/artifacts.spec.ts index a78065efb7194a2edad5d69f1058d8737921ddee..b2affb7dacdc613a69d5e14bd98b3d003ddf53bb 100644 --- a/lib/modules/manager/pip-compile/artifacts.spec.ts +++ b/lib/modules/manager/pip-compile/artifacts.spec.ts @@ -1,17 +1,16 @@ -import { exec as _exec } from 'child_process'; import _fs from 'fs-extra'; import { join } from 'upath'; -import { envMock, mockExecAll } from '../../../../test/exec-util'; +import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; import { Fixtures } from '../../../../test/fixtures'; -import { git, mocked } from '../../../../test/util'; +import { env, git } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; import { logger } from '../../../logger'; import * as docker from '../../../util/exec/docker'; -import * as _env from '../../../util/exec/env'; import type { StatusResult } from '../../../util/git/types'; import type { UpdateArtifactsConfig } from '../types'; -import * as pipCompile from './artifacts'; +import { constructPipCompileCmd } from './artifacts'; +import { updateArtifacts } from '.'; jest.mock('fs-extra'); jest.mock('child_process'); @@ -21,8 +20,6 @@ jest.mock('../../../util/host-rules'); jest.mock('../../../util/http'); const fs: jest.Mocked<typeof _fs> = _fs as any; -const exec: jest.Mock<typeof _exec> = _exec as any; -const env = mocked(_env); const adminConfig: RepoGlobalConfig = { // `join` fixes Windows CI @@ -48,7 +45,7 @@ describe('modules/manager/pip-compile/artifacts', () => { it('returns if no requirements.txt found', async () => { expect( - await pipCompile.updateArtifacts({ + await updateArtifacts({ packageFileName: 'requirements.in', updatedDeps: [], newPackageFileContent: '', @@ -62,7 +59,7 @@ describe('modules/manager/pip-compile/artifacts', () => { const execSnapshots = mockExecAll(exec); fs.readFile.mockReturnValueOnce('content' as any); expect( - await pipCompile.updateArtifacts({ + await updateArtifacts({ packageFileName: 'requirements.in', updatedDeps: [], newPackageFileContent: 'some new content', @@ -80,7 +77,7 @@ describe('modules/manager/pip-compile/artifacts', () => { } as StatusResult); fs.readFile.mockReturnValueOnce('New requirements.txt' as any); expect( - await pipCompile.updateArtifacts({ + await updateArtifacts({ packageFileName: 'requirements.in', updatedDeps: [], newPackageFileContent: 'some new content', @@ -98,7 +95,7 @@ describe('modules/manager/pip-compile/artifacts', () => { } as StatusResult); fs.readFile.mockReturnValueOnce('new lock' as any); expect( - await pipCompile.updateArtifacts({ + await updateArtifacts({ packageFileName: 'requirements.in', updatedDeps: [], newPackageFileContent: 'some new content', @@ -114,7 +111,7 @@ describe('modules/manager/pip-compile/artifacts', () => { throw new Error('not found'); }); expect( - await pipCompile.updateArtifacts({ + await updateArtifacts({ packageFileName: 'requirements.in', updatedDeps: [], newPackageFileContent: '{}', @@ -135,7 +132,7 @@ describe('modules/manager/pip-compile/artifacts', () => { } as StatusResult); fs.readFile.mockReturnValueOnce('New requirements.txt' as any); expect( - await pipCompile.updateArtifacts({ + await updateArtifacts({ packageFileName: 'requirements.in', updatedDeps: [], newPackageFileContent: '{}', @@ -153,7 +150,7 @@ describe('modules/manager/pip-compile/artifacts', () => { } as StatusResult); fs.readFile.mockReturnValueOnce('new lock' as any); expect( - await pipCompile.updateArtifacts({ + await updateArtifacts({ packageFileName: 'requirements.in', updatedDeps: [], newPackageFileContent: 'some new content', @@ -166,7 +163,7 @@ describe('modules/manager/pip-compile/artifacts', () => { describe('constructPipCompileCmd()', () => { it('returns default cmd for garbage', () => { expect( - pipCompile.constructPipCompileCmd( + constructPipCompileCmd( Fixtures.get('requirementsNoHeaders.txt'), 'subdir/requirements.in', 'subdir/requirements.txt' @@ -176,7 +173,7 @@ describe('modules/manager/pip-compile/artifacts', () => { it('returns extracted common arguments (like those featured in the README)', () => { expect( - pipCompile.constructPipCompileCmd( + constructPipCompileCmd( Fixtures.get('requirementsWithHashes.txt'), 'subdir/requirements.in', 'subdir/requirements.txt' @@ -188,7 +185,7 @@ describe('modules/manager/pip-compile/artifacts', () => { it('skips unknown arguments', () => { expect( - pipCompile.constructPipCompileCmd( + constructPipCompileCmd( Fixtures.get('requirementsWithUnknownArguments.txt'), 'subdir/requirements.in', 'subdir/requirements.txt' @@ -202,7 +199,7 @@ describe('modules/manager/pip-compile/artifacts', () => { it('skips exploitable subcommands and files', () => { expect( - pipCompile.constructPipCompileCmd( + constructPipCompileCmd( Fixtures.get('requirementsWithExploitingArguments.txt'), 'subdir/requirements.in', 'subdir/requirements.txt' diff --git a/lib/modules/manager/pip_requirements/artifacts.spec.ts b/lib/modules/manager/pip_requirements/artifacts.spec.ts index e5db0d19b6105567913feb61fd3cbf894364bc0c..c7e6d912b01577757aee70084aa60ca9343202a1 100644 --- a/lib/modules/manager/pip_requirements/artifacts.spec.ts +++ b/lib/modules/manager/pip_requirements/artifacts.spec.ts @@ -1,7 +1,7 @@ import { fs } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; import type { UpdateArtifactsConfig } from '../types'; -import { updateArtifacts } from './artifacts'; +import { updateArtifacts } from '.'; jest.mock('child_process'); jest.mock('../../../util/exec'); @@ -73,7 +73,7 @@ describe('modules/manager/pip_requirements/artifacts', () => { }); expect( await updateArtifacts({ - packageFileName: null, + packageFileName: '', updatedDeps: [{ depName: 'atomicwrites' }], newPackageFileContent, config, diff --git a/lib/modules/manager/pip_requirements/extract.spec.ts b/lib/modules/manager/pip_requirements/extract.spec.ts index 9751ce1dc157e8bc2ededda04f1a604e1f26a4c4..42f63dc3e7256cabc2550b1a08a18f4752405845 100644 --- a/lib/modules/manager/pip_requirements/extract.spec.ts +++ b/lib/modules/manager/pip_requirements/extract.spec.ts @@ -1,17 +1,17 @@ -import { loadFixture } from '../../../../test/util'; +import { Fixtures } from '../../../../test/fixtures'; import { GlobalConfig } from '../../../config/global'; -import { extractPackageFile } from './extract'; - -const requirements1 = loadFixture('requirements1.txt'); -const requirements2 = loadFixture('requirements2.txt'); -const requirements3 = loadFixture('requirements3.txt'); -const requirements4 = loadFixture('requirements4.txt'); -const requirements5 = loadFixture('requirements5.txt'); -const requirements6 = loadFixture('requirements6.txt'); -const requirements7 = loadFixture('requirements7.txt'); -const requirements8 = loadFixture('requirements8.txt'); -const requirementsWithEnvMarkers = loadFixture('requirements-env-markers.txt'); -const requirementsGitPackages = loadFixture('requirements-git-packages.txt'); +import { extractPackageFile } from '.'; + +const requirements1 = Fixtures.get('requirements1.txt'); +const requirements2 = Fixtures.get('requirements2.txt'); +const requirements3 = Fixtures.get('requirements3.txt'); +const requirements4 = Fixtures.get('requirements4.txt'); +const requirements5 = Fixtures.get('requirements5.txt'); +const requirements6 = Fixtures.get('requirements6.txt'); +const requirements7 = Fixtures.get('requirements7.txt'); +const requirements8 = Fixtures.get('requirements8.txt'); +const requirementsWithEnvMarkers = Fixtures.get('requirements-env-markers.txt'); +const requirementsGitPackages = Fixtures.get('requirements-git-packages.txt'); describe('modules/manager/pip_requirements/extract', () => { beforeEach(() => { @@ -43,18 +43,18 @@ describe('modules/manager/pip_requirements/extract', () => { it('extracts dependencies', () => { const res = extractPackageFile(requirements1); expect(res).toMatchSnapshot(); - expect(res.registryUrls).toEqual(['http://example.com/private-pypi/']); - expect(res.deps).toHaveLength(4); + expect(res?.registryUrls).toEqual(['http://example.com/private-pypi/']); + expect(res?.deps).toHaveLength(4); }); it('extracts multiple dependencies', () => { - const res = extractPackageFile(requirements2).deps; + const res = extractPackageFile(requirements2)?.deps; expect(res).toMatchSnapshot(); expect(res).toHaveLength(5); }); it('handles comments and commands', () => { - const res = extractPackageFile(requirements3).deps; + const res = extractPackageFile(requirements3)?.deps; expect(res).toMatchSnapshot(); expect(res).toHaveLength(5); }); @@ -62,60 +62,60 @@ describe('modules/manager/pip_requirements/extract', () => { it('handles extras and complex index url', () => { const res = extractPackageFile(requirements4); expect(res).toMatchSnapshot(); - expect(res.registryUrls).toEqual([ + expect(res?.registryUrls).toEqual([ 'https://artifactory.company.com/artifactory/api/pypi/python/simple', ]); - expect(res.deps).toHaveLength(3); + expect(res?.deps).toHaveLength(3); }); it('handles extra index url', () => { const res = extractPackageFile(requirements5); expect(res).toMatchSnapshot(); - expect(res.registryUrls).toEqual([ + expect(res?.registryUrls).toEqual([ 'https://artifactory.company.com/artifactory/api/pypi/python/simple', ]); - expect(res.additionalRegistryUrls).toEqual([ + expect(res?.additionalRegistryUrls).toEqual([ 'http://example.com/private-pypi/', ]); - expect(res.deps).toHaveLength(6); + expect(res?.deps).toHaveLength(6); }); it('handles extra index url and defaults without index to config', () => { const res = extractPackageFile(requirements6); expect(res).toMatchSnapshot(); - expect(res.additionalRegistryUrls).toEqual([ + expect(res?.additionalRegistryUrls).toEqual([ 'http://example.com/private-pypi/', ]); - expect(res.deps).toHaveLength(6); + expect(res?.deps).toHaveLength(6); }); it('handles extra index url and defaults without index to pypi', () => { const res = extractPackageFile(requirements6); expect(res).toMatchSnapshot(); - expect(res.additionalRegistryUrls).toEqual([ + expect(res?.additionalRegistryUrls).toEqual([ 'http://example.com/private-pypi/', ]); - expect(res.deps).toHaveLength(6); + expect(res?.deps).toHaveLength(6); }); it('handles extra spaces around pinned dependency equal signs', () => { const res = extractPackageFile(requirements4); expect(res).toMatchSnapshot(); - expect(res.deps[0].currentValue).toStartWith('=='); - expect(res.deps[0].currentVersion).toStartWith('2.0.12'); - expect(res.deps[1].currentValue).toStartWith('=='); - expect(res.deps[1].currentVersion).toStartWith('4.1.1'); - expect(res.deps[2].currentValue).toStartWith('=='); - expect(res.deps[2].currentVersion).toStartWith('3.2.1'); + expect(res?.deps[0].currentValue).toStartWith('=='); + expect(res?.deps[0].currentVersion).toStartWith('2.0.12'); + expect(res?.deps[1].currentValue).toStartWith('=='); + expect(res?.deps[1].currentVersion).toStartWith('4.1.1'); + expect(res?.deps[2].currentValue).toStartWith('=='); + expect(res?.deps[2].currentVersion).toStartWith('3.2.1'); - expect(res.deps).toHaveLength(3); + expect(res?.deps).toHaveLength(3); }); it('should not replace env vars in low trust mode', () => { process.env.PIP_TEST_TOKEN = 'its-a-secret'; const res = extractPackageFile(requirements7); - expect(res.additionalRegistryUrls).toEqual([ + expect(res?.additionalRegistryUrls).toEqual([ 'http://$PIP_TEST_TOKEN:example.com/private-pypi/', 'http://${PIP_TEST_TOKEN}:example.com/private-pypi/', 'http://$PIP_TEST_TOKEN:example.com/private-pypi/', @@ -127,7 +127,7 @@ describe('modules/manager/pip_requirements/extract', () => { process.env.PIP_TEST_TOKEN = 'its-a-secret'; GlobalConfig.set({ exposeAllEnv: true }); const res = extractPackageFile(requirements7); - expect(res.additionalRegistryUrls).toEqual([ + expect(res?.additionalRegistryUrls).toEqual([ 'http://its-a-secret:example.com/private-pypi/', 'http://its-a-secret:example.com/private-pypi/', 'http://its-a-secret:example.com/private-pypi/', @@ -138,7 +138,7 @@ describe('modules/manager/pip_requirements/extract', () => { it('should handle hashes', () => { const res = extractPackageFile(requirements8); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(3); + expect(res?.deps).toHaveLength(3); }); it('should handle dependency and ignore env markers', () => { @@ -157,7 +157,7 @@ describe('modules/manager/pip_requirements/extract', () => { it('should handle git packages', () => { const res = extractPackageFile(requirementsGitPackages); - expect(res.deps).toHaveLength(5); + expect(res?.deps).toHaveLength(5); expect(res).toEqual({ deps: [ { diff --git a/lib/modules/manager/pip_setup/extract.spec.ts b/lib/modules/manager/pip_setup/extract.spec.ts index f8a908e2c5d90939ad51994f317272eaaf7d32a6..9d94f95be9648614c48f9bd076386f7b4bbb2b1e 100644 --- a/lib/modules/manager/pip_setup/extract.spec.ts +++ b/lib/modules/manager/pip_setup/extract.spec.ts @@ -1,6 +1,6 @@ import { Fixtures } from '../../../../test/fixtures'; import type { ExtractConfig } from '../types'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; const packageFile = 'setup.py'; diff --git a/lib/modules/manager/pipenv/artifacts.spec.ts b/lib/modules/manager/pipenv/artifacts.spec.ts index 5b9679d8968a98e7bf60bc08b0d195d42feb402a..d7989afb5decff217308e43262ffd5b99d8047ea 100644 --- a/lib/modules/manager/pipenv/artifacts.spec.ts +++ b/lib/modules/manager/pipenv/artifacts.spec.ts @@ -6,7 +6,7 @@ import type { RepoGlobalConfig } from '../../../config/types'; import * as docker from '../../../util/exec/docker'; import type { StatusResult } from '../../../util/git/types'; import type { UpdateArtifactsConfig } from '../types'; -import * as pipenv from './artifacts'; +import * as pipenv from '.'; jest.mock('child_process'); jest.mock('../../../util/exec/env'); @@ -26,7 +26,8 @@ const config: UpdateArtifactsConfig = {}; const lockMaintenanceConfig = { ...config, isLockFileMaintenance: true }; describe('modules/manager/pipenv/artifacts', () => { - let pipFileLock; + // TODO: #7154 + let pipFileLock: any; beforeEach(() => { jest.resetAllMocks(); diff --git a/lib/modules/manager/pipenv/extract.spec.ts b/lib/modules/manager/pipenv/extract.spec.ts index b8c4efb7b38c91b3a557589a0de7bfaaaae72f9a..b9d6bdd568726695183bbfa8508981600dba9d8e 100644 --- a/lib/modules/manager/pipenv/extract.spec.ts +++ b/lib/modules/manager/pipenv/extract.spec.ts @@ -1,13 +1,14 @@ -import { fs as fsutil, loadFixture } from '../../../../test/util'; -import { extractPackageFile } from './extract'; +import { Fixtures } from '../../../../test/fixtures'; +import { fs as fsutil } from '../../../../test/util'; +import { extractPackageFile } from '.'; jest.mock('../../../util/fs'); -const pipfile1 = loadFixture('Pipfile1'); -const pipfile2 = loadFixture('Pipfile2'); -const pipfile3 = loadFixture('Pipfile3'); -const pipfile4 = loadFixture('Pipfile4'); -const pipfile5 = loadFixture('Pipfile5'); +const pipfile1 = Fixtures.get('Pipfile1'); +const pipfile2 = Fixtures.get('Pipfile2'); +const pipfile3 = Fixtures.get('Pipfile3'); +const pipfile4 = Fixtures.get('Pipfile4'); +const pipfile5 = Fixtures.get('Pipfile5'); describe('modules/manager/pipenv/extract', () => { describe('extractPackageFile()', () => { @@ -23,48 +24,48 @@ describe('modules/manager/pipenv/extract', () => { fsutil.localPathExists.mockResolvedValueOnce(true); const res = await extractPackageFile(pipfile1, 'Pipfile'); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(6); - expect(res.deps.filter((dep) => !dep.skipReason)).toHaveLength(4); + expect(res?.deps).toHaveLength(6); + expect(res?.deps.filter((dep) => !dep.skipReason)).toHaveLength(4); }); it('marks packages with "extras" as skipReason === any-version', async () => { const res = await extractPackageFile(pipfile3, 'Pipfile'); - expect(res.deps.filter((r) => !r.skipReason)).toHaveLength(0); - expect(res.deps.filter((r) => r.skipReason)).toHaveLength(6); + expect(res?.deps.filter((r) => !r.skipReason)).toHaveLength(0); + expect(res?.deps.filter((r) => r.skipReason)).toHaveLength(6); }); it('extracts multiple dependencies', async () => { fsutil.localPathExists.mockResolvedValueOnce(true); const res = await extractPackageFile(pipfile2, 'Pipfile'); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(5); + expect(res?.deps).toHaveLength(5); }); it('ignores git dependencies', async () => { const content = '[packages]\r\nflask = {git = "https://github.com/pallets/flask.git"}\r\nwerkzeug = ">=0.14"'; const res = await extractPackageFile(content, 'Pipfile'); - expect(res.deps.filter((r) => !r.skipReason)).toHaveLength(1); + expect(res?.deps.filter((r) => !r.skipReason)).toHaveLength(1); }); it('ignores invalid package names', async () => { const content = '[packages]\r\nfoo = "==1.0.0"\r\n_invalid = "==1.0.0"'; const res = await extractPackageFile(content, 'Pipfile'); - expect(res.deps).toHaveLength(2); - expect(res.deps.filter((dep) => !dep.skipReason)).toHaveLength(1); + expect(res?.deps).toHaveLength(2); + expect(res?.deps.filter((dep) => !dep.skipReason)).toHaveLength(1); }); it('ignores relative path dependencies', async () => { const content = '[packages]\r\nfoo = "==1.0.0"\r\ntest = {path = "."}'; const res = await extractPackageFile(content, 'Pipfile'); - expect(res.deps.filter((r) => !r.skipReason)).toHaveLength(1); + expect(res?.deps.filter((r) => !r.skipReason)).toHaveLength(1); }); it('ignores invalid versions', async () => { const content = '[packages]\r\nfoo = "==1.0.0"\r\nsome-package = "==0 0"'; const res = await extractPackageFile(content, 'Pipfile'); - expect(res.deps).toHaveLength(2); - expect(res.deps.filter((dep) => !dep.skipReason)).toHaveLength(1); + expect(res?.deps).toHaveLength(2); + expect(res?.deps.filter((dep) => !dep.skipReason)).toHaveLength(1); }); it('extracts all sources', async () => { @@ -73,7 +74,7 @@ describe('modules/manager/pipenv/extract', () => { '[[source]]\r\nurl = "other-source-url"\r\n' + '[packages]\r\nfoo = "==1.0.0"\r\n'; const res = await extractPackageFile(content, 'Pipfile'); - expect(res.registryUrls).toEqual(['source-url', 'other-source-url']); + expect(res?.registryUrls).toEqual(['source-url', 'other-source-url']); }); it('extracts example pipfile', async () => { @@ -111,10 +112,10 @@ describe('modules/manager/pipenv/extract', () => { fsutil.localPathExists.mockResolvedValueOnce(true); const res = await extractPackageFile(pipfile5, 'Pipfile'); expect(res).toMatchSnapshot(); - expect(res.registryUrls).toBeDefined(); - expect(res.registryUrls).toHaveLength(2); - expect(res.deps[0].registryUrls).toBeDefined(); - expect(res.deps[0].registryUrls).toHaveLength(1); + expect(res?.registryUrls).toBeDefined(); + expect(res?.registryUrls).toHaveLength(2); + expect(res?.deps[0].registryUrls).toBeDefined(); + expect(res?.deps[0].registryUrls).toHaveLength(1); }); it('gets python constraint from python_version', async () => { @@ -122,7 +123,7 @@ describe('modules/manager/pipenv/extract', () => { '[packages]\r\nfoo = "==1.0.0"\r\n' + '[requires]\r\npython_version = "3.8"'; const res = await extractPackageFile(content, 'Pipfile'); - expect(res.constraints.python).toBe('== 3.8.*'); + expect(res?.constraints?.python).toBe('== 3.8.*'); }); it('gets python constraint from python_full_version', async () => { @@ -130,19 +131,19 @@ describe('modules/manager/pipenv/extract', () => { '[packages]\r\nfoo = "==1.0.0"\r\n' + '[requires]\r\npython_full_version = "3.8.6"'; const res = await extractPackageFile(content, 'Pipfile'); - expect(res.constraints.python).toBe('== 3.8.6'); + expect(res?.constraints?.python).toBe('== 3.8.6'); }); it('gets pipenv constraint from packages', async () => { const content = '[packages]\r\npipenv = "==2020.8.13"'; const res = await extractPackageFile(content, 'Pipfile'); - expect(res.constraints.pipenv).toBe('==2020.8.13'); + expect(res?.constraints?.pipenv).toBe('==2020.8.13'); }); it('gets pipenv constraint from dev-packages', async () => { const content = '[dev-packages]\r\npipenv = "==2020.8.13"'; const res = await extractPackageFile(content, 'Pipfile'); - expect(res.constraints.pipenv).toBe('==2020.8.13'); + expect(res?.constraints?.pipenv).toBe('==2020.8.13'); }); }); }); diff --git a/lib/modules/manager/poetry/artifacts.spec.ts b/lib/modules/manager/poetry/artifacts.spec.ts index 3f29846ba5615ab88168eea6cfd8b4256ebcac74..366ed95932071a55578bed208b6cbc2bb5bb66ba 100644 --- a/lib/modules/manager/poetry/artifacts.spec.ts +++ b/lib/modules/manager/poetry/artifacts.spec.ts @@ -1,19 +1,18 @@ -import { exec as _exec } from 'child_process'; import _fs from 'fs-extra'; import { join } from 'upath'; -import { envMock, mockExecAll } from '../../../../test/exec-util'; -import { loadFixture, mocked } from '../../../../test/util'; +import { envMock, exec, mockExecAll } from '../../../../test/exec-util'; +import { Fixtures } from '../../../../test/fixtures'; +import { env, mocked } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; import * as docker from '../../../util/exec/docker'; -import * as _env from '../../../util/exec/env'; import * as _hostRules from '../../../util/host-rules'; import * as _datasource from '../../datasource'; import type { UpdateArtifactsConfig } from '../types'; -import { updateArtifacts } from './artifacts'; +import { updateArtifacts } from '.'; -const pyproject1toml = loadFixture('pyproject.1.toml'); -const pyproject10toml = loadFixture('pyproject.10.toml'); +const pyproject1toml = Fixtures.get('pyproject.1.toml'); +const pyproject10toml = Fixtures.get('pyproject.10.toml'); jest.mock('fs-extra'); jest.mock('child_process'); @@ -22,8 +21,6 @@ jest.mock('../../datasource'); jest.mock('../../../util/host-rules'); const fs: jest.Mocked<typeof _fs> = _fs as any; -const exec: jest.Mock<typeof _exec> = _exec as any; -const env = mocked(_env); const datasource = mocked(_datasource); const hostRules = mocked(_hostRules); @@ -97,7 +94,8 @@ describe('modules/manager/poetry/artifacts', () => { }); it('passes private credential environment vars', async () => { - fs.readFile.mockResolvedValueOnce(null); + // TODO #7154 + fs.readFile.mockResolvedValueOnce(null as never); fs.readFile.mockResolvedValueOnce('[metadata]\n' as never); const execSnapshots = mockExecAll(exec); fs.readFile.mockReturnValueOnce('New poetry.lock' as any); @@ -122,7 +120,8 @@ describe('modules/manager/poetry/artifacts', () => { }); it('prioritizes pypi-scoped credentials', async () => { - fs.readFile.mockResolvedValueOnce(null); + // TODO #7154 + fs.readFile.mockResolvedValueOnce(null as never); fs.readFile.mockResolvedValueOnce(Buffer.from('[metadata]\n')); const execSnapshots = mockExecAll(exec); fs.readFile.mockResolvedValueOnce(Buffer.from('New poetry.lock')); @@ -147,7 +146,8 @@ describe('modules/manager/poetry/artifacts', () => { }); it('returns updated pyproject.lock', async () => { - fs.readFile.mockResolvedValueOnce(null); + // TODO #7154 + fs.readFile.mockResolvedValueOnce(null as never); fs.readFile.mockResolvedValueOnce('[metadata]\n' as never); const execSnapshots = mockExecAll(exec); fs.readFile.mockReturnValueOnce('New poetry.lock' as any); diff --git a/lib/modules/manager/poetry/extract.spec.ts b/lib/modules/manager/poetry/extract.spec.ts index 1a390223fdd2f7e641bc4e418641b561ef0e3a87..4892799b64c39c70564000fe68445ce6f4b75d77 100644 --- a/lib/modules/manager/poetry/extract.spec.ts +++ b/lib/modules/manager/poetry/extract.spec.ts @@ -1,21 +1,22 @@ -import { fs, loadFixture } from '../../../../test/util'; -import { extractPackageFile } from './extract'; +import { Fixtures } from '../../../../test/fixtures'; +import { fs } from '../../../../test/util'; +import { extractPackageFile } from '.'; jest.mock('../../../util/fs'); -const pyproject1toml = loadFixture('pyproject.1.toml'); -const pyproject2toml = loadFixture('pyproject.2.toml'); -const pyproject3toml = loadFixture('pyproject.3.toml'); -const pyproject4toml = loadFixture('pyproject.4.toml'); -const pyproject5toml = loadFixture('pyproject.5.toml'); -const pyproject6toml = loadFixture('pyproject.6.toml'); -const pyproject7toml = loadFixture('pyproject.7.toml'); -const pyproject8toml = loadFixture('pyproject.8.toml'); -const pyproject9toml = loadFixture('pyproject.9.toml'); +const pyproject1toml = Fixtures.get('pyproject.1.toml'); +const pyproject2toml = Fixtures.get('pyproject.2.toml'); +const pyproject3toml = Fixtures.get('pyproject.3.toml'); +const pyproject4toml = Fixtures.get('pyproject.4.toml'); +const pyproject5toml = Fixtures.get('pyproject.5.toml'); +const pyproject6toml = Fixtures.get('pyproject.6.toml'); +const pyproject7toml = Fixtures.get('pyproject.7.toml'); +const pyproject8toml = Fixtures.get('pyproject.8.toml'); +const pyproject9toml = Fixtures.get('pyproject.9.toml'); // pyproject.10.toml use by artifacts -const pyproject11toml = loadFixture('pyproject.11.toml'); -const pyproject11tomlLock = loadFixture('pyproject.11.toml.lock'); +const pyproject11toml = Fixtures.get('pyproject.11.toml'); +const pyproject11tomlLock = Fixtures.get('pyproject.11.toml.lock'); describe('modules/manager/poetry/extract', () => { describe('extractPackageFile()', () => { @@ -42,9 +43,9 @@ describe('modules/manager/poetry/extract', () => { it('extracts multiple dependencies', async () => { const res = await extractPackageFile(pyproject1toml, filename); - expect(res.deps).toMatchSnapshot(); - expect(res.deps).toHaveLength(9); - expect(res.extractedConstraints).toEqual({ + expect(res?.deps).toMatchSnapshot(); + expect(res?.deps).toHaveLength(9); + expect(res?.extractedConstraints).toEqual({ python: '~2.7 || ^3.4', }); }); @@ -52,7 +53,7 @@ describe('modules/manager/poetry/extract', () => { it('extracts multiple dependencies (with dep = {version = "1.2.3"} case)', async () => { const res = await extractPackageFile(pyproject2toml, filename); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(7); + expect(res?.deps).toHaveLength(7); }); it('handles case with no dependencies', async () => { @@ -63,23 +64,23 @@ describe('modules/manager/poetry/extract', () => { it('handles multiple constraint dependencies', async () => { const res = await extractPackageFile(pyproject4toml, filename); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toHaveLength(1); }); it('extracts registries', async () => { const res = await extractPackageFile(pyproject6toml, filename); - expect(res.registryUrls).toMatchSnapshot(); - expect(res.registryUrls).toHaveLength(3); + expect(res?.registryUrls).toMatchSnapshot(); + expect(res?.registryUrls).toHaveLength(3); }); it('can parse empty registries', async () => { const res = await extractPackageFile(pyproject7toml, filename); - expect(res.registryUrls).toBeUndefined(); + expect(res?.registryUrls).toBeUndefined(); }); it('can parse missing registries', async () => { const res = await extractPackageFile(pyproject1toml, filename); - expect(res.registryUrls).toBeUndefined(); + expect(res?.registryUrls).toBeUndefined(); }); it('dedupes registries', async () => { @@ -143,7 +144,7 @@ describe('modules/manager/poetry/extract', () => { it('skips git dependencies', async () => { const content = '[tool.poetry.dependencies]\r\nflask = {git = "https://github.com/pallets/flask.git"}\r\nwerkzeug = ">=0.14"'; - const res = (await extractPackageFile(content, filename)).deps; + const res = (await extractPackageFile(content, filename))!.deps; expect(res[0].depName).toBe('flask'); expect(res[0].currentValue).toBeEmptyString(); expect(res[0].skipReason).toBe('git-dependency'); @@ -153,7 +154,7 @@ describe('modules/manager/poetry/extract', () => { it('skips git dependencies with version', async () => { const content = '[tool.poetry.dependencies]\r\nflask = {git = "https://github.com/pallets/flask.git", version="1.2.3"}\r\nwerkzeug = ">=0.14"'; - const res = (await extractPackageFile(content, filename)).deps; + const res = (await extractPackageFile(content, filename))!.deps; expect(res[0].depName).toBe('flask'); expect(res[0].currentValue).toBe('1.2.3'); expect(res[0].skipReason).toBe('git-dependency'); @@ -163,7 +164,7 @@ describe('modules/manager/poetry/extract', () => { it('skips path dependencies', async () => { const content = '[tool.poetry.dependencies]\r\nflask = {path = "/some/path/"}\r\nwerkzeug = ">=0.14"'; - const res = (await extractPackageFile(content, filename)).deps; + const res = (await extractPackageFile(content, filename))!.deps; expect(res[0].depName).toBe('flask'); expect(res[0].currentValue).toBe(''); expect(res[0].skipReason).toBe('path-dependency'); @@ -173,7 +174,7 @@ describe('modules/manager/poetry/extract', () => { it('skips path dependencies with version', async () => { const content = '[tool.poetry.dependencies]\r\nflask = {path = "/some/path/", version = "1.2.3"}\r\nwerkzeug = ">=0.14"'; - const res = (await extractPackageFile(content, filename)).deps; + const res = (await extractPackageFile(content, filename))!.deps; expect(res[0].depName).toBe('flask'); expect(res[0].currentValue).toBe('1.2.3'); expect(res[0].skipReason).toBe('path-dependency'); diff --git a/lib/modules/manager/poetry/update-locked.spec.ts b/lib/modules/manager/poetry/update-locked.spec.ts index 2151734f4779662bba39e6b7e81f251c20ace404..3118f8afe3b21113174360a8ad2734e63054995e 100644 --- a/lib/modules/manager/poetry/update-locked.spec.ts +++ b/lib/modules/manager/poetry/update-locked.spec.ts @@ -1,11 +1,11 @@ -import { loadFixture } from '../../../../test/util'; +import { Fixtures } from '../../../../test/fixtures'; import type { UpdateLockedConfig } from '../types'; import { updateLockedDependency } from '.'; const lockFile = 'pyproject.11.toml.lock'; const packageFile = 'pyproject.11.toml'; -const lockFileContent = loadFixture(lockFile); +const lockFileContent = Fixtures.get(lockFile); describe('modules/manager/poetry/update-locked', () => { it('detects already updated', () => { diff --git a/lib/modules/manager/pre-commit/extract.spec.ts b/lib/modules/manager/pre-commit/extract.spec.ts index 215ad73cc833e3ba882ba8aff886d67f5e14771c..d7278ae76028142121f08b9371b619f9b9a3d7cb 100644 --- a/lib/modules/manager/pre-commit/extract.spec.ts +++ b/lib/modules/manager/pre-commit/extract.spec.ts @@ -1,21 +1,22 @@ -import { loadFixture, mocked } from '../../../../test/util'; +import { Fixtures } from '../../../../test/fixtures'; +import { mocked } from '../../../../test/util'; import * as _hostRules from '../../../util/host-rules'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; jest.mock('../../../util/host-rules'); const hostRules = mocked(_hostRules); const filename = '.pre-commit.yaml'; -const complexPrecommitConfig = loadFixture('complex.pre-commit-config.yaml'); -const examplePrecommitConfig = loadFixture('.pre-commit-config.yaml'); -const emptyReposPrecommitConfig = loadFixture( +const complexPrecommitConfig = Fixtures.get('complex.pre-commit-config.yaml'); +const examplePrecommitConfig = Fixtures.get('.pre-commit-config.yaml'); +const emptyReposPrecommitConfig = Fixtures.get( 'empty_repos.pre-commit-config.yaml' ); -const noReposPrecommitConfig = loadFixture('no_repos.pre-commit-config.yaml'); -const invalidRepoPrecommitConfig = loadFixture( +const noReposPrecommitConfig = Fixtures.get('no_repos.pre-commit-config.yaml'); +const invalidRepoPrecommitConfig = Fixtures.get( 'invalid_repo.pre-commit-config.yaml' ); -const enterpriseGitPrecommitConfig = loadFixture( +const enterpriseGitPrecommitConfig = Fixtures.get( 'enterprise.pre-commit-config.yaml' ); @@ -36,7 +37,8 @@ describe('modules/manager/pre-commit/extract', () => { }); it('returns null for no file content', () => { - const result = extractPackageFile(null, filename); + // TODO #7154 + const result = extractPackageFile(null as never, filename); expect(result).toBeNull(); }); diff --git a/lib/modules/manager/pyenv/extract.spec.ts b/lib/modules/manager/pyenv/extract.spec.ts index 4608069ae7eaca33bae05d82724f09e5e944c5d1..cd9183318b84e8d98863fe3efe0001e2755b6ec9 100644 --- a/lib/modules/manager/pyenv/extract.spec.ts +++ b/lib/modules/manager/pyenv/extract.spec.ts @@ -1,4 +1,4 @@ -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/pyenv/extract', () => { describe('extractPackageFile()', () => { diff --git a/lib/modules/manager/regex/index.spec.ts b/lib/modules/manager/regex/index.spec.ts index 88ab4d4c463ee483123e62dd9d47b7f9700c45a2..3437cec7fa26d3a691ad117b07b8c52f41d671c3 100644 --- a/lib/modules/manager/regex/index.spec.ts +++ b/lib/modules/manager/regex/index.spec.ts @@ -1,12 +1,12 @@ -import { loadFixture } from '../../../../test/util'; +import { Fixtures } from '../../../../test/fixtures'; import { logger } from '../../../logger'; import type { CustomExtractConfig } from '../types'; import { defaultConfig, extractPackageFile } from '.'; -const dockerfileContent = loadFixture(`Dockerfile`); -const ansibleYamlContent = loadFixture(`ansible.yml`); -const exampleJsonContent = loadFixture(`example.json`); -const exampleGitlabCiYml = loadFixture(`gitlab-ci.yml`); +const dockerfileContent = Fixtures.get(`Dockerfile`); +const ansibleYamlContent = Fixtures.get(`ansible.yml`); +const exampleJsonContent = Fixtures.get(`example.json`); +const exampleGitlabCiYml = Fixtures.get(`gitlab-ci.yml`); describe('modules/manager/regex/index', () => { it('has default config', () => { @@ -30,14 +30,14 @@ describe('modules/manager/regex/index', () => { config ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(8); - expect(res.deps.find((dep) => dep.depName === 'yarn').versioning).toBe( + expect(res?.deps).toHaveLength(8); + expect(res?.deps.find((dep) => dep.depName === 'yarn')?.versioning).toBe( 'semver' ); - expect(res.deps.find((dep) => dep.depName === 'gradle').versioning).toBe( + expect(res?.deps.find((dep) => dep.depName === 'gradle')?.versioning).toBe( 'maven' ); - expect(res.deps.filter((dep) => dep.depType === 'final')).toHaveLength(8); + expect(res?.deps.filter((dep) => dep.depType === 'final')).toHaveLength(8); }); it('returns null if no dependencies found', async () => { @@ -79,11 +79,11 @@ describe('modules/manager/regex/index', () => { config ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toHaveLength(1); expect( - res.deps.find( + res?.deps.find( (dep) => dep.depName === 'openresty/headers-more-nginx-module' - ).extractVersion + )?.extractVersion ).toBe('^v(?<version>.*)$'); }); @@ -136,9 +136,9 @@ describe('modules/manager/regex/index', () => { config ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toHaveLength(1); expect( - res.deps.find((dep) => dep.depName === 'gradle').registryUrls + res?.deps.find((dep) => dep.depName === 'gradle')?.registryUrls ).toEqual(['http://registry.gradle.com/']); }); @@ -186,11 +186,11 @@ describe('modules/manager/regex/index', () => { config ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(2); + expect(res?.deps).toHaveLength(2); expect( - res.deps.find((dep) => dep.depName === 'nodejs/node').versioning + res?.deps.find((dep) => dep.depName === 'nodejs/node')?.versioning ).toBe('node'); - expect(res.deps.find((dep) => dep.depName === 'gradle').versioning).toBe( + expect(res?.deps.find((dep) => dep.depName === 'gradle')?.versioning).toBe( 'maven' ); }); @@ -210,7 +210,7 @@ describe('modules/manager/regex/index', () => { config ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toHaveLength(1); }); it('extracts with combination strategy', async () => { @@ -228,7 +228,7 @@ describe('modules/manager/regex/index', () => { config ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toHaveLength(1); }); it('extracts with combination strategy and non standard capture groups', async () => { @@ -248,8 +248,8 @@ describe('modules/manager/regex/index', () => { 'ansible.yml', config ); - expect(res.deps).toHaveLength(1); - expect(res.deps[0].depName).toBe('docker.io/prom/prometheus'); + expect(res?.deps).toHaveLength(1); + expect(res?.deps[0].depName).toBe('docker.io/prom/prometheus'); expect(res).toMatchSnapshot(); }); @@ -268,7 +268,7 @@ describe('modules/manager/regex/index', () => { config ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toHaveLength(1); }); it('extracts with combination strategy and registry url', async () => { @@ -287,7 +287,7 @@ describe('modules/manager/regex/index', () => { config ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toHaveLength(1); }); it('extracts with combination strategy and templates', async () => { @@ -306,7 +306,7 @@ describe('modules/manager/regex/index', () => { config ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toHaveLength(1); }); it('extracts with combination strategy and empty file', async () => { @@ -337,7 +337,7 @@ describe('modules/manager/regex/index', () => { config ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toHaveLength(1); }); it('extracts with recursive strategy and multiple matches', async () => { @@ -354,7 +354,7 @@ describe('modules/manager/regex/index', () => { config ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(2); + expect(res?.deps).toHaveLength(2); }); it('extracts with recursive strategy and multiple layers ', async () => { @@ -372,7 +372,7 @@ describe('modules/manager/regex/index', () => { config ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(1); + expect(res?.deps).toHaveLength(1); }); it('extracts with recursive strategy and fail because of not sufficient regexes', async () => { @@ -417,6 +417,6 @@ describe('modules/manager/regex/index', () => { config ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(4); + expect(res?.deps).toHaveLength(4); }); }); diff --git a/lib/modules/manager/ruby-version/extract.spec.ts b/lib/modules/manager/ruby-version/extract.spec.ts index f75ecece6316c30640defee71cd93df2101ac0ab..ceb1c62d6b35226c138f774c352fabd2a55b1dec 100644 --- a/lib/modules/manager/ruby-version/extract.spec.ts +++ b/lib/modules/manager/ruby-version/extract.spec.ts @@ -1,4 +1,4 @@ -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/ruby-version/extract', () => { describe('extractPackageFile()', () => { diff --git a/lib/modules/manager/sbt/extract.spec.ts b/lib/modules/manager/sbt/extract.spec.ts index 8a38f2f098475166b113827dc0576918bc111f64..1cbae8b5ea0a45e744518a259b230ae17e1c8960 100644 --- a/lib/modules/manager/sbt/extract.spec.ts +++ b/lib/modules/manager/sbt/extract.spec.ts @@ -1,5 +1,5 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; const sbt = Fixtures.get(`sample.sbt`); const sbtScalaVersionVariable = Fixtures.get(`scala-version-variable.sbt`); @@ -12,7 +12,7 @@ const sbtPrivateVariableDependencyFile = Fixtures.get( describe('modules/manager/sbt/extract', () => { describe('extractPackageFile()', () => { it('returns null for empty', () => { - expect(extractPackageFile(null)).toBeNull(); + expect(extractPackageFile('')).toBeNull(); expect(extractPackageFile('non-sense')).toBeNull(); expect( extractPackageFile('libraryDependencies += "foo" % "bar" % ???') diff --git a/lib/modules/manager/sbt/update.spec.ts b/lib/modules/manager/sbt/update.spec.ts index 96423b065edac075ac6fbde43da930069bbb37cf..b3336b956c6e56d1ebf12fde258e48727b380ac1 100644 --- a/lib/modules/manager/sbt/update.spec.ts +++ b/lib/modules/manager/sbt/update.spec.ts @@ -1,4 +1,4 @@ -import * as sbtUpdater from './update'; +import * as sbtUpdater from '.'; describe('modules/manager/sbt/update', () => { describe('.bumpPackageVersion()', () => { diff --git a/lib/modules/manager/setup-cfg/extract.spec.ts b/lib/modules/manager/setup-cfg/extract.spec.ts index 3c5fa453b0ee9d31b545edce3e726648bb5a6c95..c369d0759559855e851b8f47002396cf9077d3c7 100644 --- a/lib/modules/manager/setup-cfg/extract.spec.ts +++ b/lib/modules/manager/setup-cfg/extract.spec.ts @@ -1,5 +1,5 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/setup-cfg/extract', () => { describe('extractPackageFile()', () => { diff --git a/lib/modules/manager/swift/index.spec.ts b/lib/modules/manager/swift/index.spec.ts index 0f0e0ce483d89e4a4715ff3c89637bfd6dbc1586..c2f1e6d748c54399c92a5299b85791b2e0658792 100644 --- a/lib/modules/manager/swift/index.spec.ts +++ b/lib/modules/manager/swift/index.spec.ts @@ -1,10 +1,9 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/swift/index', () => { describe('extractPackageFile()', () => { it('returns null for empty content', () => { - expect(extractPackageFile(null)).toBeNull(); expect(extractPackageFile(``)).toBeNull(); expect(extractPackageFile(`dependencies:[]`)).toBeNull(); expect(extractPackageFile(`dependencies:["foobar"]`)).toBeNull(); diff --git a/lib/modules/manager/terraform-version/extract.spec.ts b/lib/modules/manager/terraform-version/extract.spec.ts index f80423d46a0f072e276a89e368a676dcdeb7ee4d..65374c10959ff801fa698a367214354af7262454 100644 --- a/lib/modules/manager/terraform-version/extract.spec.ts +++ b/lib/modules/manager/terraform-version/extract.spec.ts @@ -1,4 +1,4 @@ -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/terraform-version/extract', () => { describe('extractPackageFile()', () => { diff --git a/lib/modules/manager/terraform/extract.spec.ts b/lib/modules/manager/terraform/extract.spec.ts index cc82364c0cbdd087c44068bf83b3a3a84f1d22a5..dd6a3f311ea6dce7a22d5bee59df8f527d2e83ff 100644 --- a/lib/modules/manager/terraform/extract.spec.ts +++ b/lib/modules/manager/terraform/extract.spec.ts @@ -5,22 +5,22 @@ import { GlobalConfig } from '../../../config/global'; import type { RepoGlobalConfig } from '../../../config/types'; import { extractPackageFile } from '.'; -const modules = Fixtures.get('modules.tf'); -const bitbucketModules = Fixtures.get('bitbucketModules.tf'); -const azureDevOpsModules = Fixtures.get('azureDevOpsModules.tf'); -const providers = Fixtures.get('providers.tf'); -const docker = Fixtures.get('docker.tf'); -const kubernetes = Fixtures.get('kubernetes.tf'); +const modules = Fixtures?.get('modules.tf'); +const bitbucketModules = Fixtures?.get('bitbucketModules.tf'); +const azureDevOpsModules = Fixtures?.get('azureDevOpsModules.tf'); +const providers = Fixtures?.get('providers.tf'); +const docker = Fixtures?.get('docker.tf'); +const kubernetes = Fixtures?.get('kubernetes.tf'); const tf2 = `module "relative" { source = "../fe" } `; -const helm = Fixtures.get('helm.tf'); -const lockedVersion = Fixtures.get('lockedVersion.tf'); -const lockedVersionLockfile = Fixtures.get('rangeStrategy.hcl'); -const terraformBlock = Fixtures.get('terraformBlock.tf'); -const tfeWorkspaceBlock = Fixtures.get('tfeWorkspace.tf'); +const helm = Fixtures?.get('helm.tf'); +const lockedVersion = Fixtures?.get('lockedVersion.tf'); +const lockedVersionLockfile = Fixtures?.get('rangeStrategy.hcl'); +const terraformBlock = Fixtures?.get('terraformBlock.tf'); +const tfeWorkspaceBlock = Fixtures?.get('tfeWorkspace.tf'); const adminConfig: RepoGlobalConfig = { // `join` fixes Windows CI @@ -43,15 +43,15 @@ describe('modules/manager/terraform/extract', () => { it('extracts modules', async () => { const res = await extractPackageFile(modules, 'modules.tf', {}); - expect(res.deps).toHaveLength(18); - expect(res.deps.filter((dep) => dep.skipReason)).toHaveLength(2); + expect(res?.deps).toHaveLength(18); + expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(2); expect(res).toMatchSnapshot(); }); it('extracts bitbucket modules', async () => { const res = await extractPackageFile(bitbucketModules, 'modules.tf', {}); - expect(res.deps).toHaveLength(11); - expect(res.deps.filter((dep) => dep.skipReason)).toHaveLength(0); + expect(res?.deps).toHaveLength(11); + expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(0); expect(res).toMatchSnapshot(); }); @@ -93,23 +93,23 @@ describe('modules/manager/terraform/extract', () => { it('extracts providers', async () => { const res = await extractPackageFile(providers, 'providers.tf', {}); - expect(res.deps).toHaveLength(14); - expect(res.deps.filter((dep) => dep.skipReason)).toHaveLength(2); + expect(res?.deps).toHaveLength(14); + expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(2); expect(res).toMatchSnapshot(); }); it('extracts docker resources', async () => { const res = await extractPackageFile(docker, 'docker.tf', {}); - expect(res.deps).toHaveLength(8); - expect(res.deps.filter((dep) => dep.skipReason)).toHaveLength(5); + expect(res?.deps).toHaveLength(8); + expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(5); expect(res).toMatchSnapshot(); }); it('extracts kubernetes resources', async () => { const res = await extractPackageFile(kubernetes, 'kubernetes.tf', {}); - expect(res.deps).toHaveLength(18); - expect(res.deps.filter((dep) => dep.skipReason)).toHaveLength(1); - expect(res.deps).toMatchObject([ + expect(res?.deps).toHaveLength(18); + expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(1); + expect(res?.deps).toMatchObject([ { depName: 'gcr.io/kaniko-project/executor', currentValue: 'v1.7.0', @@ -210,8 +210,8 @@ describe('modules/manager/terraform/extract', () => { it('extract helm releases', async () => { const res = await extractPackageFile(helm, 'helm.tf', {}); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(6); - expect(res.deps.filter((dep) => dep.skipReason)).toHaveLength(2); + expect(res?.deps).toHaveLength(6); + expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(2); }); it('update lockfile constraints with range strategy update-lockfile', async () => { @@ -224,8 +224,8 @@ describe('modules/manager/terraform/extract', () => { {} ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(3); - expect(res.deps.filter((dep) => dep.skipReason)).toHaveLength(0); + expect(res?.deps).toHaveLength(3); + expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(0); }); it('test terraform block with only requirement_terraform_version', async () => { @@ -234,8 +234,8 @@ describe('modules/manager/terraform/extract', () => { 'terraformBlock.tf', {} ); - expect(res.deps).toHaveLength(1); - expect(res.deps.filter((dep) => dep.skipReason)).toHaveLength(0); + expect(res?.deps).toHaveLength(1); + expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(0); expect(res).toMatchSnapshot(); }); @@ -246,8 +246,8 @@ describe('modules/manager/terraform/extract', () => { {} ); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(3); - expect(res.deps.filter((dep) => dep.skipReason)).toHaveLength(1); + expect(res?.deps).toHaveLength(3); + expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(1); }); }); }); diff --git a/lib/modules/manager/terraform/lockfile/index.spec.ts b/lib/modules/manager/terraform/lockfile/index.spec.ts index 350666da081dde11ff8ed121a2003bd27b6bd5de..a99f29835c3c933f451c97ffa164ce10320f9646 100644 --- a/lib/modules/manager/terraform/lockfile/index.spec.ts +++ b/lib/modules/manager/terraform/lockfile/index.spec.ts @@ -1,5 +1,6 @@ import { join } from 'upath'; -import { fs, loadFixture, mocked } from '../../../../../test/util'; +import { Fixtures } from '../../../../../test/fixtures'; +import { fs, mocked } from '../../../../../test/util'; import { GlobalConfig } from '../../../../config/global'; import { getPkgReleases } from '../../../datasource'; import type { UpdateArtifactsConfig } from '../../types'; @@ -21,8 +22,8 @@ const adminConfig = { cacheDir: join('/tmp/renovate/cache'), }; -const validLockfile = loadFixture('validLockfile.hcl'); -const validLockfile2 = loadFixture('validLockfile2.hcl'); +const validLockfile = Fixtures.get('validLockfile.hcl'); +const validLockfile2 = Fixtures.get('validLockfile2.hcl'); const mockHash = mocked(TerraformProviderHash).createHashes; const mockGetPkgReleases = getPkgReleases as jest.MockedFunction< @@ -37,7 +38,7 @@ describe('modules/manager/terraform/lockfile/index', () => { }); it('returns null if no .terraform.lock.hcl found', async () => { - fs.readLocalFile.mockResolvedValueOnce(null); + fs.readLocalFile.mockResolvedValueOnce(''); expect( await updateArtifacts({ @@ -50,7 +51,7 @@ describe('modules/manager/terraform/lockfile/index', () => { }); it('returns null if .terraform.lock.hcl is empty', async () => { - fs.readLocalFile.mockResolvedValueOnce('empty' as any); + fs.readLocalFile.mockResolvedValueOnce('empty'); expect( await updateArtifacts({ @@ -63,7 +64,7 @@ describe('modules/manager/terraform/lockfile/index', () => { }); it('update single dependency with exact constraint and depType provider', async () => { - fs.readLocalFile.mockResolvedValueOnce(validLockfile as any); + fs.readLocalFile.mockResolvedValueOnce(validLockfile); fs.getSiblingFileName.mockReturnValueOnce('.terraform.lock.hcl'); mockHash.mockResolvedValueOnce([ @@ -87,15 +88,15 @@ describe('modules/manager/terraform/lockfile/index', () => { }); expect(result).not.toBeNull(); expect(result).toBeArrayOfSize(1); - expect(result[0].file).not.toBeNull(); - expect(result[0].file).toMatchSnapshot(); + expect(result?.[0].file).not.toBeNull(); + expect(result?.[0].file).toMatchSnapshot(); expect(mockHash.mock.calls).toBeArrayOfSize(1); expect(mockHash.mock.calls).toMatchSnapshot(); }); it('update single dependency with exact constraint and and depType required_provider', async () => { - fs.readLocalFile.mockResolvedValueOnce(validLockfile as any); + fs.readLocalFile.mockResolvedValueOnce(validLockfile); fs.getSiblingFileName.mockReturnValueOnce('.terraform.lock.hcl'); mockHash.mockResolvedValueOnce([ @@ -119,8 +120,8 @@ describe('modules/manager/terraform/lockfile/index', () => { }); expect(result).not.toBeNull(); expect(result).toBeArrayOfSize(1); - expect(result[0].file).not.toBeNull(); - expect(result[0].file).toMatchSnapshot(); + expect(result?.[0].file).not.toBeNull(); + expect(result?.[0].file).toMatchSnapshot(); expect(mockHash.mock.calls).toBeArrayOfSize(1); expect(mockHash.mock.calls).toMatchSnapshot(); @@ -145,7 +146,7 @@ describe('modules/manager/terraform/lockfile/index', () => { }); it('update single dependency with range constraint and minor update from private registry', async () => { - fs.readLocalFile.mockResolvedValueOnce(validLockfile as any); + fs.readLocalFile.mockResolvedValueOnce(validLockfile); fs.getSiblingFileName.mockReturnValueOnce('.terraform.lock.hcl'); mockHash.mockResolvedValueOnce([ @@ -170,15 +171,15 @@ describe('modules/manager/terraform/lockfile/index', () => { }); expect(result).not.toBeNull(); expect(result).toBeArrayOfSize(1); - expect(result[0].file).not.toBeNull(); - expect(result[0].file).toMatchSnapshot(); + expect(result?.[0].file).not.toBeNull(); + expect(result?.[0].file).toMatchSnapshot(); expect(mockHash.mock.calls).toBeArrayOfSize(1); expect(mockHash.mock.calls).toMatchSnapshot(); }); it('update single dependency with range constraint and major update', async () => { - fs.readLocalFile.mockResolvedValueOnce(validLockfile as any); + fs.readLocalFile.mockResolvedValueOnce(validLockfile); fs.getSiblingFileName.mockReturnValueOnce('.terraform.lock.hcl'); mockHash.mockResolvedValueOnce([ @@ -202,15 +203,15 @@ describe('modules/manager/terraform/lockfile/index', () => { }); expect(result).not.toBeNull(); expect(result).toBeArrayOfSize(1); - expect(result[0].file).not.toBeNull(); - expect(result[0].file).toMatchSnapshot(); + expect(result?.[0].file).not.toBeNull(); + expect(result?.[0].file).toMatchSnapshot(); expect(mockHash.mock.calls).toBeArrayOfSize(1); expect(mockHash.mock.calls).toMatchSnapshot(); }); it('update single dependency in subfolder', async () => { - fs.readLocalFile.mockResolvedValueOnce(validLockfile as any); + fs.readLocalFile.mockResolvedValueOnce(validLockfile); fs.getSiblingFileName.mockReturnValueOnce('test/.terraform.lock.hcl'); mockHash.mockResolvedValueOnce([ @@ -234,15 +235,15 @@ describe('modules/manager/terraform/lockfile/index', () => { }); expect(result).not.toBeNull(); expect(result).toBeArrayOfSize(1); - expect(result[0].file).not.toBeNull(); - expect(result[0].file).toMatchSnapshot(); + expect(result?.[0].file).not.toBeNull(); + expect(result?.[0].file).toMatchSnapshot(); expect(mockHash.mock.calls).toBeArrayOfSize(1); expect(mockHash.mock.calls).toMatchSnapshot(); }); it('update multiple dependencies which are not ordered', async () => { - fs.readLocalFile.mockResolvedValue(validLockfile2 as any); + fs.readLocalFile.mockResolvedValue(validLockfile2); fs.getSiblingFileName.mockReturnValue('test/.terraform.lock.hcl'); mockHash.mockResolvedValue([ @@ -287,15 +288,15 @@ describe('modules/manager/terraform/lockfile/index', () => { }); expect(result).not.toBeNull(); expect(result).toBeArrayOfSize(1); - expect(result[0].file).not.toBeNull(); - expect(result[0].file).toMatchSnapshot(); + expect(result?.[0].file).not.toBeNull(); + expect(result?.[0].file).toMatchSnapshot(); expect(mockHash.mock.calls).toBeArrayOfSize(4); expect(mockHash.mock.calls).toMatchSnapshot(); }); it('do full lock file maintenance', async () => { - fs.readLocalFile.mockResolvedValueOnce(validLockfile as any); + fs.readLocalFile.mockResolvedValueOnce(validLockfile); fs.getSiblingFileName.mockReturnValueOnce('.terraform.lock.hcl'); mockGetPkgReleases @@ -360,15 +361,15 @@ describe('modules/manager/terraform/lockfile/index', () => { expect(result).not.toBeNull(); expect(result).toBeArrayOfSize(1); - result.forEach((value) => expect(value.file).not.toBeNull()); - result.forEach((value) => expect(value.file).toMatchSnapshot()); + result?.forEach((value) => expect(value.file).not.toBeNull()); + result?.forEach((value) => expect(value.file).toMatchSnapshot()); expect(mockHash.mock.calls).toBeArrayOfSize(2); expect(mockHash.mock.calls).toMatchSnapshot(); }); it('do full lock file maintenance with lockfile in subfolder', async () => { - fs.readLocalFile.mockResolvedValueOnce(validLockfile as any); + fs.readLocalFile.mockResolvedValueOnce(validLockfile); fs.getSiblingFileName.mockReturnValueOnce('subfolder/.terraform.lock.hcl'); mockGetPkgReleases @@ -433,15 +434,15 @@ describe('modules/manager/terraform/lockfile/index', () => { expect(result).not.toBeNull(); expect(result).toBeArrayOfSize(1); - result.forEach((value) => expect(value.file).not.toBeNull()); - result.forEach((value) => expect(value.file).toMatchSnapshot()); + result?.forEach((value) => expect(value.file).not.toBeNull()); + result?.forEach((value) => expect(value.file).toMatchSnapshot()); expect(mockHash.mock.calls).toBeArrayOfSize(2); expect(mockHash.mock.calls).toMatchSnapshot(); }); it('do full lock file maintenance without necessary changes', async () => { - fs.readLocalFile.mockResolvedValueOnce(validLockfile as any); + fs.readLocalFile.mockResolvedValueOnce(validLockfile); mockGetPkgReleases .mockResolvedValueOnce({ @@ -493,7 +494,7 @@ describe('modules/manager/terraform/lockfile/index', () => { }); it('return null if hashing fails', async () => { - fs.readLocalFile.mockResolvedValueOnce(validLockfile as any); + fs.readLocalFile.mockResolvedValueOnce(validLockfile); mockGetPkgReleases .mockResolvedValueOnce({ diff --git a/lib/modules/manager/terraform/modules.spec.ts b/lib/modules/manager/terraform/modules.spec.ts index 2978022009938c775c898f6d7f38e9d94e418a23..6e7c6bb26549e281dda6ab251143674d50d920f3 100644 --- a/lib/modules/manager/terraform/modules.spec.ts +++ b/lib/modules/manager/terraform/modules.spec.ts @@ -8,18 +8,23 @@ import { describe('modules/manager/terraform/modules', () => { describe('githubRefMatchRegex', () => { it('should split project and tag from source', () => { - const { project, tag } = githubRefMatchRegex.exec( + const groups = githubRefMatchRegex.exec( 'github.com/hashicorp/example?ref=v1.0.0' - ).groups; - expect(project).toBe('hashicorp/example'); - expect(tag).toBe('v1.0.0'); + )?.groups; + expect(groups).toEqual({ + project: 'hashicorp/example', + tag: 'v1.0.0', + }); }); it('should parse alpha-numeric characters as well as dots, underscores, and dashes in repo names', () => { - const { project } = githubRefMatchRegex.exec( + const groups = githubRefMatchRegex.exec( 'github.com/hashicorp/example.repo-123?ref=v1.0.0' - ).groups; - expect(project).toBe('hashicorp/example.repo-123'); + )?.groups; + expect(groups).toEqual({ + project: 'hashicorp/example.repo-123', + tag: 'v1.0.0', + }); }); }); @@ -27,50 +32,59 @@ describe('modules/manager/terraform/modules', () => { it('should split project and tag from source', () => { const http = gitTagsRefMatchRegex.exec( 'http://github.com/hashicorp/example?ref=v1.0.0' - ).groups; + )?.groups; const https = gitTagsRefMatchRegex.exec( 'https://github.com/hashicorp/example?ref=v1.0.0' - ).groups; + )?.groups; const ssh = gitTagsRefMatchRegex.exec( 'ssh://github.com/hashicorp/example?ref=v1.0.0' - ).groups; - - expect(http.project).toBe('hashicorp/example'); - expect(http.tag).toBe('v1.0.0'); - - expect(https.project).toBe('hashicorp/example'); - expect(https.tag).toBe('v1.0.0'); + )?.groups; - expect(ssh.project).toBe('hashicorp/example'); - expect(ssh.tag).toBe('v1.0.0'); + expect(http).toMatchObject({ + project: 'hashicorp/example', + tag: 'v1.0.0', + }); + expect(https).toMatchObject({ + project: 'hashicorp/example', + tag: 'v1.0.0', + }); + expect(ssh).toMatchObject({ + project: 'hashicorp/example', + tag: 'v1.0.0', + }); }); it('should parse alpha-numeric characters as well as dots, underscores, and dashes in repo names', () => { const http = gitTagsRefMatchRegex.exec( 'http://github.com/hashicorp/example.repo-123?ref=v1.0.0' - ).groups; + )?.groups; const https = gitTagsRefMatchRegex.exec( 'https://github.com/hashicorp/example.repo-123?ref=v1.0.0' - ).groups; + )?.groups; const ssh = gitTagsRefMatchRegex.exec( 'ssh://github.com/hashicorp/example.repo-123?ref=v1.0.0' - ).groups; + )?.groups; const withoutSshHttpHttps = gitTagsRefMatchRegex.exec( 'git@my-gitlab-instance.local:devops/terraform/instance.git?ref=v5.0.0' - ).groups; - - expect(http.project).toBe('hashicorp/example.repo-123'); - expect(http.tag).toBe('v1.0.0'); - - expect(https.project).toBe('hashicorp/example.repo-123'); - expect(https.tag).toBe('v1.0.0'); - - expect(ssh.project).toBe('hashicorp/example.repo-123'); - expect(ssh.tag).toBe('v1.0.0'); + )?.groups; - expect(withoutSshHttpHttps.project).toBe('terraform/instance.git'); - expect(withoutSshHttpHttps.tag).toBe('v5.0.0'); + expect(http).toMatchObject({ + project: 'hashicorp/example.repo-123', + tag: 'v1.0.0', + }); + expect(https).toMatchObject({ + project: 'hashicorp/example.repo-123', + tag: 'v1.0.0', + }); + expect(ssh).toMatchObject({ + project: 'hashicorp/example.repo-123', + tag: 'v1.0.0', + }); + expect(withoutSshHttpHttps).toMatchObject({ + project: 'terraform/instance.git', + tag: 'v5.0.0', + }); }); }); @@ -78,49 +92,57 @@ describe('modules/manager/terraform/modules', () => { it('should split workspace, project and tag from source', () => { const ssh = bitbucketRefMatchRegex.exec( 'git::ssh://git@bitbucket.org/hashicorp/example.git?ref=v1.0.0' - ).groups; + )?.groups; const https = bitbucketRefMatchRegex.exec( 'git::https://git@bitbucket.org/hashicorp/example.git?ref=v1.0.0' - ).groups; + )?.groups; const plain = bitbucketRefMatchRegex.exec( 'bitbucket.org/hashicorp/example.git?ref=v1.0.0' - ).groups; + )?.groups; const subfolder = bitbucketRefMatchRegex.exec( 'bitbucket.org/hashicorp/example.git/terraform?ref=v1.0.0' - ).groups; + )?.groups; const subfolderWithDoubleSlash = bitbucketRefMatchRegex.exec( 'bitbucket.org/hashicorp/example.git//terraform?ref=v1.0.0' - ).groups; - - expect(ssh.workspace).toBe('hashicorp'); - expect(ssh.project).toBe('example'); - expect(ssh.tag).toBe('v1.0.0'); - - expect(https.workspace).toBe('hashicorp'); - expect(https.project).toBe('example'); - expect(https.tag).toBe('v1.0.0'); - - expect(plain.workspace).toBe('hashicorp'); - expect(plain.project).toBe('example'); - expect(plain.tag).toBe('v1.0.0'); - - expect(subfolder.workspace).toBe('hashicorp'); - expect(subfolder.project).toBe('example'); - expect(subfolder.tag).toBe('v1.0.0'); + )?.groups; - expect(subfolderWithDoubleSlash.workspace).toBe('hashicorp'); - expect(subfolderWithDoubleSlash.project).toBe('example'); - expect(subfolderWithDoubleSlash.tag).toBe('v1.0.0'); + expect(ssh).toMatchObject({ + workspace: 'hashicorp', + project: 'example', + tag: 'v1.0.0', + }); + expect(https).toMatchObject({ + workspace: 'hashicorp', + project: 'example', + tag: 'v1.0.0', + }); + expect(plain).toMatchObject({ + workspace: 'hashicorp', + project: 'example', + tag: 'v1.0.0', + }); + expect(subfolder).toMatchObject({ + workspace: 'hashicorp', + project: 'example', + tag: 'v1.0.0', + }); + expect(subfolderWithDoubleSlash).toMatchObject({ + workspace: 'hashicorp', + project: 'example', + tag: 'v1.0.0', + }); }); it('should parse alpha-numeric characters as well as dots, underscores, and dashes in repo names', () => { const dots = bitbucketRefMatchRegex.exec( 'bitbucket.org/hashicorp/example.repo-123.git?ref=v1.0.0' - ).groups; + )?.groups; - expect(dots.workspace).toBe('hashicorp'); - expect(dots.project).toBe('example.repo-123'); - expect(dots.tag).toBe('v1.0.0'); + expect(dots).toMatchObject({ + workspace: 'hashicorp', + project: 'example.repo-123', + tag: 'v1.0.0', + }); }); }); diff --git a/lib/modules/manager/terragrunt-version/extract.spec.ts b/lib/modules/manager/terragrunt-version/extract.spec.ts index 21d781325d0a7f08b7fb5cf0896011bea069ef78..b1bb775d663d6ddc74a2be238542f86442dc375e 100644 --- a/lib/modules/manager/terragrunt-version/extract.spec.ts +++ b/lib/modules/manager/terragrunt-version/extract.spec.ts @@ -1,4 +1,4 @@ -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/terragrunt-version/extract', () => { describe('extractPackageFile()', () => { diff --git a/lib/modules/manager/terragrunt/extract.spec.ts b/lib/modules/manager/terragrunt/extract.spec.ts index 1d81feda462d7b6296bd820f8581fd116bf010de..9d9a201e1e9681728f3a7186f705cc4dbd260db3 100644 --- a/lib/modules/manager/terragrunt/extract.spec.ts +++ b/lib/modules/manager/terragrunt/extract.spec.ts @@ -1,5 +1,5 @@ import { Fixtures } from '../../../../test/fixtures'; -import { extractPackageFile } from './extract'; +import { extractPackageFile } from '.'; describe('modules/manager/terragrunt/extract', () => { describe('extractPackageFile()', () => { @@ -8,10 +8,10 @@ describe('modules/manager/terragrunt/extract', () => { }); it('extracts terragrunt sources', () => { - const res = extractPackageFile(Fixtures.get('2.hcl')); + const res = extractPackageFile(Fixtures?.get('2.hcl')); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(30); - expect(res.deps.filter((dep) => dep.skipReason)).toHaveLength(5); + expect(res?.deps).toHaveLength(30); + expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(5); }); it('returns null if only local terragrunt deps', () => { diff --git a/lib/modules/manager/terragrunt/modules.spec.ts b/lib/modules/manager/terragrunt/modules.spec.ts index ac03f9763d135e1d2a56f73cce6d6544816ed4a6..35f8fc625ca3e57e4c682554f93b62cee8c6436d 100644 --- a/lib/modules/manager/terragrunt/modules.spec.ts +++ b/lib/modules/manager/terragrunt/modules.spec.ts @@ -3,18 +3,23 @@ import { gitTagsRefMatchRegex, githubRefMatchRegex } from './modules'; describe('modules/manager/terragrunt/modules', () => { describe('githubRefMatchRegex', () => { it('should split project and tag from source', () => { - const { project, tag } = githubRefMatchRegex.exec( + const groups = githubRefMatchRegex.exec( 'github.com/hashicorp/example?ref=v1.0.0' - ).groups; - expect(project).toBe('hashicorp/example'); - expect(tag).toBe('v1.0.0'); + )?.groups; + expect(groups).toEqual({ + project: 'hashicorp/example', + tag: 'v1.0.0', + }); }); it('should parse alpha-numeric characters as well as dots, underscores, and dashes in repo names', () => { - const { project } = githubRefMatchRegex.exec( + const groups = githubRefMatchRegex.exec( 'github.com/hashicorp/example.repo-123?ref=v1.0.0' - ).groups; - expect(project).toBe('hashicorp/example.repo-123'); + )?.groups; + expect(groups).toEqual({ + project: 'hashicorp/example.repo-123', + tag: 'v1.0.0', + }); }); }); @@ -22,43 +27,51 @@ describe('modules/manager/terragrunt/modules', () => { it('should split project and tag from source', () => { const http = gitTagsRefMatchRegex.exec( 'http://github.com/hashicorp/example?ref=v1.0.0' - ).groups; + )?.groups; const https = gitTagsRefMatchRegex.exec( 'https://github.com/hashicorp/example?ref=v1.0.0' - ).groups; + )?.groups; const ssh = gitTagsRefMatchRegex.exec( 'ssh://github.com/hashicorp/example?ref=v1.0.0' - ).groups; + )?.groups; - expect(http.project).toBe('hashicorp/example'); - expect(http.tag).toBe('v1.0.0'); - - expect(https.project).toBe('hashicorp/example'); - expect(https.tag).toBe('v1.0.0'); - - expect(ssh.project).toBe('hashicorp/example'); - expect(ssh.tag).toBe('v1.0.0'); + expect(http).toMatchObject({ + project: 'hashicorp/example', + tag: 'v1.0.0', + }); + expect(https).toMatchObject({ + project: 'hashicorp/example', + tag: 'v1.0.0', + }); + expect(ssh).toMatchObject({ + project: 'hashicorp/example', + tag: 'v1.0.0', + }); }); it('should parse alpha-numeric characters as well as dots, underscores, and dashes in repo names', () => { const http = gitTagsRefMatchRegex.exec( 'http://github.com/hashicorp/example.repo-123?ref=v1.0.0' - ).groups; + )?.groups; const https = gitTagsRefMatchRegex.exec( 'https://github.com/hashicorp/example.repo-123?ref=v1.0.0' - ).groups; + )?.groups; const ssh = gitTagsRefMatchRegex.exec( 'ssh://github.com/hashicorp/example.repo-123?ref=v1.0.0' - ).groups; - - expect(http.project).toBe('hashicorp/example.repo-123'); - expect(http.tag).toBe('v1.0.0'); - - expect(https.project).toBe('hashicorp/example.repo-123'); - expect(https.tag).toBe('v1.0.0'); + )?.groups; - expect(ssh.project).toBe('hashicorp/example.repo-123'); - expect(ssh.tag).toBe('v1.0.0'); + expect(http).toMatchObject({ + project: 'hashicorp/example.repo-123', + tag: 'v1.0.0', + }); + expect(https).toMatchObject({ + project: 'hashicorp/example.repo-123', + tag: 'v1.0.0', + }); + expect(ssh).toMatchObject({ + project: 'hashicorp/example.repo-123', + tag: 'v1.0.0', + }); }); }); }); diff --git a/lib/modules/manager/travis/extract.spec.ts b/lib/modules/manager/travis/extract.spec.ts index a91f3e371384f631882ca53c2e9eb0cc6e0ce72c..4445302c5cbcd258c2d976a2a101dc96480d2a64 100644 --- a/lib/modules/manager/travis/extract.spec.ts +++ b/lib/modules/manager/travis/extract.spec.ts @@ -1,12 +1,12 @@ -import { loadFixture } from '../../../../test/util'; +import { Fixtures } from '../../../../test/fixtures'; import { extractPackageFile } from '.'; -const invalidYAML = loadFixture('invalid.yml'); -const matrixYAMLwithNodeSyntaxString = loadFixture('matrix_jobs.yml'); -const matrixYAMLwithNodeSyntaxArray = loadFixture('matrix_jobs_array.yml'); -const matrixYAMLwithNodeSyntaxArray2 = loadFixture('matrix_jobs_array2.yml'); -const matrixYAMLwithNodeSyntaxAlias = loadFixture('matrix_alias.yml'); -const invalidMatrixYAML = loadFixture('matrix_invalid.yml'); +const invalidYAML = Fixtures.get('invalid.yml'); +const matrixYAMLwithNodeSyntaxString = Fixtures.get('matrix_jobs.yml'); +const matrixYAMLwithNodeSyntaxArray = Fixtures.get('matrix_jobs_array.yml'); +const matrixYAMLwithNodeSyntaxArray2 = Fixtures.get('matrix_jobs_array2.yml'); +const matrixYAMLwithNodeSyntaxAlias = Fixtures.get('matrix_alias.yml'); +const invalidMatrixYAML = Fixtures.get('matrix_invalid.yml'); describe('modules/manager/travis/extract', () => { describe('extractPackageFile()', () => { @@ -18,7 +18,7 @@ describe('modules/manager/travis/extract', () => { it('returns results', () => { const res = extractPackageFile('node_js:\n - 6\n - 8\n'); expect(res).toMatchSnapshot(); - expect(res.deps).toHaveLength(2); + expect(res?.deps).toHaveLength(2); }); it('should handle invalid YAML', () => { diff --git a/lib/modules/manager/velaci/extract.spec.ts b/lib/modules/manager/velaci/extract.spec.ts index 50be1f0ad08fdd7c72d98b2de5db1952549e3d05..ed32315b7928367d06d50213ffdebfc3c5efd4db 100644 --- a/lib/modules/manager/velaci/extract.spec.ts +++ b/lib/modules/manager/velaci/extract.spec.ts @@ -14,8 +14,8 @@ describe('modules/manager/velaci/extract', () => { }); it('extracts multiple step pipeline image lines', () => { - const res = extractPackageFile(Fixtures.get('.vela-steps.yml')); - expect(res.deps).toMatchObject([ + const res = extractPackageFile(Fixtures?.get('.vela-steps.yml')); + expect(res?.deps).toMatchObject([ { currentValue: '1.13', depName: 'golang', @@ -28,8 +28,8 @@ describe('modules/manager/velaci/extract', () => { }); it('extracts multiple services pipeline image lines', () => { - const res = extractPackageFile(Fixtures.get('.vela-services.yml')); - expect(res.deps).toMatchObject([ + const res = extractPackageFile(Fixtures?.get('.vela-services.yml')); + expect(res?.deps).toMatchObject([ { currentValue: '10.0.0', depName: 'node', @@ -46,8 +46,8 @@ describe('modules/manager/velaci/extract', () => { }); it('extracts multiple stages pipeline image lines', () => { - const res = extractPackageFile(Fixtures.get('.vela-stages.yaml')); - expect(res.deps).toMatchObject([ + const res = extractPackageFile(Fixtures?.get('.vela-stages.yaml')); + expect(res?.deps).toMatchObject([ { currentValue: '1.13', depName: 'golang', @@ -60,8 +60,8 @@ describe('modules/manager/velaci/extract', () => { }); it('extracts multiple secrets pipeline image lines', () => { - const res = extractPackageFile(Fixtures.get('.vela-secrets.yml')); - expect(res.deps).toMatchObject([ + const res = extractPackageFile(Fixtures?.get('.vela-secrets.yml')); + expect(res?.deps).toMatchObject([ { currentValue: '10.0.0', depName: 'node', diff --git a/tsconfig.strict.json b/tsconfig.strict.json index 7ecbdc242979bfbb61496f745bd441f76b9be12b..31ed5c1aaa64c6522062f3c4237da15682351cf5 100644 --- a/tsconfig.strict.json +++ b/tsconfig.strict.json @@ -15,7 +15,6 @@ "tmp", // TODO: fixme "lib/workers/**/*.spec.ts", - "lib/modules/manager/**/*.spec.ts", "lib/renovate.spec.ts" ] }