forked from cypress-io/cypress-example-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrave.js
84 lines (70 loc) · 2.11 KB
/
brave.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* eslint-disable no-console */
const { defineConfig } = require('cypress')
const os = require('os')
const execa = require('execa')
const tasks = require('./tasks')
/**
* Parses STDOUT from "brave-browser --version" command.
* @param {string} stdout from Brave, something like "Brave Browser 77.0.69.135"
*/
const parseBraveVersion = (stdout) => {
const [, version] = /Brave Browser (\d+\.\d+\.\d+\.\d+)/.exec(stdout)
console.log('Brave browser version is', version)
const majorVersion = parseFloat(version.split('.')[0])
return { version, majorVersion }
}
const findBraveBrowserInfo = (browserPath) => {
return execa(browserPath, ['--version'])
.then((result) => result.stdout)
.then(parseBraveVersion)
.then(({ version, majorVersion }) => {
return {
name: 'brave',
channel: 'stable',
family: 'chromium',
displayName: 'Brave',
version,
path: browserPath,
majorVersion,
}
})
}
const findBraveBrowser = () => {
// the path is hard-coded for simplicity
switch (os.platform()) {
case 'darwin':
return findBraveBrowserInfo(
'/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'
)
case 'linux':
return findBraveBrowserInfo('brave-browser')
default:
throw new Error(`Cannot find Brave browser on platform ${os.platform()}`)
}
}
module.exports = defineConfig({
e2e: {
setupNodeEvents (on, config) {
on('task', tasks)
// only filter browsers if we are passed a list - this way
// this example works on Cypress v3.7.0+ and below
if (!config.browsers) {
return
}
// kind of hack - we don"t know the Cypress version running
// so we need to look at known Electron browser
const electron = config.browsers.find((browser) => browser.name === 'electron')
if (!electron) {
console.error('Could not find even Electron browser ⚠️')
return
}
// Cypress v3.7.0+
return findBraveBrowser().then((browser) => {
browser.family = electron.family
return {
browsers: [browser],
}
})
},
},
})