From ac598aae98cfc27e0d773c8b6b6181dc17d50958 Mon Sep 17 00:00:00 2001 From: Michael Kriese <michael.kriese@visualon.de> Date: Tue, 14 Feb 2023 22:39:04 +0100 Subject: [PATCH] test: fix tests on windows (#20412) --- .../manager/gradle-wrapper/artifacts.spec.ts | 7 +++--- lib/modules/manager/gradle/artifacts.spec.ts | 5 ++-- .../manager/maven-wrapper/artifacts.spec.ts | 24 ++++++++++++------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/modules/manager/gradle-wrapper/artifacts.spec.ts b/lib/modules/manager/gradle-wrapper/artifacts.spec.ts index a5d34e1d1e..184e18eac2 100644 --- a/lib/modules/manager/gradle-wrapper/artifacts.spec.ts +++ b/lib/modules/manager/gradle-wrapper/artifacts.spec.ts @@ -26,7 +26,7 @@ jest.mock('../../../util/git'); jest.mock('../../../util/exec/env'); jest.mock('../../datasource'); -process.env.BUILDPACK = 'true'; +process.env.CONTAINERBASE = 'true'; const adminConfig: RepoGlobalConfig = { // `join` fixes Windows CI @@ -39,12 +39,11 @@ const config: UpdateArtifactsConfig = { newValue: '5.6.4', }; -jest.spyOn(os, 'platform').mockReturnValue('linux'); +const osPlatformSpy = jest.spyOn(os, 'platform'); describe('modules/manager/gradle-wrapper/artifacts', () => { beforeEach(() => { - jest.resetAllMocks(); - + osPlatformSpy.mockReturnValue('linux'); env.getChildProcessEnv.mockReturnValue({ ...envMock.basic, LANG: 'en_US.UTF-8', diff --git a/lib/modules/manager/gradle/artifacts.spec.ts b/lib/modules/manager/gradle/artifacts.spec.ts index fffb4314e4..b3b0426da2 100644 --- a/lib/modules/manager/gradle/artifacts.spec.ts +++ b/lib/modules/manager/gradle/artifacts.spec.ts @@ -36,12 +36,11 @@ const adminConfig: RepoGlobalConfig = { containerbaseDir: join('/tmp/cache/containerbase'), }; -jest.spyOn(os, 'platform').mockReturnValue('linux'); +const osPlatformSpy = jest.spyOn(os, 'platform'); describe('modules/manager/gradle/artifacts', () => { beforeEach(() => { - jest.resetAllMocks(); - + osPlatformSpy.mockReturnValue('linux'); env.getChildProcessEnv.mockReturnValue({ ...envMock.basic, LANG: 'en_US.UTF-8', diff --git a/lib/modules/manager/maven-wrapper/artifacts.spec.ts b/lib/modules/manager/maven-wrapper/artifacts.spec.ts index 672b141728..c90b68fc70 100644 --- a/lib/modules/manager/maven-wrapper/artifacts.spec.ts +++ b/lib/modules/manager/maven-wrapper/artifacts.spec.ts @@ -11,11 +11,13 @@ import { updateArtifacts } from '.'; jest.mock('../../../util/fs'); jest.mock('../../../util/git'); -jest.spyOn(os, 'platform').mockImplementation(() => 'darwin'); jest.mock('../../../util/exec/env'); jest.mock('../../datasource'); + process.env.CONTAINERBASE = 'true'; +const osPlatformSpy = jest.spyOn(os, 'platform'); + function mockMavenFileChangedInGit(fileName = 'maven-wrapper.properties') { git.getRepoStatus.mockResolvedValueOnce( partial<StatusResult>({ @@ -26,8 +28,8 @@ function mockMavenFileChangedInGit(fileName = 'maven-wrapper.properties') { describe('modules/manager/maven-wrapper/artifacts', () => { beforeEach(() => { + osPlatformSpy.mockImplementation(() => 'linux'); GlobalConfig.set({ localDir: join('/tmp/github/some/repo') }); - jest.resetAllMocks(); fs.statLocalFile.mockResolvedValue( partial<Stats>({ isFile: () => true, @@ -52,10 +54,6 @@ describe('modules/manager/maven-wrapper/artifacts', () => { }); }); - afterEach(() => { - GlobalConfig.reset(); - }); - it('Should not update if there is no dep with maven:wrapper', async () => { const execSnapshots = mockExecAll({ stdout: '', stderr: '' }); const updatedDeps = await updateArtifacts({ @@ -95,6 +93,7 @@ describe('modules/manager/maven-wrapper/artifacts', () => { expect(execSnapshots[2].cmd).toContain('java 8.0.1'); expect(updatedDeps).toEqual(expected); + expect(git.getRepoStatus).toHaveBeenCalledOnce(); }); it('Should update when it is maven wrapper', async () => { @@ -137,6 +136,7 @@ describe('modules/manager/maven-wrapper/artifacts', () => { }, }, ]); + expect(git.getRepoStatus).toHaveBeenCalledOnce(); }); it('Should not update deps when maven-wrapper.properties is not in git change', async () => { @@ -169,6 +169,7 @@ describe('modules/manager/maven-wrapper/artifacts', () => { }, }, ]); + expect(git.getRepoStatus).toHaveBeenCalledOnce(); }); it('updates with docker', async () => { @@ -225,11 +226,11 @@ describe('modules/manager/maven-wrapper/artifacts', () => { }, }, ]); + expect(git.getRepoStatus).toHaveBeenCalledOnce(); }); it('Should return null when cmd is not found', async () => { - mockMavenFileChangedInGit('also-not-maven-wrapper.properties'); - jest.spyOn(os, 'platform').mockImplementation(() => 'win32'); + osPlatformSpy.mockImplementation(() => 'win32'); const execSnapshots = mockExecAll({ stdout: '', stderr: '' }); fs.statLocalFile.mockResolvedValue(null); const updatedDeps = await updateArtifacts({ @@ -240,10 +241,10 @@ describe('modules/manager/maven-wrapper/artifacts', () => { }); expect(updatedDeps).toBeNull(); expect(execSnapshots).toMatchObject([]); + expect(git.getRepoStatus).not.toHaveBeenCalled(); }); it('Should throw an error when it cant execute', async () => { - mockMavenFileChangedInGit(); mockExecAll(new Error('temporary-error')); const updatedDeps = await updateArtifacts({ packageFileName: 'maven', @@ -260,6 +261,7 @@ describe('modules/manager/maven-wrapper/artifacts', () => { }, }, ]); + expect(git.getRepoStatus).not.toHaveBeenCalled(); }); it('updates with binarySource install', async () => { @@ -307,6 +309,7 @@ describe('modules/manager/maven-wrapper/artifacts', () => { }, }, ]); + expect(git.getRepoStatus).toHaveBeenCalledOnce(); }); it('should run wrapper:wrapper with MVNW_REPOURL if it is a custom artifactory', async () => { @@ -346,6 +349,7 @@ describe('modules/manager/maven-wrapper/artifacts', () => { }, }, ]); + expect(git.getRepoStatus).toHaveBeenCalledOnce(); }); it('should run not include MVNW_REPOURL when run with default maven repo url', async () => { @@ -385,6 +389,7 @@ describe('modules/manager/maven-wrapper/artifacts', () => { }, ]); expect(execSnapshots[0]!.options!.env).not.toHaveProperty('MVNW_REPOURL'); + expect(git.getRepoStatus).toHaveBeenCalledOnce(); }); it('should run not include MVNW_REPOURL when run with a malformed replaceString', async () => { @@ -424,5 +429,6 @@ describe('modules/manager/maven-wrapper/artifacts', () => { ]); expect(execSnapshots[0]!.options!.env).not.toHaveProperty('MVNW_REPOURL'); + expect(git.getRepoStatus).toHaveBeenCalledOnce(); }); }); -- GitLab