mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-26 00:49:05 -06:00
fix: do not hard-code chrome for interactive e2e (#15837)
* fix: do not hard-code chrome for interactive e2e * chore: fix typo
This commit is contained in:
@@ -1,13 +1,32 @@
|
||||
const serverCt = require('@packages/server-ct')
|
||||
const { getBrowsers } = require('../browsers/utils')
|
||||
|
||||
const run = (options) => {
|
||||
const { projectRoot } = options
|
||||
const browsersForCtInteractive = ['chrome', 'chromium', 'edge', 'electron', 'firefox']
|
||||
|
||||
options.browser = options.browser || 'chrome'
|
||||
const returnDefaultBrowser = (browsersByPriority, installedBrowsers) => {
|
||||
const browserMap = installedBrowsers.reduce((acc, curr) => {
|
||||
acc[curr.name] = true
|
||||
|
||||
return serverCt.start(projectRoot, options)
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
for (const browser of browsersByPriority) {
|
||||
if (browserMap[browser]) {
|
||||
return browser
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const run = async (options) => {
|
||||
const installedBrowsers = await getBrowsers()
|
||||
|
||||
options.browser = options.browser || returnDefaultBrowser(browsersForCtInteractive, installedBrowsers)
|
||||
|
||||
return serverCt.start(options.projectRoot, options)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
run,
|
||||
returnDefaultBrowser,
|
||||
browsersForCtInteractive,
|
||||
}
|
||||
|
||||
35
packages/server/test/unit/modes/interactive-ct_spec.js
Normal file
35
packages/server/test/unit/modes/interactive-ct_spec.js
Normal file
@@ -0,0 +1,35 @@
|
||||
require('../../spec_helper')
|
||||
|
||||
const { browsers } = require('@packages/launcher/lib/browsers')
|
||||
const {
|
||||
returnDefaultBrowser,
|
||||
browsersForCtInteractive,
|
||||
} = require(`${root}../lib/modes/interactive-ct`)
|
||||
|
||||
function filterBrowsers (list) {
|
||||
return browsers.filter((browser) => list.includes(browser.name))
|
||||
}
|
||||
|
||||
describe('returnDefaultBrowser', () => {
|
||||
it('returns chrome by default is available', async () => {
|
||||
const installedBrowsers = filterBrowsers(['electron', 'chromium', 'chrome'])
|
||||
const actual = await returnDefaultBrowser(browsersForCtInteractive, installedBrowsers)
|
||||
|
||||
expect(actual).to.eq('chrome')
|
||||
})
|
||||
|
||||
it('returns chromium if chrome is not installed', async () => {
|
||||
const installedBrowsers = filterBrowsers(['electron', 'edge', 'chromium'])
|
||||
const actual = await returnDefaultBrowser(browsersForCtInteractive, installedBrowsers)
|
||||
|
||||
expect(actual).to.eq('chromium')
|
||||
})
|
||||
|
||||
it('returns undefined if no browser found', async () => {
|
||||
// error message is handlded further down.
|
||||
const installedBrowsers = filterBrowsers([])
|
||||
const actual = await returnDefaultBrowser(browsersForCtInteractive, installedBrowsers)
|
||||
|
||||
expect(actual).to.eq(undefined)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user