Skip to content

Commit

Permalink
ComparableVersion.nextMajorVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
BuZZ-T committed May 1, 2022
1 parent 4d48e11 commit 27b4440
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
30 changes: 30 additions & 0 deletions commons/ComparableVersion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,34 @@ describe('ComparableVersion', () => {
)).toEqual(new ComparableVersion(10, 1, 2, 3))
})
})

describe('nextMajorVersion', () => {
it('should go to the next major version', () => {
expect(ComparableVersion.nextMajorVersion(new ComparableVersion({
major: 10,
minor: 11,
branch: 12,
patch: 13,
}))).toEqual(new ComparableVersion({
major: 11,
minor: 0,
branch: 0,
patch: 0,
}))
})

it('should go to five major versions up', () => {
expect(ComparableVersion.nextMajorVersion(new ComparableVersion({
major: 10,
minor: 11,
branch: 12,
patch: 13,
}), 5)).toEqual(new ComparableVersion({
major: 15,
minor: 0,
branch: 0,
patch: 0,
}))
})
})
})
9 changes: 9 additions & 0 deletions commons/ComparableVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,13 @@ export class ComparableVersion implements IVersion {
public static max(...versions: ComparableVersion[]): ComparableVersion {
return versions.reduce((currentMax, version) => ComparableVersion.compare(currentMax, version) === Compared.LESS ? version : currentMax)
}

public static nextMajorVersion(version: ComparableVersion, plus = 1): ComparableVersion {
return new ComparableVersion({
major: version.major + plus,
minor: 0,
branch: 0,
patch: 0,
})
}
}
4 changes: 4 additions & 0 deletions download.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,14 @@ describe('download', () => {

beforeEach(() => {
loadVersionsMock.mockReset()
loadVersionsMock.mockResolvedValue(['10.0.0.0', '11.0.0.0', '12.0.0.0', '13.0.0.0', '14.0.0.0', '15.0.0.0'])

loadStoreMock.mockReset()
loadStoreMock.mockResolvedValue(new Store(createStore()))

mapVersionsMock.mockReset()
mapVersionsMock.mockReturnValue([new MappedVersion('10.0.0.0', true), new MappedVersion('11.0.0.0', true)])

getChromeDownloadUrlMock.mockReset()
fetchChromeZipFileMock.mockReset()

Expand Down
2 changes: 2 additions & 0 deletions download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ async function downloadForConfig(config: IChromeConfig): Promise<DownloadReportE

const mappedVersions = mapVersions(versions, config, store)

logger.debug(`total number of versions: ${versions.length}, filtered versions: ${mappedVersions.length}`)

const { chromeUrl, filenameOS, report, selectedVersion } = await getChromeDownloadUrl(config, mappedVersions)

if (chromeUrl && selectedVersion && config.download) {
Expand Down

0 comments on commit 27b4440

Please sign in to comment.