|
2 | 2 | // See LICENSE.txt for license information. |
3 | 3 |
|
4 | 4 | import * as fs from 'fs'; |
| 5 | +import {createRequire} from 'module'; |
5 | 6 | import * as path from 'path'; |
6 | 7 |
|
| 8 | +const require = createRequire(__filename); |
| 9 | + |
7 | 10 | export const sourceRootDir = path.join(__dirname, '../..'); |
8 | 11 |
|
9 | | -// The Electron binary from the npm package |
10 | | -export const electronBinaryPath = (() => { |
| 12 | +function getElectronBinaryPath(): string { |
11 | 13 | if (process.platform === 'darwin') { |
12 | 14 | return path.join(sourceRootDir, 'node_modules/electron/dist/Electron.app/Contents/MacOS/Electron'); |
13 | 15 | } |
14 | 16 | const ext = process.platform === 'win32' ? '.exe' : ''; |
15 | 17 | return path.join(sourceRootDir, `node_modules/electron/dist/electron${ext}`); |
| 18 | +} |
| 19 | + |
| 20 | +// Electron 42+ no longer downloads its binary during npm install. Playwright |
| 21 | +// launches via executablePath, so trigger the lazy download before tests run. |
| 22 | +export function ensureElectronBinary(): void { |
| 23 | + const binaryPath = getElectronBinaryPath(); |
| 24 | + if (!fs.existsSync(binaryPath)) { |
| 25 | + require(path.join(sourceRootDir, 'node_modules/electron')); |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +// The Electron binary from the npm package |
| 30 | +export const electronBinaryPath = (() => { |
| 31 | + ensureElectronBinary(); |
| 32 | + return getElectronBinaryPath(); |
16 | 33 | })(); |
17 | 34 |
|
18 | 35 | // Test build app directory — built by `npm run build-test` (NODE_ENV=test) |
|
0 commit comments