2021-01-13 03:25:02 -09:00
|
|
|
// Native
|
|
|
|
|
import path from 'path';
|
2016-09-21 22:08:56 -08:00
|
|
|
|
2021-01-13 03:25:02 -09:00
|
|
|
// Packages
|
|
|
|
|
import test from 'ava';
|
2023-07-25 09:30:19 -08:00
|
|
|
import fs from 'fs-extra';
|
2023-06-26 01:29:50 -08:00
|
|
|
import {_electron} from 'playwright';
|
2023-07-25 09:30:19 -08:00
|
|
|
import type {ElectronApplication} from 'playwright';
|
2016-09-21 22:08:56 -08:00
|
|
|
|
2021-09-08 23:48:45 -08:00
|
|
|
let app: ElectronApplication;
|
2016-09-21 22:08:56 -08:00
|
|
|
|
2021-01-13 03:25:02 -09:00
|
|
|
test.before(async () => {
|
|
|
|
|
let pathToBinary;
|
2016-09-30 07:47:07 -08:00
|
|
|
|
2021-01-13 03:25:02 -09:00
|
|
|
switch (process.platform) {
|
|
|
|
|
case 'linux':
|
|
|
|
|
pathToBinary = path.join(__dirname, '../dist/linux-unpacked/hyper');
|
|
|
|
|
break;
|
2016-09-30 07:47:07 -08:00
|
|
|
|
2021-01-13 03:25:02 -09:00
|
|
|
case 'darwin':
|
|
|
|
|
pathToBinary = path.join(__dirname, '../dist/mac/Hyper.app/Contents/MacOS/Hyper');
|
|
|
|
|
break;
|
2016-09-30 07:47:07 -08:00
|
|
|
|
2021-01-13 03:25:02 -09:00
|
|
|
case 'win32':
|
|
|
|
|
pathToBinary = path.join(__dirname, '../dist/win-unpacked/Hyper.exe');
|
|
|
|
|
break;
|
2016-11-11 08:18:04 -09:00
|
|
|
|
2021-01-13 03:25:02 -09:00
|
|
|
default:
|
|
|
|
|
throw new Error('Path to the built binary needs to be defined for this platform in test/index.js');
|
|
|
|
|
}
|
2016-09-30 07:47:07 -08:00
|
|
|
|
2021-09-08 23:48:45 -08:00
|
|
|
app = await _electron.launch({
|
|
|
|
|
executablePath: pathToBinary
|
2021-01-13 03:25:02 -09:00
|
|
|
});
|
2021-09-08 23:48:45 -08:00
|
|
|
await app.firstWindow();
|
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
2021-01-13 03:25:02 -09:00
|
|
|
});
|
2016-09-21 22:08:56 -08:00
|
|
|
|
2021-01-13 03:25:02 -09:00
|
|
|
test.after(async () => {
|
2021-09-08 23:48:45 -08:00
|
|
|
await app
|
2024-03-20 04:50:13 -08:00
|
|
|
.evaluate(({BrowserWindow}) =>
|
|
|
|
|
BrowserWindow.getFocusedWindow()
|
|
|
|
|
?.capturePage()
|
|
|
|
|
.then((img) => img.toPNG().toString('base64'))
|
2021-11-22 21:21:35 -09:00
|
|
|
)
|
2021-09-08 23:48:45 -08:00
|
|
|
.then((img) => Buffer.from(img || '', 'base64'))
|
|
|
|
|
.then(async (imageBuffer) => {
|
|
|
|
|
await fs.writeFile(`dist/tmp/${process.platform}_test.png`, imageBuffer);
|
|
|
|
|
});
|
|
|
|
|
await app.close();
|
2021-01-13 03:25:02 -09:00
|
|
|
});
|
2016-09-21 22:08:56 -08:00
|
|
|
|
2021-01-13 03:25:02 -09:00
|
|
|
test('see if dev tools are open', async (t) => {
|
2024-11-22 23:07:22 -09:00
|
|
|
const result = app.evaluate(({webContents}) => {
|
|
|
|
|
const focused = webContents.getFocusedWebContents();
|
|
|
|
|
const isDevOpen = focused?.isDevToolsOpened();
|
|
|
|
|
return Boolean(isDevOpen);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
t.false(await result);
|
2021-01-13 03:25:02 -09:00
|
|
|
});
|