diff --git a/lib/util/exec/hermit.spec.ts b/lib/util/exec/hermit.spec.ts index f5b82c2c4ad8bf60ef8d1c6ef4a4aa83cac8df85..62761c2bc514c0eda7c8e2389d4f92aebcc99192 100644 --- a/lib/util/exec/hermit.spec.ts +++ b/lib/util/exec/hermit.spec.ts @@ -1,10 +1,15 @@ -import tmp, { DirectoryResult } from 'tmp-promise'; +import _findUp from 'find-up'; +import upath from 'upath'; import { mockExecAll } from '../../../test/exec-util'; +import { mockedFunction } from '../../../test/util'; import { GlobalConfig } from '../../config/global'; -import { writeLocalFile } from '../fs'; import { findHermitCwd, getHermitEnvs, isHermit } from './hermit'; import type { RawExecOptions } from './types'; +jest.mock('find-up'); +const findUp = mockedFunction(_findUp); +const localDir = '/tmp/renovate/repository/project-a'; + describe('util/exec/hermit', () => { describe('isHermit', () => { it('should return true when binarySource is hermit', () => { @@ -16,29 +21,21 @@ describe('util/exec/hermit', () => { }); describe('findHermitCwd', () => { - let localDirResult: DirectoryResult; - let localDir: string; - - beforeEach(async () => { - localDirResult = await tmp.dir({ unsafeCleanup: true }); - localDir = localDirResult.path; - + beforeEach(() => { GlobalConfig.set({ localDir }); }); - afterEach(async () => { - await localDirResult?.cleanup(); - }); - it('should find the closest hermit cwd to the given path', async () => { - await writeLocalFile('nested/bin/hermit', 'foo'); - await writeLocalFile('bin/hermit', 'bar'); - + findUp.mockResolvedValueOnce(upath.join(localDir, 'nested/bin/hermit')); const nestedCwd = 'nested/other/directory'; expect(await findHermitCwd(nestedCwd)).toBe(`${localDir}/nested/bin`); + findUp.mockResolvedValueOnce(upath.join(localDir, 'nested/bin/hermit')); expect(await findHermitCwd('nested')).toBe(`${localDir}/nested/bin`); + + findUp.mockResolvedValueOnce(upath.join(localDir, 'bin/hermit')); expect(await findHermitCwd('')).toBe(`${localDir}/bin`); + findUp.mockResolvedValueOnce(upath.join(localDir, 'bin/hermit')); expect(await findHermitCwd('other/directory')).toBe(`${localDir}/bin`); }); @@ -50,8 +47,12 @@ describe('util/exec/hermit', () => { }); describe('getHermitEnvs', () => { + beforeEach(() => { + GlobalConfig.set({ localDir }); + }); + it('should return hermit environment variables when hermit env returns successfully', async () => { - await writeLocalFile('bin/hermit', 'bar'); + findUp.mockResolvedValueOnce(upath.join(localDir, 'bin/hermit')); mockExecAll({ stdout: `GOBIN=/usr/src/app/repository-a/.hermit/go/bin PATH=/usr/src/app/repository-a/bin