-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
server.js
55 lines (45 loc) · 1.46 KB
/
server.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
import startChrome from './browser/chromedriver';
import startNightmare from './browser/nightmare';
import startPhantom from './browser/phantomjs';
import startPlaywright from './browser/playwright';
import startPuppeteer from './browser/puppeteer';
const supportedDrivers = ['chrome', 'nightmare', 'phantomjs', 'playwright', 'puppeteer'];
const driver = process.env.TEST_BROWSER_DRIVER;
function startBrowser(options) {
const driverOptions = {
...options,
stdout(message) {
// Don't just throw away the stdout messages. They're data from a writable buffer.
if (typeof message === 'string' && message.startsWith('stdout: ')) {
if (typeof options.writebuffer === 'function') {
options.writebuffer(message.substr(8));
}
} else {
options.stdout(message);
}
},
};
switch (driver) {
case 'chrome':
startChrome(driverOptions);
break;
case 'phantomjs':
startPhantom(driverOptions);
break;
case 'nightmare':
startNightmare(driverOptions);
break;
case 'puppeteer':
startPuppeteer(driverOptions);
break;
case 'playwright':
startPlaywright(driverOptions);
break;
default:
throw new Error(
`Unknown driver "${driver}". browser-tests package requires that you set the TEST_BROWSER_DRIVER`
+ ` environment variable to one of the following: ${supportedDrivers.join(', ')}`
);
}
}
export { startBrowser };