Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
BuZZ-T committed Apr 10, 2022
1 parent a35f6dc commit dbdee61
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 5 deletions.
85 changes: 82 additions & 3 deletions download.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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)
Expand All @@ -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 () => {
Expand Down
2 changes: 2 additions & 0 deletions download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ function registerSigIntHandler(path: string): void {

function enrichAdditionalConfig(additionalConfig: Partial<IChromeConfig> = {}): IChromeConfig {
if (isChromeSingleConfig(additionalConfig)) {
console.log('single config')
return {
...DEFAULT_SINGLE_CONFIG,
...additionalConfig,
}
} else {
console.log('full config')
return {
...DEFAULT_FULL_CONFIG,
...additionalConfig,
Expand Down
24 changes: 23 additions & 1 deletion utils/typeguards.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {

Expand Down Expand Up @@ -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)
})
})
})
2 changes: 1 addition & 1 deletion utils/typeguards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export function isIVersionWithDisabled(value: unknown): value is IVersionWithDis
}

export function isChromeSingleConfig(value: Partial<IChromeConfig>): value is Partial<IChromeSingleConfig> {
return value.single !== null
return value.single !== null && value.single !== undefined
}

0 comments on commit dbdee61

Please sign in to comment.