-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
53 lines (45 loc) · 1.42 KB
/
index.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
const EventEmitter = require('events');
const {webkit, chromium, firefox} = require('playwright');
class PwBrowser extends EventEmitter {
/**
* @param {import('playwright').BrowserType} browserType
*/
constructor(browserType) {
super();
this._browserType = browserType;
this.name = browserType.name();
this.id = Math.random();
}
/**
* @param {string} url
*/
async start(url) {
this._browser = await this._browserType.launch({headless: true});
this._browser.on('close', () => this.emit('done'));
const page = await this._browser.newPage();
await page.goto(`${url}?id=${this.id}`);
}
isCaptured() {
return true;
}
async forceKill() {
await this._browser.close();
}
}
// Karma actually parses the function.toString, so we can't pass in the class.
function ChromiumBrowserWrapper() {
return new PwBrowser(chromium);
}
// Karma actually parses the function.toString, so we can't pass in the class.
function FirefoxBrowserWrapper() {
return new PwBrowser(firefox);
}
// Karma actually parses the function.toString, so we can't pass in the class.
function WebKitBrowserWrapper() {
return new PwBrowser(webkit);
}
module.exports = {
'launcher:Chromium': ['type', ChromiumBrowserWrapper],
'launcher:Firefox': ['type', FirefoxBrowserWrapper],
'launcher:WebKit': ['type', WebKitBrowserWrapper],
}