mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-27 02:14:36 -05:00
fix: better handle unconventional browser version (#16990)
This commit is contained in:
Vendored
+1
-1
@@ -60,7 +60,7 @@ declare namespace Cypress {
|
||||
*/
|
||||
displayName: string
|
||||
version: string
|
||||
majorVersion: number
|
||||
majorVersion: number | string
|
||||
path: string
|
||||
isHeaded: boolean
|
||||
isHeadless: boolean
|
||||
|
||||
@@ -26,17 +26,13 @@ export const setMajorVersion = <T extends HasVersion>(browser: T): T => {
|
||||
let majorVersion = browser.majorVersion
|
||||
|
||||
if (browser.version) {
|
||||
majorVersion = browser.version.split('.')[0]
|
||||
majorVersion = parseInt(browser.version.split('.')[0]) || browser.version
|
||||
log(
|
||||
'browser %s version %s major version %s',
|
||||
browser.name,
|
||||
browser.version,
|
||||
majorVersion,
|
||||
)
|
||||
|
||||
if (majorVersion) {
|
||||
majorVersion = parseInt(majorVersion)
|
||||
}
|
||||
}
|
||||
|
||||
return extend({}, browser, { majorVersion })
|
||||
|
||||
@@ -39,15 +39,29 @@ describe('browser detection', () => {
|
||||
})
|
||||
|
||||
context('#setMajorVersion', () => {
|
||||
const foundBrowser = {
|
||||
name: 'test browser',
|
||||
version: '11.22.33',
|
||||
}
|
||||
it('major version is converted to number when string of numbers', () => {
|
||||
const foundBrowser = {
|
||||
name: 'test browser',
|
||||
version: '11.22.33',
|
||||
}
|
||||
|
||||
const res = setMajorVersion(foundBrowser)
|
||||
const res = setMajorVersion(foundBrowser)
|
||||
|
||||
// @ts-ignore
|
||||
expect(res.majorVersion, 'major version was converted to number').to.equal(11)
|
||||
// @ts-ignore
|
||||
expect(res.majorVersion).to.equal(11)
|
||||
})
|
||||
|
||||
it('falls back to version when unconventional browser version', () => {
|
||||
const foundBrowser = {
|
||||
name: 'test browser',
|
||||
version: 'VMware Fusion 12.1.0',
|
||||
}
|
||||
|
||||
const res = setMajorVersion(foundBrowser)
|
||||
|
||||
// @ts-ignore
|
||||
expect(res.majorVersion).to.equal(foundBrowser.version)
|
||||
})
|
||||
})
|
||||
|
||||
context('#detectByPath', () => {
|
||||
|
||||
@@ -38,6 +38,10 @@ const getBrowserPath = (browser) => {
|
||||
)
|
||||
}
|
||||
|
||||
const getMajorVersion = (version) => {
|
||||
return parseFloat(version.split('.')[0]) || version
|
||||
}
|
||||
|
||||
const defaultLaunchOptions: {
|
||||
preferences: {[key: string]: any}
|
||||
extensions: string[]
|
||||
@@ -193,6 +197,8 @@ export = {
|
||||
|
||||
getBrowserPath,
|
||||
|
||||
getMajorVersion,
|
||||
|
||||
getProfileDir,
|
||||
|
||||
getExtensionDir,
|
||||
@@ -244,7 +250,7 @@ export = {
|
||||
const version = process.versions.chrome || ''
|
||||
|
||||
if (version) {
|
||||
majorVersion = parseFloat(version.split('.')[0])
|
||||
majorVersion = getMajorVersion(version)
|
||||
}
|
||||
|
||||
const electronBrowser: FoundBrowser = {
|
||||
|
||||
@@ -128,6 +128,24 @@ describe('lib/browsers/index', () => {
|
||||
expect(onWarning).to.be.calledWithMatch({ type: 'DEPRECATED_BEFORE_BROWSER_LAUNCH_ARGS' })
|
||||
})
|
||||
})
|
||||
|
||||
context('.getMajorVersion', () => {
|
||||
it('returns first number when string of numbers', () => {
|
||||
expect(utils.getMajorVersion('91.0.4472.106')).to.eq(91) // Chromium format
|
||||
expect(utils.getMajorVersion('91.0a1')).to.eq(91) // Firefox format
|
||||
})
|
||||
|
||||
it('is empty string when empty string', () => {
|
||||
expect(utils.getMajorVersion('')).to.eq('') // fallback if no version
|
||||
})
|
||||
|
||||
// https://github.com/cypress-io/cypress/issues/15485
|
||||
it('returns version when unconventional version format', () => {
|
||||
const vers = 'VMware Fusion 12.1.0'
|
||||
|
||||
expect(utils.getMajorVersion(vers)).to.eq(vers)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
// Ooo, browser clean up tests are disabled?!!
|
||||
|
||||
Reference in New Issue
Block a user