hyper/test/index.ts

57 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-01-13 03:25:02 -09:00
// Native
import path from 'path';
import fs from 'fs-extra';
2016-09-21 22:08:56 -08:00
2021-01-13 03:25:02 -09:00
// Packages
import test from 'ava';
2023-06-26 01:29:50 -08:00
import type {ElectronApplication} from 'playwright';
import {_electron} from 'playwright';
2016-09-21 22:08:56 -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;
Add Windows support and first-class Linux support (#946) * `child_pty` => `pty.js` * Create a frameless window on Windows and Linux * Add a brand new UI for Linux and Windows :nail_care: * [Windows] Fix plugin installation * [Windows] Fix the `build` script * [Windows] Add a bigger `icon.ico` * [Mac] Add `WebKitAppRegion: drag` when running on macOS * Fix code style :thinking: * Add `appveyor.yml` * Fix code style (again) * [Windows] Fix AppVeyor's `install` script * [Windows] Try a new AppVeyor config * [Windows] Set the binary path so Spectron can run the tests * [Windows] Try to build on x64 * Try again to build on x64 * Try one more time :weary: * Throw an error to indicate that `pty.js` was built incorrectly * [Win/Linux] Add `display: hidden` to <Tabs /> if tabs.length === 1 * [Win/Linux] Reorganize SVGs – via @CodeTheory * [Win/Linux] Fix the hamburger menu height * Make the SVGs look better with `shape-rendering: crispEdges;` * [Win/Linux] Add config options for the window controls and the :hamburger: menu * Add `electron-squirrel-startup` dependency * [Win] Handle Squirrel commands * [Win/Linux] Fix default color for the :hamburger: and window controls – via @CodeTheory * [Win/Linux] Add some padding - via @CodeTheory * [Win/Linux] Add hover states – via @CodeTheory * [Win] Fix empty window/tab titles * [Win] Fix opening Preferences (#978) * [Win] Fix opening Preferences * Update ui.js * Update ui.js * Enhance messages and default editor * [Win] Add dependency instructions to the README.md [skip ci] * Fix code style * [Win/Linux] Check the number of open windows before quitting the app
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
app = await _electron.launch({
executablePath: pathToBinary
2021-01-13 03:25:02 -09: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 () => {
await app
2023-07-10 05:56:33 -08:00
.evaluate(
({BrowserWindow}) =>
BrowserWindow.getFocusedWindow()
?.capturePage()
.then((img) => img.toPNG().toString('base64'))
)
.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) => {
2023-05-16 21:56:28 -08:00
t.false(await app.evaluate(({webContents}) => !!webContents.getFocusedWebContents()?.isDevToolsOpened()));
2021-01-13 03:25:02 -09:00
});