forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser_path_spec.js
62 lines (54 loc) · 1.67 KB
/
browser_path_spec.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
const path = require('path')
const { exec } = require('child_process')
const systemTests = require('../lib/system-tests').default
const launcher = require('@packages/launcher')
const absPath = (pathStr) => {
return new Promise((resolve, reject) => {
if (path.basename(pathStr) !== pathStr) {
return resolve(pathStr)
}
return exec(`which ${pathStr}`, (err, stdout) => {
if (err) {
return reject(err)
}
return resolve(stdout.trim())
})
})
}
describe('e2e launching browsers by path', () => {
systemTests.setup()
it('fails with bad browser path', function () {
return systemTests.exec(this, {
project: 'e2e',
spec: 'simple.cy.js',
browser: '/this/aint/gonna/be/found',
expectedExitCode: 1,
})
.then((res) => {
expect(res.stdout).to.contain('We could not identify a known browser at the path you provided: `/this/aint/gonna/be/found`')
expect(res.code).to.eq(1)
})
})
it('works with an installed browser path', function () {
return launcher.detect().then((browsers) => {
return browsers.find((browser) => {
return browser.family === 'chromium'
})
}).tap((browser) => {
if (!browser) {
throw new Error('A \'chromium\' family browser must be installed for this test')
}
}).get('path')
// turn binary browser names ("google-chrome") into their absolute paths
// so that server recognizes them as a path, not as a browser name
.then((absPath))
.then((foundPath) => {
return systemTests.exec(this, {
project: 'e2e',
spec: 'simple.cy.js',
browser: foundPath,
snapshot: true,
})
})
})
})