-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathbrowsers.ts
54 lines (42 loc) · 1.48 KB
/
browsers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import Debug from 'debug'
import type * as cp from 'child_process'
import { utils } from './utils'
import type { FoundBrowser } from '@packages/types'
import type { Readable } from 'stream'
export const debug = Debug('cypress:launcher:browsers')
/** starts a found browser and opens URL if given one */
export type LaunchedBrowser = cp.ChildProcessByStdio<null, Readable, Readable>
// NOTE: For Firefox, geckodriver is used to launch the browser
export function launch (
browser: FoundBrowser,
url: string,
debuggingPort: number,
args: string[] = [],
browserEnv = {},
) {
debug('launching browser %o', { browser, url })
if (!browser.path) {
throw new Error(`Browser ${browser.name} is missing path`)
}
if (url) {
args = [url].concat(args)
}
const spawnOpts: cp.SpawnOptionsWithStdioTuple<cp.StdioNull, cp.StdioPipe, cp.StdioPipe> = {
stdio: ['ignore', 'pipe', 'pipe'],
// allow setting default env vars
// but only if it's not already set by the environment
env: { ...browserEnv, ...process.env },
}
debug('spawning browser with opts %o', { browser, url, spawnOpts })
const proc = utils.spawnWithArch(browser.path, args, spawnOpts)
proc.stdout.on('data', (buf) => {
debug('%s stdout: %s', browser.name, String(buf).trim())
})
proc.stderr.on('data', (buf) => {
debug('%s stderr: %s', browser.name, String(buf).trim())
})
proc.on('exit', (code, signal) => {
debug('%s exited: %o', browser.name, { code, signal })
})
return proc
}