-
Notifications
You must be signed in to change notification settings - Fork 220
/
puppeteerCompile.js
59 lines (46 loc) · 2.18 KB
/
puppeteerCompile.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
const puppeteer = require('puppeteer')
const path = require('path')
const fs = require('fs')
const { compress, decompress } = require('./utils')
module.exports = async function (reporter, definition) {
if (reporter.compilation) {
const chromeExecutablePath = puppeteer.executablePath()
const chromePath = path.dirname(chromeExecutablePath)
let chromeExecutableName = path.basename(chromeExecutablePath)
if (fs.existsSync(path.join(chromePath, 'interactive_ui_tests.exe'))) {
fs.unlinkSync(path.join(chromePath, 'interactive_ui_tests.exe'))
}
const pathToChromeZip = path.join(reporter.options.tempDirectory, 'chrome.zip')
let chromeDirectory
if (process.platform === 'darwin') {
chromeDirectory = path.join(path.dirname(chromeExecutablePath), '../../../')
// points to <Chrome app name>.app/Contents/MacOS/<Chrome exe name>
chromeExecutableName = path.relative(chromeDirectory, chromeExecutablePath)
} else {
chromeDirectory = path.dirname(chromeExecutablePath)
}
await compress(chromeDirectory, pathToChromeZip)
reporter.compilation.value('chromeExeName', chromeExecutableName)
reporter.compilation.resourceInTemp('chrome.zip', pathToChromeZip)
}
if (reporter.execution) {
const zipPath = reporter.execution.resourceTempPath('chrome.zip')
reporter.options.chrome = reporter.options.chrome || {}
reporter.options.chrome.launchOptions = reporter.options.chrome.launchOptions || {}
const chromeExeName = reporter.execution.value('chromeExeName')
reporter.options.chrome.launchOptions.executablePath = path.join(
path.dirname(zipPath),
'chrome',
chromeExeName
)
if (fs.existsSync(reporter.options.chrome.launchOptions.executablePath)) {
reporter.logger.debug('skip decompressing chrome in temp because it already exists')
return
}
reporter.initializeListeners.add('chrome exe', async () => {
reporter.logger.debug('chrome decompress started')
await decompress(zipPath, reporter.options.chrome.launchOptions.executablePath)
reporter.logger.debug('chrome decompress finished')
})
}
}