diff --git a/download.spec.ts b/download.spec.ts index 3002cfa..c0e55db 100644 --- a/download.spec.ts +++ b/download.spec.ts @@ -154,6 +154,7 @@ describe('download', () => { }) it('should fetch the zip and create the dest folder', async () => { + mapVersionsMock.mockReturnValue([new MappedVersion(10, 0, 0, 1, false)]) getChromeDownloadUrlMock.mockResolvedValue(createGetChromeDownloadUrlReturn()) fetchChromeZipFileMock.mockResolvedValue(zipFileResource) @@ -181,6 +182,36 @@ describe('download', () => { expect(fetchChromeZipFileMock).toHaveBeenCalledTimes(1) expect(fetchChromeZipFileMock).toHaveBeenCalledWith('chromeUrl') + + expect(getChromeDownloadUrlMock).toHaveBeenCalledTimes(1) + expect(getChromeDownloadUrlMock).toHaveBeenCalledWith({ + arch: 'x64', + autoUnzip: false, + download: true, + downloadFolder: 'down_folder', + hideNegativeHits: false, + interactive: true, + inverse: false, + max: new ComparableVersion({ + major: 10000, + minor: 0, + branch: 0, + patch: 0, + }), + min: new ComparableVersion({ + branch: 0, + major: 0, + minor: 0, + patch: 0, + }), + onFail: 'nothing', + onlyNewestMajor: false, + os: 'linux', + quiet: false, + results: 10, + single: null, + store: true, + }, [new MappedVersion(10, 0, 0, 1, false)]) }) it('should fetch the zip and create the dest folder on finish', async () => { @@ -243,7 +274,8 @@ describe('download', () => { expect(fetchChromeZipFileMock).toHaveBeenCalledWith('chromeUrl') }) - it.only('should fetch the zip with defaults', async () => { + it('should fetch the zip with defaults', async () => { + mapVersionsMock.mockReturnValue([new MappedVersion(10, 0, 0, 2, false)]) getChromeDownloadUrlMock.mockResolvedValue(createGetChromeDownloadUrlReturn()) fetchChromeZipFileMock.mockResolvedValue(zipFileResource) @@ -259,10 +291,57 @@ describe('download', () => { expect(fetchChromeZipFileMock).toHaveBeenCalledTimes(1) expect(fetchChromeZipFileMock).toHaveBeenCalledWith('chromeUrl') + + expect(getChromeDownloadUrlMock).toHaveBeenCalledTimes(1) + expect(getChromeDownloadUrlMock).toHaveBeenCalledWith({ + arch: 'x64', + autoUnzip: false, + download: true, + downloadFolder: null, + hideNegativeHits: false, + interactive: true, + inverse: false, + max: new ComparableVersion({ + major: 10000, + minor: 0, + branch: 0, + patch: 0, + }), + min: new ComparableVersion({ + branch: 0, + major: 0, + minor: 0, + patch: 0, + }), + onFail: 'nothing', + onlyNewestMajor: false, + os: 'linux', + quiet: false, + results: 10, + single: null, + store: true, + }, [new MappedVersion(10, 0, 0, 2, false)]) + }) - it.skip('should', () => { - // + it('should fetch the zip with defaults for single', async () => { + getChromeDownloadUrlMock.mockResolvedValue(createGetChromeDownloadUrlReturn()) + + fetchChromeZipFileMock.mockResolvedValue(zipFileResource) + + // Act + await downloadChromium.withDefaults({ + single: new ComparableVersion(10, 0, 0, 0), + }) + + expect(progressConstructorMock).toHaveBeenCalledTimes(1) + expect(progressConstructorMock).toHaveBeenCalledWith(zipFileResource, { throttle: 100 }) + + expect(progressMock.start).toHaveBeenCalledTimes(0) + expect(progressMock.fraction).toHaveBeenCalledTimes(0) + + expect(fetchChromeZipFileMock).toHaveBeenCalledTimes(1) + expect(fetchChromeZipFileMock).toHaveBeenCalledWith('chromeUrl') }) it('should fetch and exract the zip', async () => { diff --git a/download.ts b/download.ts index 326c528..973afa9 100644 --- a/download.ts +++ b/download.ts @@ -44,11 +44,13 @@ function registerSigIntHandler(path: string): void { function enrichAdditionalConfig(additionalConfig: Partial = {}): IChromeConfig { if (isChromeSingleConfig(additionalConfig)) { + console.log('single config') return { ...DEFAULT_SINGLE_CONFIG, ...additionalConfig, } } else { + console.log('full config') return { ...DEFAULT_FULL_CONFIG, ...additionalConfig, diff --git a/utils/typeguards.spec.ts b/utils/typeguards.spec.ts index 348ccdb..cd42fd8 100644 --- a/utils/typeguards.spec.ts +++ b/utils/typeguards.spec.ts @@ -4,7 +4,8 @@ * @group unit/utils/typeguard */ -import { isTextFunction, isIVersion, isIVersionWithDisabled } from './typeguards' +import { ComparableVersion } from '../commons/ComparableVersion' +import { isTextFunction, isIVersion, isIVersionWithDisabled, isChromeSingleConfig } from './typeguards' describe('typeguards', () => { @@ -140,4 +141,25 @@ describe('typeguards', () => { })).toBe(false) }) }) + + describe('isChromeSingleConfig', () => { + it('should correctly identify an IChromeSingleConfig', () => { + expect(isChromeSingleConfig({ + single: new ComparableVersion(1,2,3,4), + })).toBe(true) + }) + + it('should return false on single === null', () => { + expect(isChromeSingleConfig({ + hideNegativeHits: true, + single: null, + })).toBe(false) + }) + + it('should return false on single === undefined', () => { + expect(isChromeSingleConfig({ + inverse: false, + })).toBe(false) + }) + }) }) diff --git a/utils/typeguards.ts b/utils/typeguards.ts index ed566fc..4fbc480 100644 --- a/utils/typeguards.ts +++ b/utils/typeguards.ts @@ -16,5 +16,5 @@ export function isIVersionWithDisabled(value: unknown): value is IVersionWithDis } export function isChromeSingleConfig(value: Partial): value is Partial { - return value.single !== null + return value.single !== null && value.single !== undefined }