From 679176f26ee2f2c11673379422e6add4558d6103 Mon Sep 17 00:00:00 2001 From: Sergio Zharinov Date: Fri, 3 Jul 2020 17:08:16 +0400 Subject: [PATCH] test(git): Decouple 'gitfs/fs' and 'gitfs/git' in tests (#6661) --- lib/manager/bundler/artifacts.spec.ts | 66 +++++---- lib/manager/bundler/extract.spec.ts | 18 ++- lib/manager/composer/artifacts.spec.ts | 46 +++--- lib/manager/composer/extract.spec.ts | 10 +- lib/manager/gradle-wrapper/artifacts.spec.ts | 6 +- lib/manager/gradle/index.spec.ts | 48 ++++--- lib/manager/helm-requirements/extract.spec.ts | 24 ++-- lib/manager/maven/index.spec.ts | 22 ++- lib/manager/npm/extract/index.spec.ts | 26 ++-- lib/manager/npm/extract/npm.spec.ts | 12 +- lib/manager/npm/extract/yarn.spec.ts | 10 +- .../npm/post-update/node-version.spec.ts | 35 +++-- lib/platform/azure/index.spec.ts | 12 +- lib/platform/bitbucket-server/index.spec.ts | 16 +-- lib/platform/bitbucket/index.spec.ts | 12 +- lib/platform/gitea/index.spec.ts | 78 ++++++----- lib/platform/github/index.spec.ts | 14 +- lib/platform/gitlab/index.spec.ts | 16 +-- lib/util/gitfs/git/index.spec.ts | 132 +++++++++--------- lib/util/gitfs/git/index.ts | 2 + lib/util/gitfs/index.ts | 1 - lib/workers/branch/auto-replace.spec.ts | 2 +- .../repository/extract/manager-files.spec.ts | 10 +- lib/workers/repository/init/config.spec.ts | 22 +-- .../onboarding/branch/index.spec.ts | 12 +- test/util.ts | 6 +- 26 files changed, 322 insertions(+), 336 deletions(-) diff --git a/lib/manager/bundler/artifacts.spec.ts b/lib/manager/bundler/artifacts.spec.ts index 6ad0c4b5d6566d..4cd088e938e369 100644 --- a/lib/manager/bundler/artifacts.spec.ts +++ b/lib/manager/bundler/artifacts.spec.ts @@ -2,17 +2,15 @@ import { exec as _exec } from 'child_process'; import Git from 'simple-git/promise'; import { join } from 'upath'; import { envMock, mockExecAll } from '../../../test/execUtil'; -import { mocked, platform } from '../../../test/util'; +import { fs, mocked, platform } from '../../../test/util'; import * as _datasource from '../../datasource'; import { setUtilConfig } from '../../util'; import { BinarySource } from '../../util/exec/common'; import * as docker from '../../util/exec/docker'; import * as _env from '../../util/exec/env'; -import * as _gitfs from '../../util/gitfs'; import * as _bundlerHostRules from './host-rules'; import { updateArtifacts } from '.'; -const gitfs: jest.Mocked = _gitfs as any; const exec: jest.Mock = _exec as any; const env = mocked(_env); const datasource = mocked(_datasource); @@ -22,7 +20,7 @@ jest.mock('fs-extra'); jest.mock('child_process'); jest.mock('../../../lib/util/exec/env'); jest.mock('../../../lib/datasource'); -jest.mock('../../../lib/util/gitfs'); +jest.mock('../../../lib/util/gitfs/fs'); jest.mock('../../../lib/util/host-rules'); jest.mock('./host-rules'); @@ -59,13 +57,13 @@ describe('bundler.updateArtifacts()', () => { ).toBeNull(); }); it('returns null if Gemfile.lock was not changed', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); - gitfs.writeLocalFile.mockResolvedValueOnce(null as never); + fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); + fs.writeLocalFile.mockResolvedValueOnce(null as never); const execSnapshots = mockExecAll(exec); platform.getRepoStatus.mockResolvedValueOnce({ modified: [], } as Git.StatusResult); - gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); + fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); expect( await updateArtifacts({ packageFileName: 'Gemfile', @@ -77,14 +75,14 @@ describe('bundler.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('works for default binarySource', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); - gitfs.writeLocalFile.mockResolvedValueOnce(null as never); - gitfs.readLocalFile.mockResolvedValueOnce(null); + fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); + fs.writeLocalFile.mockResolvedValueOnce(null as never); + fs.readLocalFile.mockResolvedValueOnce(null); const execSnapshots = mockExecAll(exec); platform.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as Git.StatusResult); - gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); + fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); expect( await updateArtifacts({ packageFileName: 'Gemfile', @@ -96,14 +94,14 @@ describe('bundler.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('works explicit global binarySource', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); - gitfs.writeLocalFile.mockResolvedValueOnce(null as never); - gitfs.readLocalFile.mockResolvedValueOnce(null); + fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); + fs.writeLocalFile.mockResolvedValueOnce(null as never); + fs.readLocalFile.mockResolvedValueOnce(null); const execSnapshots = mockExecAll(exec); platform.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as Git.StatusResult); - gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); + fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); expect( await updateArtifacts({ packageFileName: 'Gemfile', @@ -123,9 +121,9 @@ describe('bundler.updateArtifacts()', () => { await setUtilConfig({ ...config, binarySource: BinarySource.Docker }); }); it('.ruby-version', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); - gitfs.writeLocalFile.mockResolvedValueOnce(null as never); - gitfs.readLocalFile.mockResolvedValueOnce('1.2.0'); + fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); + fs.writeLocalFile.mockResolvedValueOnce(null as never); + fs.readLocalFile.mockResolvedValueOnce('1.2.0'); datasource.getPkgReleases.mockResolvedValueOnce({ releases: [ { version: '1.0.0' }, @@ -137,7 +135,7 @@ describe('bundler.updateArtifacts()', () => { platform.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as Git.StatusResult); - gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); + fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); expect( await updateArtifacts({ packageFileName: 'Gemfile', @@ -152,8 +150,8 @@ describe('bundler.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('compatibility options', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); - gitfs.writeLocalFile.mockResolvedValueOnce(null as never); + fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); + fs.writeLocalFile.mockResolvedValueOnce(null as never); datasource.getPkgReleases.mockResolvedValueOnce({ releases: [ { version: '1.0.0' }, @@ -165,7 +163,7 @@ describe('bundler.updateArtifacts()', () => { platform.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as Git.StatusResult); - gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); + fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); expect( await updateArtifacts({ packageFileName: 'Gemfile', @@ -185,8 +183,8 @@ describe('bundler.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('invalid compatibility options', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); - gitfs.writeLocalFile.mockResolvedValueOnce(null as never); + fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); + fs.writeLocalFile.mockResolvedValueOnce(null as never); datasource.getPkgReleases.mockResolvedValueOnce({ releases: [ { version: '1.0.0' }, @@ -198,7 +196,7 @@ describe('bundler.updateArtifacts()', () => { platform.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as Git.StatusResult); - gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); + fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); expect( await updateArtifacts({ packageFileName: 'Gemfile', @@ -219,9 +217,9 @@ describe('bundler.updateArtifacts()', () => { }); it('injects bundler host configuration environment variables', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); - gitfs.writeLocalFile.mockResolvedValueOnce(null as never); - gitfs.readLocalFile.mockResolvedValueOnce('1.2.0'); + fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); + fs.writeLocalFile.mockResolvedValueOnce(null as never); + fs.readLocalFile.mockResolvedValueOnce('1.2.0'); datasource.getPkgReleases.mockResolvedValueOnce({ releases: [ { version: '1.0.0' }, @@ -245,7 +243,7 @@ describe('bundler.updateArtifacts()', () => { platform.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as Git.StatusResult); - gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); + fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); expect( await updateArtifacts({ packageFileName: 'Gemfile', @@ -264,8 +262,8 @@ describe('bundler.updateArtifacts()', () => { const execError = new Error(); (execError as any).stdout = ' foo was resolved to'; (execError as any).stderr = ''; - gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); - gitfs.writeLocalFile.mockResolvedValueOnce(null as never); + fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); + fs.writeLocalFile.mockResolvedValueOnce(null as never); const execSnapshots = mockExecAll(exec, execError); platform.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], @@ -284,13 +282,13 @@ describe('bundler.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('performs lockFileMaintenance', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); - gitfs.writeLocalFile.mockResolvedValueOnce(null as never); + fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock'); + fs.writeLocalFile.mockResolvedValueOnce(null as never); const execSnapshots = mockExecAll(exec); platform.getRepoStatus.mockResolvedValueOnce({ modified: ['Gemfile.lock'], } as Git.StatusResult); - gitfs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); + fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any); expect( await updateArtifacts({ packageFileName: 'Gemfile', diff --git a/lib/manager/bundler/extract.spec.ts b/lib/manager/bundler/extract.spec.ts index 64e1319461dcbb..7f4f407f0051e4 100644 --- a/lib/manager/bundler/extract.spec.ts +++ b/lib/manager/bundler/extract.spec.ts @@ -1,11 +1,9 @@ import { readFileSync } from 'fs'; -import * as _gitfs from '../../util/gitfs'; +import { fs } from '../../../test/util'; import { isValid } from '../../versioning/ruby'; import { extractPackageFile } from './extract'; -jest.mock('../../util/gitfs'); - -const gitfs: any = _gitfs; +jest.mock('../../util/gitfs/fs'); const railsGemfile = readFileSync( 'lib/manager/bundler/__fixtures__/Gemfile.rails', @@ -74,7 +72,7 @@ describe('lib/manager/bundler/extract', () => { expect(await extractPackageFile('nothing here', 'Gemfile')).toBeNull(); }); it('parses rails Gemfile', async () => { - gitfs.readLocalFile.mockReturnValueOnce(railsGemfileLock); + fs.readLocalFile.mockResolvedValueOnce(railsGemfileLock); const res = await extractPackageFile(railsGemfile, 'Gemfile'); expect(res).toMatchSnapshot(); // couple of dependency of ruby rails are not present in the lock file. Filter out those before processing @@ -98,7 +96,7 @@ describe('lib/manager/bundler/extract', () => { validateGems(sourceGroupGemfile, res); }); it('parse webpacker Gemfile', async () => { - gitfs.readLocalFile.mockReturnValueOnce(webPackerGemfileLock); + fs.readLocalFile.mockResolvedValueOnce(webPackerGemfileLock); const res = await extractPackageFile(webPackerGemfile, 'Gemfile'); expect(res).toMatchSnapshot(); expect( @@ -112,7 +110,7 @@ describe('lib/manager/bundler/extract', () => { validateGems(webPackerGemfile, res); }); it('parse mastodon Gemfile', async () => { - gitfs.readLocalFile.mockReturnValueOnce(mastodonGemfileLock); + fs.readLocalFile.mockResolvedValueOnce(mastodonGemfileLock); const res = await extractPackageFile(mastodonGemfile, 'Gemfile'); expect(res).toMatchSnapshot(); expect( @@ -130,7 +128,7 @@ describe('lib/manager/bundler/extract', () => { validateGems(mastodonGemfile, res); }); it('parse Ruby CI Gemfile', async () => { - gitfs.readLocalFile.mockReturnValueOnce(rubyCIGemfileLock); + fs.readLocalFile.mockResolvedValueOnce(rubyCIGemfileLock); const res = await extractPackageFile(rubyCIGemfile, 'Gemfile'); expect(res).toMatchSnapshot(); expect( @@ -145,7 +143,7 @@ describe('lib/manager/bundler/extract', () => { }); }); it('parse Gitlab Foss Gemfile', async () => { - gitfs.readLocalFile.mockReturnValueOnce(gitlabFossGemfileLock); + fs.readLocalFile.mockResolvedValueOnce(gitlabFossGemfileLock); const res = await extractPackageFile(gitlabFossGemfile, 'Gemfile'); expect(res).toMatchSnapshot(); expect( @@ -160,7 +158,7 @@ describe('lib/manager/bundler/extract', () => { }); it('parse source blocks with spaces in Gemfile', async () => { - gitfs.readLocalFile.mockReturnValueOnce(sourceBlockWithNewLinesGemfileLock); + fs.readLocalFile.mockResolvedValueOnce(sourceBlockWithNewLinesGemfileLock); const res = await extractPackageFile( sourceBlockWithNewLinesGemfile, 'Gemfile' diff --git a/lib/manager/composer/artifacts.spec.ts b/lib/manager/composer/artifacts.spec.ts index aebbc6b046095f..4242edb2d6be8c 100644 --- a/lib/manager/composer/artifacts.spec.ts +++ b/lib/manager/composer/artifacts.spec.ts @@ -1,23 +1,21 @@ import { exec as _exec } from 'child_process'; import { join } from 'upath'; import { envMock, mockExecAll } from '../../../test/execUtil'; -import { mocked, platform } from '../../../test/util'; +import { fs, mocked, platform } from '../../../test/util'; import { setUtilConfig } from '../../util'; import { BinarySource } from '../../util/exec/common'; import * as docker from '../../util/exec/docker'; import * as _env from '../../util/exec/env'; import { StatusResult } from '../../util/gitfs'; -import * as _gitfs from '../../util/gitfs'; import * as composer from './artifacts'; jest.mock('child_process'); jest.mock('../../util/exec/env'); -jest.mock('../../util/gitfs'); +jest.mock('../../util/gitfs/fs'); jest.mock('../../util/host-rules'); const hostRules = require('../../util/host-rules'); -const gitfs: jest.Mocked = _gitfs as any; const exec: jest.Mock = _exec as any; const env = mocked(_env); @@ -48,9 +46,9 @@ describe('.updateArtifacts()', () => { ).toBeNull(); }); it('returns null if unchanged', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); + fs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); const execSnapshots = mockExecAll(exec); - gitfs.readLocalFile.mockReturnValueOnce('Current composer.lock' as any); + fs.readLocalFile.mockReturnValueOnce('Current composer.lock' as any); platform.getRepoStatus.mockResolvedValue({ modified: [] } as StatusResult); expect( await composer.updateArtifacts({ @@ -63,9 +61,9 @@ describe('.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('uses hostRules to write auth.json', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); + fs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); const execSnapshots = mockExecAll(exec); - gitfs.readLocalFile.mockReturnValueOnce('Current composer.lock' as any); + fs.readLocalFile.mockReturnValueOnce('Current composer.lock' as any); const authConfig = { ...config, registryUrls: ['https://packagist.renovatebot.com'], @@ -86,9 +84,9 @@ describe('.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('returns updated composer.lock', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); + fs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); const execSnapshots = mockExecAll(exec); - gitfs.readLocalFile.mockReturnValueOnce('New composer.lock' as any); + fs.readLocalFile.mockReturnValueOnce('New composer.lock' as any); platform.getRepoStatus.mockResolvedValue({ modified: ['composer.lock'], } as StatusResult); @@ -103,9 +101,9 @@ describe('.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('performs lockFileMaintenance', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); + fs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); const execSnapshots = mockExecAll(exec); - gitfs.readLocalFile.mockReturnValueOnce('New composer.lock' as any); + fs.readLocalFile.mockReturnValueOnce('New composer.lock' as any); platform.getRepoStatus.mockResolvedValue({ modified: ['composer.lock'], } as StatusResult); @@ -125,11 +123,11 @@ describe('.updateArtifacts()', () => { it('supports docker mode', async () => { jest.spyOn(docker, 'removeDanglingContainers').mockResolvedValueOnce(); await setUtilConfig({ ...config, binarySource: BinarySource.Docker }); - gitfs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); + fs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); const execSnapshots = mockExecAll(exec); - gitfs.readLocalFile.mockReturnValueOnce('New composer.lock' as any); + fs.readLocalFile.mockReturnValueOnce('New composer.lock' as any); expect( await composer.updateArtifacts({ packageFileName: 'composer.json', @@ -141,9 +139,9 @@ describe('.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('supports global mode', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); + fs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); const execSnapshots = mockExecAll(exec); - gitfs.readLocalFile.mockReturnValueOnce('New composer.lock' as any); + fs.readLocalFile.mockReturnValueOnce('New composer.lock' as any); expect( await composer.updateArtifacts({ packageFileName: 'composer.json', @@ -158,8 +156,8 @@ describe('.updateArtifacts()', () => { expect(execSnapshots).toMatchSnapshot(); }); it('catches errors', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); - gitfs.writeLocalFile.mockImplementationOnce(() => { + fs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); + fs.writeLocalFile.mockImplementationOnce(() => { throw new Error('not found'); }); expect( @@ -172,8 +170,8 @@ describe('.updateArtifacts()', () => { ).toMatchSnapshot(); }); it('catches unmet requirements errors', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); - gitfs.writeLocalFile.mockImplementationOnce(() => { + fs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); + fs.writeLocalFile.mockImplementationOnce(() => { throw new Error( 'fooYour requirements could not be resolved to an installable set of packages.bar' ); @@ -188,8 +186,8 @@ describe('.updateArtifacts()', () => { ).toMatchSnapshot(); }); it('throws for disk space', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); - gitfs.writeLocalFile.mockImplementationOnce(() => { + fs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); + fs.writeLocalFile.mockImplementationOnce(() => { throw new Error( 'vendor/composer/07fe2366/sebastianbergmann-php-code-coverage-c896779/src/Report/Html/Renderer/Template/js/d3.min.js: write error (disk full?). Continue? (y/n/^C) ' ); @@ -204,9 +202,9 @@ describe('.updateArtifacts()', () => { ).rejects.toThrow(); }); it('disables ignorePlatformReqs', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); + fs.readLocalFile.mockResolvedValueOnce('Current composer.lock' as any); const execSnapshots = mockExecAll(exec); - gitfs.readLocalFile.mockReturnValueOnce('New composer.lock' as any); + fs.readLocalFile.mockReturnValueOnce('New composer.lock' as any); platform.getRepoStatus.mockResolvedValue({ modified: ['composer.lock'], } as StatusResult); diff --git a/lib/manager/composer/extract.spec.ts b/lib/manager/composer/extract.spec.ts index 701aede97679a4..1a740d2f8c6de1 100644 --- a/lib/manager/composer/extract.spec.ts +++ b/lib/manager/composer/extract.spec.ts @@ -1,10 +1,8 @@ import { readFileSync } from 'fs'; -import * as _gitfs from '../../util/gitfs'; +import { fs } from '../../../test/util'; import { extractPackageFile } from './extract'; -jest.mock('../../util/gitfs'); - -const gitfs: any = _gitfs; +jest.mock('../../util/gitfs/fs'); const requirements1 = readFileSync( 'lib/manager/composer/__fixtures__/composer1.json', @@ -63,13 +61,13 @@ describe('lib/manager/composer/extract', () => { expect(res.registryUrls).toHaveLength(2); }); it('extracts object repositories and registryUrls with lock file', async () => { - gitfs.readLocalFile.mockResolvedValue(requirements5Lock); + fs.readLocalFile.mockResolvedValue(requirements5Lock); const res = await extractPackageFile(requirements5, packageFile); expect(res).toMatchSnapshot(); expect(res.registryUrls).toHaveLength(2); }); it('extracts dependencies with lock file', async () => { - gitfs.readLocalFile.mockResolvedValue('some content'); + fs.readLocalFile.mockResolvedValue('some content'); const res = await extractPackageFile(requirements1, packageFile); expect(res).toMatchSnapshot(); }); diff --git a/lib/manager/gradle-wrapper/artifacts.spec.ts b/lib/manager/gradle-wrapper/artifacts.spec.ts index 1cbcef6df54469..609439fd8f82e3 100644 --- a/lib/manager/gradle-wrapper/artifacts.spec.ts +++ b/lib/manager/gradle-wrapper/artifacts.spec.ts @@ -8,8 +8,8 @@ import * as httpMock from '../../../test/httpMock'; import { addReplacingSerializer, env, + fs, getName, - gitfs, partial, platform, } from '../../../test/util'; @@ -19,7 +19,7 @@ import { resetPrefetchedImages } from '../../util/exec/docker'; import * as dcUpdate from '.'; jest.mock('child_process'); -jest.mock('../../util/gitfs'); +jest.mock('../../util/gitfs/fs'); jest.mock('../../util/exec/env'); const exec: jest.Mock = _exec as any; @@ -51,7 +51,7 @@ describe(getName(__filename), () => { await setUtilConfig(config); resetPrefetchedImages(); - gitfs.readLocalFile.mockResolvedValue('test'); + fs.readLocalFile.mockResolvedValue('test'); }); afterEach(() => { diff --git a/lib/manager/gradle/index.spec.ts b/lib/manager/gradle/index.spec.ts index 8108888d7c8b73..fe19ad34f6dad6 100644 --- a/lib/manager/gradle/index.spec.ts +++ b/lib/manager/gradle/index.spec.ts @@ -1,6 +1,6 @@ import { exec as _exec } from 'child_process'; import * as _os from 'os'; -import fs from 'fs-extra'; +import fsExtra from 'fs-extra'; import tmp, { DirectoryResult } from 'tmp-promise'; import * as upath from 'upath'; import { envMock, mockExecAll } from '../../../test/execUtil'; @@ -9,7 +9,7 @@ import * as _util from '../../util'; import { BinarySource } from '../../util/exec/common'; import * as _docker from '../../util/exec/docker'; import * as _env from '../../util/exec/env'; -import * as _utilfs from '../../util/gitfs'; +import * as _fs from '../../util/gitfs/fs'; import { ExtractConfig } from '../common'; import { ifSystemSupportsGradle } from './__testutil__/gradle'; import { GRADLE_DEPENDENCY_REPORT_FILENAME } from './gradle-updates-report'; @@ -17,11 +17,11 @@ import * as _manager from '.'; const fixtures = 'lib/manager/gradle/__fixtures__'; const standardUpdatesReport = () => - fs.readFile(`${fixtures}/updatesReport.json`, 'utf8'); + fsExtra.readFile(`${fixtures}/updatesReport.json`, 'utf8'); const emptyUpdatesReport = () => - fs.readFile(`${fixtures}/updatesReportEmpty.json`, 'utf8'); + fsExtra.readFile(`${fixtures}/updatesReportEmpty.json`, 'utf8'); const multiProjectUpdatesReport = () => - fs.readFile(`${fixtures}/MultiProjectUpdatesReport.json`, 'utf8'); + fsExtra.readFile(`${fixtures}/MultiProjectUpdatesReport.json`, 'utf8'); const baseConfig = { gradle: { @@ -44,16 +44,16 @@ async function setupMocks() { jest.mock('child_process'); jest.mock('../../util/exec/env'); - jest.mock('../../util/gitfs'); + jest.mock('../../util/gitfs/fs'); jest.mock('os'); const os: jest.Mocked = require('os'); - const gitfs: jest.Mocked = require('../../util/gitfs'); + const fs: jest.Mocked = require('../../util/gitfs/fs'); const env: jest.Mocked = require('../../util/exec/env'); const exec: jest.Mock = require('child_process').exec; const util: jest.Mocked = require('../../util'); - gitfs.readLocalFile.mockResolvedValue(` + fs.readLocalFile.mockResolvedValue(` dependency 'foo:foo:1.2.3' dependency "bar:bar:3.4.5" `); @@ -97,10 +97,10 @@ describe(getName(__filename), () => { dir: string = config.localDir ) { if (addGradleWrapper) { - await fs.copy(`${fixtures}/gradle-wrappers/6`, dir); + await fsExtra.copy(`${fixtures}/gradle-wrappers/6`, dir); } if (updatesReport) { - await fs.writeFile( + await fsExtra.writeFile( `${dir}/${GRADLE_DEPENDENCY_REPORT_FILENAME}`, await updatesReport ); @@ -224,7 +224,7 @@ describe(getName(__filename), () => { it('should return gradle dependencies for build.gradle in subdirectories if there is gradlew in the same directory', async () => { const execSnapshots = mockExecAll(exec, gradleOutput); await initializeWorkingDir(true, standardUpdatesReport()); - await fs.mkdirs(`${config.localDir}/foo`); + await fsExtra.mkdirs(`${config.localDir}/foo`); await initializeWorkingDir( true, standardUpdatesReport(), @@ -245,9 +245,9 @@ describe(getName(__filename), () => { await manager.extractAllPackageFiles(config, ['build.gradle']); await expect( - fs.access( + fsExtra.access( `${config.localDir}/renovate-plugin.gradle`, - fs.constants.F_OK + fsExtra.constants.F_OK ) ).resolves.toBeUndefined(); expect(execSnapshots).toMatchSnapshot(); @@ -303,7 +303,7 @@ describe(getName(__filename), () => { it('should update an existing module dependency', async () => { const execSnapshots = mockExecAll(exec, gradleOutput); - const buildGradleContent = await fs.readFile( + const buildGradleContent = await fsExtra.readFile( `${fixtures}/build.gradle.example1`, 'utf8' ); @@ -403,8 +403,8 @@ describe(getName(__filename), () => { workingDir = await tmp.dir({ unsafeCleanup: true }); successFile = ''; testRunConfig = { ...baseConfig, localDir: workingDir.path }; - await fs.copy(`${fixtures}/minimal-project`, workingDir.path); - await fs.copy(`${fixtures}/gradle-wrappers/6`, workingDir.path); + await fsExtra.copy(`${fixtures}/minimal-project`, workingDir.path); + await fsExtra.copy(`${fixtures}/gradle-wrappers/6`, workingDir.path); const mockPluginContent = ` allprojects { @@ -414,7 +414,7 @@ allprojects { } } }`; - await fs.writeFile( + await fsExtra.writeFile( `${workingDir.path}/renovate-plugin.gradle`, mockPluginContent ); @@ -422,16 +422,20 @@ allprojects { }); it('executes an executable gradle wrapper', async () => { - const gradlew = await fs.stat(`${workingDir.path}/gradlew`); + const gradlew = await fsExtra.stat(`${workingDir.path}/gradlew`); await manager.executeGradle(testRunConfig, workingDir.path, gradlew); - await expect(fs.readFile(successFile, 'utf8')).resolves.toBe('success'); + await expect(fsExtra.readFile(successFile, 'utf8')).resolves.toBe( + 'success' + ); }, 120000); it('executes a not-executable gradle wrapper', async () => { - await fs.chmod(`${workingDir.path}/gradlew`, '444'); - const gradlew = await fs.stat(`${workingDir.path}/gradlew`); + await fsExtra.chmod(`${workingDir.path}/gradlew`, '444'); + const gradlew = await fsExtra.stat(`${workingDir.path}/gradlew`); await manager.executeGradle(testRunConfig, workingDir.path, gradlew); - await expect(fs.readFile(successFile, 'utf8')).resolves.toBe('success'); + await expect(fsExtra.readFile(successFile, 'utf8')).resolves.toBe( + 'success' + ); }, 120000); }); }); diff --git a/lib/manager/helm-requirements/extract.spec.ts b/lib/manager/helm-requirements/extract.spec.ts index f73bc6be7f170d..02aa1cff9e4dd1 100644 --- a/lib/manager/helm-requirements/extract.spec.ts +++ b/lib/manager/helm-requirements/extract.spec.ts @@ -1,18 +1,16 @@ -import * as _gitfs from '../../util/gitfs'; +import { fs } from '../../../test/util'; import { extractPackageFile } from './extract'; -jest.mock('../../util/gitfs'); - -const gitfs: any = _gitfs; +jest.mock('../../util/gitfs/fs'); describe('lib/manager/helm-requirements/extract', () => { describe('extractPackageFile()', () => { beforeEach(() => { jest.resetAllMocks(); - gitfs.readLocalFile = jest.fn(); + fs.readLocalFile = jest.fn(); }); it('skips invalid registry urls', async () => { - gitfs.readLocalFile.mockResolvedValueOnce(` + fs.readLocalFile.mockResolvedValueOnce(` apiVersion: v1 appVersion: "1.0" description: A Helm chart for Kubernetes @@ -41,7 +39,7 @@ describe('lib/manager/helm-requirements/extract', () => { expect(result.deps.every((dep) => dep.skipReason)).toEqual(true); }); it('parses simple requirements.yaml correctly', async () => { - gitfs.readLocalFile.mockResolvedValueOnce(` + fs.readLocalFile.mockResolvedValueOnce(` apiVersion: v1 appVersion: "1.0" description: A Helm chart for Kubernetes @@ -67,7 +65,7 @@ describe('lib/manager/helm-requirements/extract', () => { expect(result).toMatchSnapshot(); }); it('parses simple requirements.yaml but skips if necessary fields missing', async () => { - gitfs.readLocalFile.mockResolvedValueOnce(` + fs.readLocalFile.mockResolvedValueOnce(` apiVersion: v1 appVersion: "1.0" description: A Helm chart for Kubernetes @@ -82,7 +80,7 @@ describe('lib/manager/helm-requirements/extract', () => { expect(result).toBeNull(); }); it('resolves aliased registry urls', async () => { - gitfs.readLocalFile.mockResolvedValueOnce(` + fs.readLocalFile.mockResolvedValueOnce(` apiVersion: v1 appVersion: "1.0" description: A Helm chart for Kubernetes @@ -106,7 +104,7 @@ describe('lib/manager/helm-requirements/extract', () => { expect(result.deps.every((dep) => dep.skipReason)).toEqual(false); }); it("doesn't fail if Chart.yaml is invalid", async () => { - gitfs.readLocalFile.mockResolvedValueOnce(` + fs.readLocalFile.mockResolvedValueOnce(` Invalid Chart.yaml content. arr: [ @@ -129,7 +127,7 @@ describe('lib/manager/helm-requirements/extract', () => { expect(result).toBeNull(); }); it('skips local dependencies', async () => { - gitfs.readLocalFile.mockResolvedValueOnce(` + fs.readLocalFile.mockResolvedValueOnce(` apiVersion: v1 appVersion: "1.0" description: A Helm chart for Kubernetes @@ -155,7 +153,7 @@ describe('lib/manager/helm-requirements/extract', () => { expect(result).toMatchSnapshot(); }); it('returns null if no dependencies', async () => { - gitfs.readLocalFile.mockResolvedValueOnce(` + fs.readLocalFile.mockResolvedValueOnce(` apiVersion: v1 appVersion: "1.0" description: A Helm chart for Kubernetes @@ -174,7 +172,7 @@ describe('lib/manager/helm-requirements/extract', () => { expect(result).toBeNull(); }); it('returns null if requirements.yaml is invalid', async () => { - gitfs.readLocalFile.mockResolvedValueOnce(` + fs.readLocalFile.mockResolvedValueOnce(` apiVersion: v1 appVersion: "1.0" description: A Helm chart for Kubernetes diff --git a/lib/manager/maven/index.spec.ts b/lib/manager/maven/index.spec.ts index 2f0487dfab5abb..7b0f30493565b4 100644 --- a/lib/manager/maven/index.spec.ts +++ b/lib/manager/maven/index.spec.ts @@ -1,12 +1,10 @@ import { readFileSync } from 'fs'; -import * as _gitfs from '../../util/gitfs'; +import { fs } from '../../../test/util'; import { PackageDependency, PackageFile } from '../common'; import { extractPackage, resolveParents } from './extract'; import { extractAllPackageFiles, updateDependency } from './index'; -jest.mock('../../util/gitfs'); - -const gitfs: any = _gitfs; +jest.mock('../../util/gitfs/fs'); const pomContent = readFileSync( 'lib/manager/maven/__fixtures__/simple.pom.xml', @@ -32,19 +30,19 @@ function selectDep(deps: PackageDependency[], name = 'org.example:quuz') { describe('manager/maven', () => { describe('extractAllPackageFiles', () => { it('should return empty if package has no content', async () => { - gitfs.readLocalFile.mockReturnValueOnce(null); + fs.readLocalFile.mockResolvedValueOnce(null); const res = await extractAllPackageFiles({}, ['random.pom.xml']); expect(res).toEqual([]); }); it('should return empty for packages with invalid content', async () => { - gitfs.readLocalFile.mockReturnValueOnce('invalid content'); + fs.readLocalFile.mockResolvedValueOnce('invalid content'); const res = await extractAllPackageFiles({}, ['random.pom.xml']); expect(res).toEqual([]); }); it('should return package files info', async () => { - gitfs.readLocalFile.mockReturnValueOnce(pomContent); + fs.readLocalFile.mockResolvedValueOnce(pomContent); const packages = await extractAllPackageFiles({}, ['random.pom.xml']); // windows path fix for (const p of packages) { @@ -99,9 +97,9 @@ describe('manager/maven', () => { }); it('should include registryUrls from parent pom files', async () => { - gitfs.readLocalFile - .mockReturnValueOnce(pomParent) - .mockReturnValueOnce(pomChild); + fs.readLocalFile + .mockResolvedValueOnce(pomParent) + .mockResolvedValueOnce(pomChild); const packages = await extractAllPackageFiles({}, [ 'parent.pom.xml', 'child.pom.xml', @@ -134,7 +132,7 @@ describe('manager/maven', () => { }); it('should update to version of the latest dep in implicit group', async () => { - gitfs.readLocalFile.mockReturnValueOnce(origContent); + fs.readLocalFile.mockResolvedValueOnce(origContent); const [{ deps }] = await extractAllPackageFiles({}, ['pom.xml']); const dep1 = selectDep(deps, 'org.example:foo-1'); @@ -179,7 +177,7 @@ describe('manager/maven', () => { }); it('should return null for ungrouped deps if content was updated outside', async () => { - gitfs.readLocalFile.mockReturnValueOnce(origContent); + fs.readLocalFile.mockResolvedValueOnce(origContent); const [{ deps }] = await extractAllPackageFiles({}, ['pom.xml']); const dep = selectDep(deps, 'org.example:bar'); const upgrade = { ...dep, newValue: '2.0.2' }; diff --git a/lib/manager/npm/extract/index.spec.ts b/lib/manager/npm/extract/index.spec.ts index 7cb181416ea5a1..7d7ac8a6596beb 100644 --- a/lib/manager/npm/extract/index.spec.ts +++ b/lib/manager/npm/extract/index.spec.ts @@ -1,16 +1,16 @@ -import fs from 'fs'; +import { readFileSync } from 'fs'; import path from 'path'; import { getConfig } from '../../../config/defaults'; -import * as _gitfs from '../../../util/gitfs/fs'; +import * as _fs from '../../../util/gitfs/fs'; import * as npmExtract from '.'; -const gitfs: any = _gitfs; +const fs: any = _fs; // TODO: fix types const defaultConfig = getConfig(); function readFixture(fixture: string) { - return fs.readFileSync( + return readFileSync( path.resolve(__dirname, `../__fixtures__/${fixture}`), 'utf8' ); @@ -25,7 +25,7 @@ const invalidNameContent = readFixture('invalid-name.json'); describe('manager/npm/extract', () => { describe('.extractPackageFile()', () => { beforeEach(() => { - gitfs.readLocalFile = jest.fn(() => null); + fs.readLocalFile = jest.fn(() => null); }); it('returns null if cannot parse', async () => { const res = await npmExtract.extractPackageFile( @@ -85,7 +85,7 @@ describe('manager/npm/extract', () => { expect(res).toMatchSnapshot(); }); it('finds a lock file', async () => { - gitfs.readLocalFile = jest.fn((fileName) => { + fs.readLocalFile = jest.fn((fileName) => { if (fileName === 'yarn.lock') { return '# yarn.lock'; } @@ -99,7 +99,7 @@ describe('manager/npm/extract', () => { expect(res).toMatchSnapshot(); }); it('finds and filters .npmrc', async () => { - gitfs.readLocalFile = jest.fn((fileName) => { + fs.readLocalFile = jest.fn((fileName) => { if (fileName === '.npmrc') { return 'save-exact = true\npackage-lock = false\n'; } @@ -113,7 +113,7 @@ describe('manager/npm/extract', () => { expect(res.npmrc).toBeDefined(); }); it('finds and discards .npmrc', async () => { - gitfs.readLocalFile = jest.fn((fileName) => { + fs.readLocalFile = jest.fn((fileName) => { if (fileName === '.npmrc') { // eslint-disable-next-line return '//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}\n'; @@ -128,7 +128,7 @@ describe('manager/npm/extract', () => { expect(res.npmrc).toBeUndefined(); }); it('finds lerna', async () => { - gitfs.readLocalFile = jest.fn((fileName) => { + fs.readLocalFile = jest.fn((fileName) => { if (fileName === 'lerna.json') { return '{}'; } @@ -142,7 +142,7 @@ describe('manager/npm/extract', () => { expect(res).toMatchSnapshot(); }); it('finds "npmClient":"npm" in lerna.json', async () => { - gitfs.readLocalFile = jest.fn((fileName) => { + fs.readLocalFile = jest.fn((fileName) => { if (fileName === 'lerna.json') { return '{ "npmClient": "npm" }'; } @@ -156,7 +156,7 @@ describe('manager/npm/extract', () => { expect(res).toMatchSnapshot(); }); it('finds "npmClient":"yarn" in lerna.json', async () => { - gitfs.readLocalFile = jest.fn((fileName) => { + fs.readLocalFile = jest.fn((fileName) => { if (fileName === 'lerna.json') { return '{ "npmClient": "yarn" }'; } @@ -170,7 +170,7 @@ describe('manager/npm/extract', () => { expect(res).toMatchSnapshot(); }); it('finds simple yarn workspaces', async () => { - gitfs.readLocalFile = jest.fn((fileName) => { + fs.readLocalFile = jest.fn((fileName) => { if (fileName === 'lerna.json') { return '{}'; } @@ -184,7 +184,7 @@ describe('manager/npm/extract', () => { expect(res).toMatchSnapshot(); }); it('finds complex yarn workspaces', async () => { - gitfs.readLocalFile = jest.fn((fileName) => { + fs.readLocalFile = jest.fn((fileName) => { if (fileName === 'lerna.json') { return '{}'; } diff --git a/lib/manager/npm/extract/npm.spec.ts b/lib/manager/npm/extract/npm.spec.ts index 61e399f5e3634e..0d79fa64da442e 100644 --- a/lib/manager/npm/extract/npm.spec.ts +++ b/lib/manager/npm/extract/npm.spec.ts @@ -1,15 +1,13 @@ import { readFileSync } from 'fs'; -import * as _gitfs from '../../../util/gitfs'; +import { fs } from '../../../../test/util'; import { getNpmLock } from './npm'; -jest.mock('../../../util/gitfs'); - -const gitfs: any = _gitfs; +jest.mock('../../../util/gitfs/fs'); describe('manager/npm/extract/npm', () => { describe('.getNpmLock()', () => { it('returns empty if failed to parse', async () => { - gitfs.readLocalFile.mockReturnValueOnce('abcd'); + fs.readLocalFile.mockResolvedValueOnce('abcd'); const res = await getNpmLock('package.json'); expect(Object.keys(res)).toHaveLength(0); }); @@ -17,13 +15,13 @@ describe('manager/npm/extract/npm', () => { const plocktest1Lock = readFileSync( 'lib/manager/npm/__fixtures__/plocktest1/package-lock.json' ); - gitfs.readLocalFile.mockReturnValueOnce(plocktest1Lock); + fs.readLocalFile.mockResolvedValueOnce(plocktest1Lock as never); const res = await getNpmLock('package.json'); expect(res).toMatchSnapshot(); expect(Object.keys(res)).toHaveLength(7); }); it('returns empty if no deps', async () => { - gitfs.readLocalFile.mockResolvedValueOnce('{}'); + fs.readLocalFile.mockResolvedValueOnce('{}'); const res = await getNpmLock('package.json'); expect(Object.keys(res)).toHaveLength(0); }); diff --git a/lib/manager/npm/extract/yarn.spec.ts b/lib/manager/npm/extract/yarn.spec.ts index 850e8e26b6d3c8..7bb289dab4368e 100644 --- a/lib/manager/npm/extract/yarn.spec.ts +++ b/lib/manager/npm/extract/yarn.spec.ts @@ -1,15 +1,13 @@ import { readFileSync } from 'fs'; -import * as _gitfs from '../../../util/gitfs'; +import { fs } from '../../../../test/util'; import { getYarnLock } from './yarn'; -jest.mock('../../../util/gitfs'); - -const gitfs: any = _gitfs; +jest.mock('../../../util/gitfs/fs'); describe('manager/npm/extract/yarn', () => { describe('.getYarnLock()', () => { it('returns empty if exception parsing', async () => { - gitfs.readLocalFile.mockReturnValueOnce('abcd'); + fs.readLocalFile.mockResolvedValueOnce('abcd'); const res = await getYarnLock('package.json'); expect(Object.keys(res)).toHaveLength(0); }); @@ -18,7 +16,7 @@ describe('manager/npm/extract/yarn', () => { 'lib/manager/npm/__fixtures__/plocktest1/yarn.lock', 'utf8' ); - gitfs.readLocalFile.mockReturnValueOnce(plocktest1Lock); + fs.readLocalFile.mockResolvedValueOnce(plocktest1Lock); const res = await getYarnLock('package.json'); expect(res).toMatchSnapshot(); expect(Object.keys(res)).toHaveLength(7); diff --git a/lib/manager/npm/post-update/node-version.spec.ts b/lib/manager/npm/post-update/node-version.spec.ts index fb3d4c9e148632..01519fa9efc72d 100644 --- a/lib/manager/npm/post-update/node-version.spec.ts +++ b/lib/manager/npm/post-update/node-version.spec.ts @@ -1,10 +1,7 @@ -import { mocked } from '../../../../test/util'; -import * as _gitfs from '../../../util/gitfs'; +import { fs } from '../../../../test/util'; import { getNodeConstraint } from './node-version'; -jest.mock('../../../util/gitfs'); - -const gitfs = mocked(_gitfs); +jest.mock('../../../util/gitfs/fs'); describe('getNodeConstraint', () => { const config = { @@ -12,36 +9,36 @@ describe('getNodeConstraint', () => { compatibility: { node: '^12.16.0' }, }; it('returns package.json range', async () => { - gitfs.readLocalFile = jest.fn(); - gitfs.readLocalFile.mockResolvedValueOnce(null); - gitfs.readLocalFile.mockResolvedValueOnce(null); + fs.readLocalFile = jest.fn(); + fs.readLocalFile.mockResolvedValueOnce(null); + fs.readLocalFile.mockResolvedValueOnce(null); const res = await getNodeConstraint(config); expect(res).toEqual('^12.16.0'); }); it('returns .node-version value', async () => { - gitfs.readLocalFile = jest.fn(); - gitfs.readLocalFile.mockResolvedValueOnce(null); - gitfs.readLocalFile.mockResolvedValueOnce('12.16.1\n'); + fs.readLocalFile = jest.fn(); + fs.readLocalFile.mockResolvedValueOnce(null); + fs.readLocalFile.mockResolvedValueOnce('12.16.1\n'); const res = await getNodeConstraint(config); expect(res).toEqual('12.16.1'); }); it('returns .nvmrc value', async () => { - gitfs.readLocalFile = jest.fn(); - gitfs.readLocalFile.mockResolvedValueOnce('12.16.2\n'); + fs.readLocalFile = jest.fn(); + fs.readLocalFile.mockResolvedValueOnce('12.16.2\n'); const res = await getNodeConstraint(config); expect(res).toEqual('12.16.2'); }); it('ignores unusable ranges in dotfiles', async () => { - gitfs.readLocalFile = jest.fn(); - gitfs.readLocalFile.mockResolvedValueOnce('latest'); - gitfs.readLocalFile.mockResolvedValueOnce('lts'); + fs.readLocalFile = jest.fn(); + fs.readLocalFile.mockResolvedValueOnce('latest'); + fs.readLocalFile.mockResolvedValueOnce('lts'); const res = await getNodeConstraint(config); expect(res).toEqual('^12.16.0'); }); it('returns no constraint', async () => { - gitfs.readLocalFile = jest.fn(); - gitfs.readLocalFile.mockResolvedValueOnce(null); - gitfs.readLocalFile.mockResolvedValueOnce(null); + fs.readLocalFile = jest.fn(); + fs.readLocalFile.mockResolvedValueOnce(null); + fs.readLocalFile.mockResolvedValueOnce(null); const res = await getNodeConstraint({ ...config, compatibility: null }); expect(res).toBeNull(); }); diff --git a/lib/platform/azure/index.spec.ts b/lib/platform/azure/index.spec.ts index fed43031377b86..32906620c2ac5f 100644 --- a/lib/platform/azure/index.spec.ts +++ b/lib/platform/azure/index.spec.ts @@ -1,7 +1,7 @@ import is from '@sindresorhus/is'; import { REPOSITORY_DISABLED } from '../../constants/error-messages'; import { BranchStatus } from '../../types'; -import * as _gitfs from '../../util/gitfs'; +import * as _git from '../../util/gitfs/git'; import * as _hostRules from '../../util/host-rules'; import { Platform, RepoParams } from '../common'; @@ -10,22 +10,22 @@ describe('platform/azure', () => { let azure: Platform; let azureApi: jest.Mocked; let azureHelper: jest.Mocked; - let gitfs: jest.Mocked; + let git: jest.Mocked; beforeEach(async () => { // reset module jest.resetModules(); jest.mock('./azure-got-wrapper'); jest.mock('./azure-helper'); - jest.mock('../../util/gitfs'); + jest.mock('../../util/gitfs/git'); jest.mock('../../util/host-rules'); hostRules = require('../../util/host-rules'); require('../../util/sanitize').sanitize = jest.fn((input) => input); azure = await import('.'); azureApi = require('./azure-got-wrapper'); azureHelper = require('./azure-helper'); - gitfs = require('../../util/gitfs'); - gitfs.branchExists.mockResolvedValue(true); - gitfs.isBranchStale.mockResolvedValue(false); + git = require('../../util/gitfs/git'); + git.branchExists.mockResolvedValue(true); + git.isBranchStale.mockResolvedValue(false); hostRules.find.mockReturnValue({ token: 'token', }); diff --git a/lib/platform/bitbucket-server/index.spec.ts b/lib/platform/bitbucket-server/index.spec.ts index 7b1f9f589656c3..1e9857fb3c8910 100644 --- a/lib/platform/bitbucket-server/index.spec.ts +++ b/lib/platform/bitbucket-server/index.spec.ts @@ -7,7 +7,7 @@ import { } from '../../constants/error-messages'; import { PR_STATE_CLOSED, PR_STATE_OPEN } from '../../constants/pull-requests'; import { BranchStatus } from '../../types'; -import * as _gitfs from '../../util/gitfs'; +import * as _git from '../../util/gitfs/git'; import { Platform } from '../common'; function repoMock( @@ -143,7 +143,7 @@ describe('platform/bitbucket-server', () => { describe(scenarioName, () => { let bitbucket: Platform; let hostRules: jest.Mocked; - let gitfs: jest.Mocked; + let git: jest.Mocked; async function initRepo(config = {}): Promise { const scope = httpMock @@ -172,14 +172,14 @@ describe('platform/bitbucket-server', () => { httpMock.reset(); httpMock.setup(); jest.mock('delay'); - jest.mock('../../util/gitfs'); + jest.mock('../../util/gitfs/git'); jest.mock('../../util/host-rules'); hostRules = require('../../util/host-rules'); bitbucket = await import('.'); - gitfs = require('../../util/gitfs'); - gitfs.branchExists.mockResolvedValue(true); - gitfs.isBranchStale.mockResolvedValue(false); - gitfs.getBranchCommit.mockResolvedValue( + git = require('../../util/gitfs/git'); + git.branchExists.mockResolvedValue(true); + git.isBranchStale.mockResolvedValue(false); + git.getBranchCommit.mockResolvedValue( '0d9c7726c3d628b7e28af234595cfd20febdbf8e' ); const endpoint = @@ -1788,7 +1788,7 @@ Followed by some information. }); it('throws repository-changed', async () => { - gitfs.branchExists.mockResolvedValue(false); + git.branchExists.mockResolvedValue(false); await initRepo(); await expect( bitbucket.getBranchStatus('somebranch', []) diff --git a/lib/platform/bitbucket/index.spec.ts b/lib/platform/bitbucket/index.spec.ts index cf3c01592ce001..1dbb5740c8d380 100644 --- a/lib/platform/bitbucket/index.spec.ts +++ b/lib/platform/bitbucket/index.spec.ts @@ -3,7 +3,7 @@ import * as httpMock from '../../../test/httpMock'; import { REPOSITORY_DISABLED } from '../../constants/error-messages'; import { logger as _logger } from '../../logger'; import { BranchStatus } from '../../types'; -import * as _gitfs from '../../util/gitfs'; +import * as _git from '../../util/gitfs/git'; import { setBaseUrl } from '../../util/http/bitbucket'; import { Platform, RepoParams } from '../common'; @@ -48,22 +48,22 @@ const commits = { describe('platform/bitbucket', () => { let bitbucket: Platform; let hostRules: jest.Mocked; - let gitfs: jest.Mocked; + let git: jest.Mocked; let logger: jest.Mocked; beforeEach(async () => { // reset module jest.resetModules(); httpMock.reset(); httpMock.setup(); - jest.mock('../../util/gitfs'); + jest.mock('../../util/gitfs/git'); jest.mock('../../util/host-rules'); jest.mock('../../logger'); hostRules = require('../../util/host-rules'); bitbucket = await import('.'); logger = (await import('../../logger')).logger as any; - gitfs = require('../../util/gitfs'); - gitfs.branchExists.mockResolvedValue(true); - gitfs.isBranchStale.mockResolvedValue(false); + git = require('../../util/gitfs/git'); + git.branchExists.mockResolvedValue(true); + git.isBranchStale.mockResolvedValue(false); // clean up hostRules hostRules.clear(); hostRules.find.mockReturnValue({ diff --git a/lib/platform/gitea/index.spec.ts b/lib/platform/gitea/index.spec.ts index d95ae4aedfc646..5388932ae225c9 100644 --- a/lib/platform/gitea/index.spec.ts +++ b/lib/platform/gitea/index.spec.ts @@ -18,7 +18,7 @@ import { } from '../../constants/error-messages'; import { logger as _logger } from '../../logger'; import { BranchStatus } from '../../types'; -import * as _gitfs from '../../util/gitfs'; +import * as _git from '../../util/gitfs/git'; import { setBaseUrl } from '../../util/http/gitea'; import * as ght from './gitea-helper'; @@ -26,7 +26,7 @@ describe('platform/gitea', () => { let gitea: Platform; let helper: jest.Mocked; let logger: jest.Mocked; - let gitfs: jest.Mocked; + let gitvcs: jest.Mocked; const mockCommitHash = '0d9c7726c3d628b7e28af234595cfd20febdbf8e'; @@ -157,15 +157,15 @@ describe('platform/gitea', () => { jest.resetModules(); jest.clearAllMocks(); jest.mock('./gitea-helper'); - jest.mock('../../util/gitfs'); + jest.mock('../../util/gitfs/git'); jest.mock('../../logger'); gitea = await import('.'); helper = (await import('./gitea-helper')) as any; logger = (await import('../../logger')).logger as any; - gitfs = require('../../util/gitfs'); - gitfs.isBranchStale.mockResolvedValue(false); - gitfs.getBranchCommit.mockResolvedValue(mockCommitHash); + gitvcs = require('../../util/gitfs/git'); + gitvcs.isBranchStale.mockResolvedValue(false); + gitvcs.getBranchCommit.mockResolvedValue(mockCommitHash); global.gitAuthor = { name: 'Renovate', email: 'renovate@example.com' }; @@ -331,13 +331,13 @@ describe('platform/gitea', () => { describe('cleanRepo', () => { it('does not throw an error with uninitialized repo', async () => { await gitea.cleanRepo(); - expect(gitfs.cleanRepo).toHaveBeenCalledTimes(1); + expect(gitvcs.cleanRepo).toHaveBeenCalledTimes(1); }); it('propagates call to storage class with initialized repo', async () => { await initFakeRepo(); await gitea.cleanRepo(); - expect(gitfs.cleanRepo).toHaveBeenCalledTimes(1); + expect(gitvcs.cleanRepo).toHaveBeenCalledTimes(1); }); }); @@ -410,16 +410,18 @@ describe('platform/gitea', () => { await initFakeRepo(); await gitea.setBaseBranch(); - expect(gitfs.setBaseBranch).toHaveBeenCalledTimes(1); - expect(gitfs.setBaseBranch).toHaveBeenCalledWith(mockRepo.default_branch); + expect(gitvcs.setBaseBranch).toHaveBeenCalledTimes(1); + expect(gitvcs.setBaseBranch).toHaveBeenCalledWith( + mockRepo.default_branch + ); }); it('should set custom base branch', async () => { await initFakeRepo(); await gitea.setBaseBranch('devel'); - expect(gitfs.setBaseBranch).toHaveBeenCalledTimes(1); - expect(gitfs.setBaseBranch).toHaveBeenCalledWith('devel'); + expect(gitvcs.setBaseBranch).toHaveBeenCalledTimes(1); + expect(gitvcs.setBaseBranch).toHaveBeenCalledWith('devel'); }); }); @@ -1289,8 +1291,8 @@ describe('platform/gitea', () => { await initFakeRepo(); await gitea.deleteBranch('some-branch'); - expect(gitfs.deleteBranch).toHaveBeenCalledTimes(1); - expect(gitfs.deleteBranch).toHaveBeenCalledWith('some-branch'); + expect(gitvcs.deleteBranch).toHaveBeenCalledTimes(1); + expect(gitvcs.deleteBranch).toHaveBeenCalledWith('some-branch'); }); it('should not close pull request by default', async () => { @@ -1311,8 +1313,8 @@ describe('platform/gitea', () => { mockRepo.full_name, mockPR.number ); - expect(gitfs.deleteBranch).toHaveBeenCalledTimes(1); - expect(gitfs.deleteBranch).toHaveBeenCalledWith(mockPR.head.label); + expect(gitvcs.deleteBranch).toHaveBeenCalledTimes(1); + expect(gitvcs.deleteBranch).toHaveBeenCalledWith(mockPR.head.label); }); it('should skip closing pull request if missing', async () => { @@ -1321,8 +1323,8 @@ describe('platform/gitea', () => { await gitea.deleteBranch('missing', true); expect(helper.closePR).not.toHaveBeenCalled(); - expect(gitfs.deleteBranch).toHaveBeenCalledTimes(1); - expect(gitfs.deleteBranch).toHaveBeenCalledWith('missing'); + expect(gitvcs.deleteBranch).toHaveBeenCalledTimes(1); + expect(gitvcs.deleteBranch).toHaveBeenCalledWith('missing'); }); }); @@ -1358,8 +1360,8 @@ describe('platform/gitea', () => { await initFakeRepo(); await gitea.commitFiles(commitConfig); - expect(gitfs.commitFiles).toHaveBeenCalledTimes(1); - expect(gitfs.commitFiles).toHaveBeenCalledWith({ + expect(gitvcs.commitFiles).toHaveBeenCalledTimes(1); + expect(gitvcs.commitFiles).toHaveBeenCalledWith({ ...commitConfig, }); }); @@ -1378,8 +1380,8 @@ describe('platform/gitea', () => { await initFakeRepo(); await gitea.isBranchStale('some-branch'); - expect(gitfs.isBranchStale).toHaveBeenCalledTimes(1); - expect(gitfs.isBranchStale).toHaveBeenCalledWith('some-branch'); + expect(gitvcs.isBranchStale).toHaveBeenCalledTimes(1); + expect(gitvcs.isBranchStale).toHaveBeenCalledWith('some-branch'); }); }); @@ -1388,8 +1390,8 @@ describe('platform/gitea', () => { await initFakeRepo(); await gitea.setBranchPrefix('some-branch'); - expect(gitfs.setBranchPrefix).toHaveBeenCalledTimes(1); - expect(gitfs.setBranchPrefix).toHaveBeenCalledWith('some-branch'); + expect(gitvcs.setBranchPrefix).toHaveBeenCalledTimes(1); + expect(gitvcs.setBranchPrefix).toHaveBeenCalledWith('some-branch'); }); }); @@ -1398,8 +1400,8 @@ describe('platform/gitea', () => { await initFakeRepo(); await gitea.branchExists('some-branch'); - expect(gitfs.branchExists).toHaveBeenCalledTimes(1); - expect(gitfs.branchExists).toHaveBeenCalledWith('some-branch'); + expect(gitvcs.branchExists).toHaveBeenCalledTimes(1); + expect(gitvcs.branchExists).toHaveBeenCalledWith('some-branch'); }); }); @@ -1408,8 +1410,8 @@ describe('platform/gitea', () => { await initFakeRepo(); await gitea.mergeBranch('some-branch'); - expect(gitfs.mergeBranch).toHaveBeenCalledTimes(1); - expect(gitfs.mergeBranch).toHaveBeenCalledWith('some-branch'); + expect(gitvcs.mergeBranch).toHaveBeenCalledTimes(1); + expect(gitvcs.mergeBranch).toHaveBeenCalledWith('some-branch'); }); }); @@ -1418,8 +1420,10 @@ describe('platform/gitea', () => { await initFakeRepo(); await gitea.getBranchLastCommitTime('some-branch'); - expect(gitfs.getBranchLastCommitTime).toHaveBeenCalledTimes(1); - expect(gitfs.getBranchLastCommitTime).toHaveBeenCalledWith('some-branch'); + expect(gitvcs.getBranchLastCommitTime).toHaveBeenCalledTimes(1); + expect(gitvcs.getBranchLastCommitTime).toHaveBeenCalledWith( + 'some-branch' + ); }); }); @@ -1428,8 +1432,8 @@ describe('platform/gitea', () => { await initFakeRepo(); await gitea.getFile('some-file', 'some-branch'); - expect(gitfs.getFile).toHaveBeenCalledTimes(1); - expect(gitfs.getFile).toHaveBeenCalledWith('some-file', 'some-branch'); + expect(gitvcs.getFile).toHaveBeenCalledTimes(1); + expect(gitvcs.getFile).toHaveBeenCalledWith('some-file', 'some-branch'); }); }); @@ -1438,7 +1442,7 @@ describe('platform/gitea', () => { await initFakeRepo(); await gitea.getRepoStatus(); - expect(gitfs.getRepoStatus).toHaveBeenCalledTimes(1); + expect(gitvcs.getRepoStatus).toHaveBeenCalledTimes(1); }); }); @@ -1447,7 +1451,7 @@ describe('platform/gitea', () => { await initFakeRepo(); await gitea.getFileList(); - expect(gitfs.getFileList).toHaveBeenCalledTimes(1); + expect(gitvcs.getFileList).toHaveBeenCalledTimes(1); }); }); @@ -1456,8 +1460,8 @@ describe('platform/gitea', () => { await initFakeRepo(); await gitea.getAllRenovateBranches('some-prefix'); - expect(gitfs.getAllRenovateBranches).toHaveBeenCalledTimes(1); - expect(gitfs.getAllRenovateBranches).toHaveBeenCalledWith('some-prefix'); + expect(gitvcs.getAllRenovateBranches).toHaveBeenCalledTimes(1); + expect(gitvcs.getAllRenovateBranches).toHaveBeenCalledWith('some-prefix'); }); }); @@ -1466,7 +1470,7 @@ describe('platform/gitea', () => { await initFakeRepo(); await gitea.getCommitMessages(); - expect(gitfs.getCommitMessages).toHaveBeenCalledTimes(1); + expect(gitvcs.getCommitMessages).toHaveBeenCalledTimes(1); }); }); diff --git a/lib/platform/github/index.spec.ts b/lib/platform/github/index.spec.ts index a287c9ee0d570d..7834a77cbb7a7a 100644 --- a/lib/platform/github/index.spec.ts +++ b/lib/platform/github/index.spec.ts @@ -7,7 +7,7 @@ import { REPOSITORY_RENAMED, } from '../../constants/error-messages'; import { BranchStatus } from '../../types'; -import * as _gitfs from '../../util/gitfs'; +import * as _git from '../../util/gitfs/git'; import { Platform } from '../common'; const githubApiHost = 'https://api.github.com'; @@ -15,7 +15,7 @@ const githubApiHost = 'https://api.github.com'; describe('platform/github', () => { let github: Platform; let hostRules: jest.Mocked; - let gitfs: jest.Mocked; + let git: jest.Mocked; beforeEach(async () => { // reset module jest.resetModules(); @@ -24,11 +24,11 @@ describe('platform/github', () => { jest.mock('../../util/host-rules'); github = await import('.'); hostRules = mocked(await import('../../util/host-rules')); - jest.mock('../../util/gitfs'); - gitfs = mocked(await import('../../util/gitfs')); - gitfs.branchExists.mockResolvedValue(true); - gitfs.isBranchStale.mockResolvedValue(true); - gitfs.getBranchCommit.mockResolvedValue( + jest.mock('../../util/gitfs/git'); + git = mocked(await import('../../util/gitfs/git')); + git.branchExists.mockResolvedValue(true); + git.isBranchStale.mockResolvedValue(true); + git.getBranchCommit.mockResolvedValue( '0d9c7726c3d628b7e28af234595cfd20febdbf8e' ); delete global.gitAuthor; diff --git a/lib/platform/gitlab/index.spec.ts b/lib/platform/gitlab/index.spec.ts index dca6e43fddb744..05d5975cf43b5a 100644 --- a/lib/platform/gitlab/index.spec.ts +++ b/lib/platform/gitlab/index.spec.ts @@ -14,7 +14,7 @@ import { PR_STATE_OPEN, } from '../../constants/pull-requests'; import { BranchStatus } from '../../types'; -import * as _gitfs from '../../util/gitfs'; +import * as _git from '../../util/gitfs/git'; import * as _hostRules from '../../util/host-rules'; const gitlabApiHost = 'https://gitlab.com'; @@ -22,7 +22,7 @@ const gitlabApiHost = 'https://gitlab.com'; describe('platform/gitlab', () => { let gitlab: Platform; let hostRules: jest.Mocked; - let gitfs: jest.Mocked; + let git: jest.Mocked; beforeEach(async () => { // reset module jest.resetModules(); @@ -31,11 +31,11 @@ describe('platform/gitlab', () => { jest.mock('../../util/host-rules'); jest.mock('delay'); hostRules = require('../../util/host-rules'); - jest.mock('../../util/gitfs'); - gitfs = require('../../util/gitfs'); - gitfs.branchExists.mockResolvedValue(true); - gitfs.isBranchStale.mockResolvedValue(true); - gitfs.getBranchCommit.mockResolvedValue( + jest.mock('../../util/gitfs/git'); + git = require('../../util/gitfs/git'); + git.branchExists.mockResolvedValue(true); + git.isBranchStale.mockResolvedValue(true); + git.getBranchCommit.mockResolvedValue( '0d9c7726c3d628b7e28af234595cfd20febdbf8e' ); hostRules.find.mockReturnValue({ @@ -578,7 +578,7 @@ describe('platform/gitlab', () => { }); it('throws repository-changed', async () => { expect.assertions(2); - gitfs.branchExists.mockResolvedValue(false); + git.branchExists.mockResolvedValue(false); await initRepo(); await expect(gitlab.getBranchStatus('somebranch', [])).rejects.toThrow( REPOSITORY_CHANGED diff --git a/lib/util/gitfs/git/index.spec.ts b/lib/util/gitfs/git/index.spec.ts index 3e9e8af2173cdc..156ac77652e344 100644 --- a/lib/util/gitfs/git/index.spec.ts +++ b/lib/util/gitfs/git/index.spec.ts @@ -1,7 +1,7 @@ import fs from 'fs-extra'; import Git from 'simple-git/promise'; import tmp from 'tmp-promise'; -import * as gitfs from '.'; +import * as git from '.'; describe('platform/git', () => { jest.setTimeout(15000); @@ -46,7 +46,7 @@ describe('platform/git', () => { const repo = Git(origin.path); await repo.clone(base.path, '.', ['--bare']); tmpDir = await tmp.dir({ unsafeCleanup: true }); - await gitfs.initRepo({ + await git.initRepo({ localDir: tmpDir.path, url: origin.path, extraCloneOpts: { @@ -60,7 +60,7 @@ describe('platform/git', () => { afterEach(async () => { await tmpDir.cleanup(); await origin.cleanup(); - gitfs.cleanRepo(); + git.cleanRepo(); }); afterAll(async () => { @@ -69,45 +69,45 @@ describe('platform/git', () => { describe('setBaseBranch(branchName)', () => { it('sets the base branch as master', async () => { - await expect(gitfs.setBaseBranch('master')).resolves.not.toThrow(); + await expect(git.setBaseBranch('master')).resolves.not.toThrow(); }); it('sets non-master base branch', async () => { - await expect(gitfs.setBaseBranch('develop')).resolves.not.toThrow(); + await expect(git.setBaseBranch('develop')).resolves.not.toThrow(); }); it('should throw if branch does not exist', async () => { - await expect(gitfs.setBaseBranch('not_found')).rejects.toMatchSnapshot(); + await expect(git.setBaseBranch('not_found')).rejects.toMatchSnapshot(); }); }); describe('getFileList()', () => { it('should return the correct files', async () => { - expect(await gitfs.getFileList()).toMatchSnapshot(); + expect(await git.getFileList()).toMatchSnapshot(); }); it('should exclude submodules', async () => { const repo = Git(base.path).silent(true); await repo.submoduleAdd(base.path, 'submodule'); await repo.commit('Add submodule'); - await gitfs.initRepo({ + await git.initRepo({ localDir: tmpDir.path, url: base.path, }); expect(await fs.exists(tmpDir.path + '/.gitmodules')).toBeTruthy(); - expect(await gitfs.getFileList()).toMatchSnapshot(); + expect(await git.getFileList()).toMatchSnapshot(); await repo.reset(['--hard', 'HEAD^']); }); }); describe('branchExists(branchName)', () => { it('should return true if found', async () => { - expect(await gitfs.branchExists('renovate/future_branch')).toBe(true); - expect(await gitfs.branchExists('renovate/future_branch')).toBe(true); // should come from cache + expect(await git.branchExists('renovate/future_branch')).toBe(true); + expect(await git.branchExists('renovate/future_branch')).toBe(true); // should come from cache }); it('should return false if not found', async () => { - expect(await gitfs.branchExists('not_found')).toBe(false); + expect(await git.branchExists('not_found')).toBe(false); }); }); describe('getAllRenovateBranches()', () => { it('should return all renovate branches', async () => { - await gitfs.setBranchPrefix('renovate/'); - const res = await gitfs.getAllRenovateBranches('renovate/'); + await git.setBranchPrefix('renovate/'); + const res = await git.getAllRenovateBranches('renovate/'); expect(res).toContain('renovate/past_branch'); expect(res).toContain('renovate/future_branch'); expect(res).not.toContain('master'); @@ -115,72 +115,68 @@ describe('platform/git', () => { }); describe('isBranchStale()', () => { it('should return false if same SHA as master', async () => { - expect(await gitfs.isBranchStale('renovate/future_branch')).toBe(false); + expect(await git.isBranchStale('renovate/future_branch')).toBe(false); }); it('should return true if SHA different from master', async () => { - expect(await gitfs.isBranchStale('renovate/past_branch')).toBe(true); + expect(await git.isBranchStale('renovate/past_branch')).toBe(true); }); it('should throw if branch does not exist', async () => { - await expect(gitfs.isBranchStale('not_found')).rejects.toMatchSnapshot(); + await expect(git.isBranchStale('not_found')).rejects.toMatchSnapshot(); }); }); describe('getBranchCommit(branchName)', () => { it('should return same value for equal refs', async () => { - const hex = await gitfs.getBranchCommit('renovate/past_branch'); - expect(hex).toBe(await gitfs.getBranchCommit('master~1')); + const hex = await git.getBranchCommit('renovate/past_branch'); + expect(hex).toBe(await git.getBranchCommit('master~1')); expect(hex).toHaveLength(40); }); it('should throw if branch does not exist', async () => { - await expect( - gitfs.getBranchCommit('not_found') - ).rejects.toMatchSnapshot(); + await expect(git.getBranchCommit('not_found')).rejects.toMatchSnapshot(); }); }); describe('createBranch(branchName, sha)', () => { it('resets existing branch', async () => { - const hex = await gitfs.getBranchCommit('renovate/past_branch'); - expect(await gitfs.getBranchCommit('renovate/future_branch')).not.toBe( - hex - ); - await gitfs.createBranch('renovate/future_branch', hex); - expect(await gitfs.getBranchCommit('renovate/future_branch')).toBe(hex); + const hex = await git.getBranchCommit('renovate/past_branch'); + expect(await git.getBranchCommit('renovate/future_branch')).not.toBe(hex); + await git.createBranch('renovate/future_branch', hex); + expect(await git.getBranchCommit('renovate/future_branch')).toBe(hex); }); }); describe('getBranchFiles(branchName, baseBranchName?)', () => { it('detects changed files', async () => { - const hex = await gitfs.getBranchCommit('master'); - await gitfs.createBranch('renovate/branch_with_changes', hex); + const hex = await git.getBranchCommit('master'); + await git.createBranch('renovate/branch_with_changes', hex); const file = { name: 'some-new-file', contents: 'some new-contents', }; - await gitfs.commitFiles({ + await git.commitFiles({ branchName: 'renovate/branch_with_changes', files: [file], message: 'Create something', }); - const branchFiles = await gitfs.getBranchFiles( + const branchFiles = await git.getBranchFiles( 'renovate/branch_with_changes', 'master' ); expect(branchFiles).toMatchSnapshot(); }); it('detects changed files compared to current base branch', async () => { - const hex = await gitfs.getBranchCommit('master'); - await gitfs.createBranch('renovate/branch_with_changes', hex); + const hex = await git.getBranchCommit('master'); + await git.createBranch('renovate/branch_with_changes', hex); const file = { name: 'some-new-file', contents: 'some new-contents', }; - await gitfs.commitFiles({ + await git.commitFiles({ branchName: 'renovate/branch_with_changes', files: [file], message: 'Create something', }); - const branchFiles = await gitfs.getBranchFiles( + const branchFiles = await git.getBranchFiles( 'renovate/branch_with_changes' ); expect(branchFiles).toMatchSnapshot(); @@ -189,8 +185,8 @@ describe('platform/git', () => { describe('mergeBranch(branchName)', () => { it('should perform a branch merge', async () => { - await gitfs.setBranchPrefix('renovate/'); - await gitfs.mergeBranch('renovate/future_branch'); + await git.setBranchPrefix('renovate/'); + await git.mergeBranch('renovate/future_branch'); const merged = await Git(origin.path).branch([ '--verbose', '--merged', @@ -199,38 +195,38 @@ describe('platform/git', () => { expect(merged.all).toContain('renovate/future_branch'); }); it('should throw if branch merge throws', async () => { - await expect(gitfs.mergeBranch('not_found')).rejects.toThrow(); + await expect(git.mergeBranch('not_found')).rejects.toThrow(); }); }); describe('deleteBranch(branchName)', () => { it('should send delete', async () => { - await gitfs.deleteBranch('renovate/past_branch'); + await git.deleteBranch('renovate/past_branch'); const branches = await Git(origin.path).branch({}); expect(branches.all).not.toContain('renovate/past_branch'); }); }); describe('getBranchLastCommitTime', () => { it('should return a Date', async () => { - const time = await gitfs.getBranchLastCommitTime('master'); + const time = await git.getBranchLastCommitTime('master'); expect(time).toEqual(masterCommitDate); }); it('handles error', async () => { - const res = await gitfs.getBranchLastCommitTime('some-branch'); + const res = await git.getBranchLastCommitTime('some-branch'); expect(res).toBeDefined(); }); }); describe('getFile(filePath, branchName)', () => { it('gets the file', async () => { - const res = await gitfs.getFile('master_file'); + const res = await git.getFile('master_file'); expect(res).toBe('master'); }); it('short cuts 404', async () => { - const res = await gitfs.getFile('some-missing-path'); + const res = await git.getFile('some-missing-path'); expect(res).toBeNull(); }); it('returns null for 404', async () => { await expect( - gitfs.getFile('some-path', 'some-branch') + git.getFile('some-path', 'some-branch') ).rejects.toMatchSnapshot(); }); }); @@ -240,7 +236,7 @@ describe('platform/git', () => { name: 'some-new-file', contents: 'some new-contents', }; - const commit = await gitfs.commitFiles({ + const commit = await git.commitFiles({ branchName: 'renovate/past_branch', files: [file], message: 'Create something', @@ -252,7 +248,7 @@ describe('platform/git', () => { name: '|delete|', contents: 'file_to_delete', }; - const commit = await gitfs.commitFiles({ + const commit = await git.commitFiles({ branchName: 'renovate/something', files: [file], message: 'Delete something', @@ -270,7 +266,7 @@ describe('platform/git', () => { contents: 'other updated content', }, ]; - const commit = await gitfs.commitFiles({ + const commit = await git.commitFiles({ branchName: 'renovate/something', files, message: 'Update something', @@ -284,7 +280,7 @@ describe('platform/git', () => { contents: 'some content', }, ]; - const commit = await gitfs.commitFiles({ + const commit = await git.commitFiles({ branchName: 'renovate/something', files, message: 'Update something', @@ -300,7 +296,7 @@ describe('platform/git', () => { `refs/heads/${branchName}:refs/remotes/origin/${branchName}`, ]); const files = []; - const commit = await gitfs.commitFiles({ + const commit = await git.commitFiles({ branchName, files, message: 'Update something', @@ -311,12 +307,12 @@ describe('platform/git', () => { describe('getCommitMessages()', () => { it('returns commit messages', async () => { - expect(await gitfs.getCommitMessages()).toMatchSnapshot(); + expect(await git.getCommitMessages()).toMatchSnapshot(); }); }); describe('Storage.getUrl()', () => { - const getUrl = gitfs.getUrl; + const getUrl = git.getUrl; it('returns https url', () => { expect( getUrl({ @@ -356,22 +352,22 @@ describe('platform/git', () => { await repo.commit('past message2'); await repo.checkout('master'); - expect(await gitfs.branchExists('test')).toBeFalsy(); + expect(await git.branchExists('test')).toBeFalsy(); - expect(await gitfs.getCommitMessages()).toMatchSnapshot(); + expect(await git.getCommitMessages()).toMatchSnapshot(); - await gitfs.setBaseBranch('develop'); + await git.setBaseBranch('develop'); - await gitfs.initRepo({ + await git.initRepo({ localDir: tmpDir.path, url: base.path, }); - expect(await gitfs.branchExists('test')).toBeTruthy(); + expect(await git.branchExists('test')).toBeTruthy(); - await gitfs.setBaseBranch('test'); + await git.setBaseBranch('test'); - const msg = await gitfs.getCommitMessages(); + const msg = await git.getCommitMessages(); expect(msg).toMatchSnapshot(); expect(msg).toContain('past message2'); }); @@ -384,16 +380,16 @@ describe('platform/git', () => { await repo.commit('past message2'); await repo.checkout('master'); - await gitfs.initRepo({ + await git.initRepo({ localDir: tmpDir.path, url: base.path, }); - await gitfs.setBranchPrefix('renovate/'); - expect(await gitfs.branchExists('renovate/test')).toBe(true); - const cid = await gitfs.getBranchCommit('renovate/test'); + await git.setBranchPrefix('renovate/'); + expect(await git.branchExists('renovate/test')).toBe(true); + const cid = await git.getBranchCommit('renovate/test'); - await gitfs.initRepo({ + await git.initRepo({ localDir: tmpDir.path, url: base.path, }); @@ -401,9 +397,9 @@ describe('platform/git', () => { await repo.checkout('renovate/test'); await repo.commit('past message3', ['--amend']); - await gitfs.setBranchPrefix('renovate/'); - expect(await gitfs.branchExists('renovate/test')).toBe(true); - expect(await gitfs.getBranchCommit('renovate/test')).not.toEqual(cid); + await git.setBranchPrefix('renovate/'); + expect(await git.branchExists('renovate/test')).toBe(true); + expect(await git.getBranchCommit('renovate/test')).not.toEqual(cid); }); it('should fail clone ssh submodule', async () => { @@ -422,7 +418,7 @@ describe('platform/git', () => { 'test', ]); await repo.commit('Add submodule'); - await gitfs.initRepo({ + await git.initRepo({ localDir: tmpDir.path, url: base.path, }); diff --git a/lib/util/gitfs/git/index.ts b/lib/util/gitfs/git/index.ts index eb6a86555e45da..c08b3caa821953 100644 --- a/lib/util/gitfs/git/index.ts +++ b/lib/util/gitfs/git/index.ts @@ -15,6 +15,8 @@ import { ExternalHostError } from '../../../types/errors/external-host-error'; import * as limits from '../../../workers/global/limits'; import { writePrivateKey } from './private-key'; +export * from './private-key'; + declare module 'fs-extra' { export function exists(pathLike: string): Promise; } diff --git a/lib/util/gitfs/index.ts b/lib/util/gitfs/index.ts index dc681c92741c9e..c4924195be6872 100644 --- a/lib/util/gitfs/index.ts +++ b/lib/util/gitfs/index.ts @@ -1,3 +1,2 @@ export * from './fs'; export * from './git'; -export * from './git/private-key'; diff --git a/lib/workers/branch/auto-replace.spec.ts b/lib/workers/branch/auto-replace.spec.ts index f0a297b0242eca..0d669c138148d9 100644 --- a/lib/workers/branch/auto-replace.spec.ts +++ b/lib/workers/branch/auto-replace.spec.ts @@ -10,7 +10,7 @@ const sampleHtml = readFileSync( 'utf8' ); -jest.mock('../../util/gitfs'); +jest.mock('../../util/gitfs/fs'); describe('workers/branch/auto-replace', () => { describe('doAutoReplace', () => { diff --git a/lib/workers/repository/extract/manager-files.spec.ts b/lib/workers/repository/extract/manager-files.spec.ts index f68fddc3e591ec..c447596b4516fe 100644 --- a/lib/workers/repository/extract/manager-files.spec.ts +++ b/lib/workers/repository/extract/manager-files.spec.ts @@ -1,15 +1,13 @@ -import { getConfig, mocked } from '../../../../test/util'; +import { fs, getConfig, mocked } from '../../../../test/util'; import { RenovateConfig } from '../../../config'; import * as _html from '../../../manager/html'; -import * as _gitfs from '../../../util/gitfs'; import * as _fileMatch from './file-match'; import { getManagerPackageFiles } from './manager-files'; jest.mock('./file-match'); jest.mock('../../../manager/html'); -jest.mock('../../../util/gitfs'); +jest.mock('../../../util/gitfs/fs'); -const gitfs: any = _gitfs; const fileMatch = mocked(_fileMatch); const html = mocked(_html); @@ -44,7 +42,7 @@ describe('workers/repository/extract/manager-files', () => { fileList: ['Dockerfile'], }; fileMatch.getMatchingFiles.mockResolvedValue(['Dockerfile']); - gitfs.readLocalFile.mockResolvedValueOnce('some content'); + fs.readLocalFile.mockResolvedValueOnce('some content'); html.extractPackageFile = jest.fn(() => ({ deps: [{}, { replaceString: 'abc' }], })) as never; @@ -58,7 +56,7 @@ describe('workers/repository/extract/manager-files', () => { fileList: ['package.json'], }; fileMatch.getMatchingFiles.mockResolvedValue(['package.json']); - gitfs.readLocalFile.mockResolvedValueOnce( + fs.readLocalFile.mockResolvedValueOnce( '{"dependencies":{"chalk":"2.0.0"}}' ); const res = await getManagerPackageFiles(managerConfig); diff --git a/lib/workers/repository/init/config.spec.ts b/lib/workers/repository/init/config.spec.ts index ae19098d527527..4fe7364f228f9c 100644 --- a/lib/workers/repository/init/config.spec.ts +++ b/lib/workers/repository/init/config.spec.ts @@ -1,14 +1,14 @@ import { RenovateConfig, + fs, getConfig, - gitfs, mocked, platform, } from '../../../../test/util'; import * as _migrateAndValidate from '../../../config/migrate-validate'; import { mergeRenovateConfig } from './config'; -jest.mock('../../../util/gitfs'); +jest.mock('../../../util/gitfs/fs'); const migrateAndValidate = mocked(_migrateAndValidate); @@ -32,7 +32,7 @@ describe('workers/repository/init/config', () => { }); it('returns config if not found', async () => { platform.getFileList.mockResolvedValue(['package.json']); - gitfs.readLocalFile.mockResolvedValue('{}'); + fs.readLocalFile.mockResolvedValue('{}'); const res = await mergeRenovateConfig(config); expect(res).toMatchObject(config); }); @@ -44,13 +44,13 @@ describe('workers/repository/init/config', () => { prHourlyLimit: 10, }, }); - gitfs.readLocalFile.mockResolvedValue(pJson); + fs.readLocalFile.mockResolvedValue(pJson); const renovateConfig = await mergeRenovateConfig(config); expect(renovateConfig).toBeTruthy(); }); it('returns error if cannot parse', async () => { platform.getFileList.mockResolvedValue(['package.json', 'renovate.json']); - gitfs.readLocalFile.mockResolvedValue('cannot parse'); + fs.readLocalFile.mockResolvedValue('cannot parse'); let e; try { await mergeRenovateConfig(config); @@ -64,7 +64,7 @@ describe('workers/repository/init/config', () => { }); it('throws error if duplicate keys', async () => { platform.getFileList.mockResolvedValue(['package.json', '.renovaterc']); - gitfs.readLocalFile.mockResolvedValue( + fs.readLocalFile.mockResolvedValue( '{ "enabled": true, "enabled": false }' ); let e; @@ -83,7 +83,7 @@ describe('workers/repository/init/config', () => { 'package.json', 'renovate.json5', ]); - gitfs.readLocalFile.mockResolvedValue(`{ + fs.readLocalFile.mockResolvedValue(`{ // this is json5 format }`); const renovateConfig = await mergeRenovateConfig(config); @@ -94,7 +94,7 @@ describe('workers/repository/init/config', () => { 'package.json', '.github/renovate.json', ]); - gitfs.readLocalFile.mockResolvedValue('{}'); + fs.readLocalFile.mockResolvedValue('{}'); const renovateConfig = await mergeRenovateConfig(config); expect(renovateConfig).toBeTruthy(); }); @@ -103,7 +103,7 @@ describe('workers/repository/init/config', () => { 'package.json', '.gitlab/renovate.json', ]); - gitfs.readLocalFile.mockResolvedValue('{}'); + fs.readLocalFile.mockResolvedValue('{}'); const renovateConfig = await mergeRenovateConfig(config); expect(renovateConfig).toBeTruthy(); }); @@ -112,7 +112,7 @@ describe('workers/repository/init/config', () => { 'package.json', '.renovaterc.json', ]); - gitfs.readLocalFile.mockResolvedValue('{}'); + fs.readLocalFile.mockResolvedValue('{}'); const renovateConfig = await mergeRenovateConfig(config); expect(renovateConfig).toBeTruthy(); }); @@ -121,7 +121,7 @@ describe('workers/repository/init/config', () => { 'package.json', '.renovaterc.json', ]); - gitfs.readLocalFile.mockResolvedValue('{}'); + fs.readLocalFile.mockResolvedValue('{}'); migrateAndValidate.migrateAndValidate.mockResolvedValueOnce({ errors: [{ depName: 'dep', message: 'test error' }], }); diff --git a/lib/workers/repository/onboarding/branch/index.spec.ts b/lib/workers/repository/onboarding/branch/index.spec.ts index 7df826de279d6e..b1b966b4c7ffba 100644 --- a/lib/workers/repository/onboarding/branch/index.spec.ts +++ b/lib/workers/repository/onboarding/branch/index.spec.ts @@ -1,8 +1,8 @@ import { mock } from 'jest-mock-extended'; import { RenovateConfig, + fs, getConfig, - gitfs, platform, } from '../../../../../test/util'; import { PR_STATE_OPEN } from '../../../../constants/pull-requests'; @@ -13,7 +13,7 @@ import { checkOnboardingBranch } from '.'; const rebase: any = _rebase; jest.mock('../../../../workers/repository/onboarding/branch/rebase'); -jest.mock('../../../../util/gitfs'); +jest.mock('../../../../util/gitfs/fs'); describe('workers/repository/onboarding/branch', () => { describe('checkOnboardingBranch', () => { @@ -32,7 +32,7 @@ describe('workers/repository/onboarding/branch', () => { }); it('has default onboarding config', async () => { platform.getFileList.mockResolvedValue(['package.json']); - gitfs.readLocalFile.mockResolvedValue('{}'); + fs.readLocalFile.mockResolvedValue('{}'); await checkOnboardingBranch(config); expect( platform.commitFiles.mock.calls[0][0].files[0].contents @@ -55,7 +55,7 @@ describe('workers/repository/onboarding/branch', () => { config.requireConfig = true; config.onboarding = false; platform.getFileList.mockResolvedValueOnce(['package.json']); - gitfs.readLocalFile.mockResolvedValueOnce('{}'); + fs.readLocalFile.mockResolvedValueOnce('{}'); const onboardingResult = checkOnboardingBranch(config); await expect(onboardingResult).rejects.toThrow('disabled'); }); @@ -66,7 +66,7 @@ describe('workers/repository/onboarding/branch', () => { }); it('detects repo is onboarded via package.json config', async () => { platform.getFileList.mockResolvedValueOnce(['package.json']); - gitfs.readLocalFile.mockResolvedValueOnce('{"renovate":{}}'); + fs.readLocalFile.mockResolvedValueOnce('{"renovate":{}}'); const res = await checkOnboardingBranch(config); expect(res.repoIsOnboarded).toBe(true); }); @@ -99,7 +99,7 @@ describe('workers/repository/onboarding/branch', () => { ignore: ['foo', 'bar'], }, }); - gitfs.readLocalFile.mockResolvedValue(pJsonContent); + fs.readLocalFile.mockResolvedValue(pJsonContent); platform.commitFiles.mockResolvedValueOnce('abc123'); await checkOnboardingBranch(config); expect( diff --git a/test/util.ts b/test/util.ts index 90f324bd058442..4d662f001f4b70 100644 --- a/test/util.ts +++ b/test/util.ts @@ -4,7 +4,8 @@ import { RenovateConfig as _RenovateConfig } from '../lib/config'; import { getConfig } from '../lib/config/defaults'; import { platform as _platform } from '../lib/platform'; import * as _env from '../lib/util/exec/env'; -import * as _gitfs from '../lib/util/gitfs'; +import * as _fs from '../lib/util/gitfs/fs'; +import * as _git from '../lib/util/gitfs/git'; import * as _hostRules from '../lib/util/host-rules'; /** @@ -23,7 +24,8 @@ export function partial(obj: Partial): T { return obj as T; } -export const gitfs = mocked(_gitfs); +export const fs = mocked(_fs); +export const git = mocked(_git); export const platform = mocked(_platform); export const env = mocked(_env); export const hostRules = mocked(_hostRules);