Switch from spectron to playwright to fix tests

This commit is contained in:
TC
2021-12-30 19:26:01 +01:00
parent 8d66735585
commit 9d6765125b
4 changed files with 120 additions and 712 deletions

View File

@ -97,10 +97,9 @@
"electron-builder": "^22.10.5", "electron-builder": "^22.10.5",
"electron-devtools-installer": "^3.1.1", "electron-devtools-installer": "^3.1.1",
"electron-icon-maker": "0.0.5", "electron-icon-maker": "0.0.5",
"get-port": "^5.1.1",
"jest": "^27.3.1", "jest": "^27.3.1",
"playwright": "^1.17.1",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"spectron": "^14.0.0",
"xo": "^0.45.0" "xo": "^0.45.0"
}, },
"resolutions": { "resolutions": {

View File

@ -1,9 +1,7 @@
const path = require("path"); const path = require("path");
const getPort = require("get-port");
const NodeEnvironment = require("jest-environment-node"); const NodeEnvironment = require("jest-environment-node");
const electronPath = require("electron"); const { _electron: electron } = require("playwright");
const { Application } = require("spectron");
class TestEnvironment extends NodeEnvironment { class TestEnvironment extends NodeEnvironment {
constructor(config) { constructor(config) {
@ -14,21 +12,12 @@ class TestEnvironment extends NodeEnvironment {
await super.setup(); await super.setup();
const appPath = path.resolve(__dirname, ".."); const appPath = path.resolve(__dirname, "..");
const port = await getPort(); this.global.__APP__ = await electron.launch({ args: [appPath] });
this.global.__APP__ = new Application({
path: electronPath,
args: [appPath],
port,
});
await this.global.__APP__.start();
const { client } = this.global.__APP__;
await client.waitUntilWindowLoaded();
} }
async teardown() { async teardown() {
if (this.global.__APP__.isRunning()) { if (this.global.__APP__) {
await this.global.__APP__.stop(); await this.global.__APP__.close();
} }
await super.teardown(); await super.teardown();
} }

View File

@ -6,22 +6,11 @@ describe("YouTube Music App", () => {
const app = global.__APP__; const app = global.__APP__;
test("With default settings, app is launched and visible", async () => { test("With default settings, app is launched and visible", async () => {
expect(app.isRunning()).toBe(true); const window = await app.firstWindow();
const title = await window.title();
const win = app.browserWindow;
const isMenuVisible = await win.isMenuBarVisible();
expect(isMenuVisible).toBe(true);
const isVisible = await win.isVisible();
expect(isVisible).toBe(true);
const { width, height } = await win.getBounds();
expect(width).toBeGreaterThan(0);
expect(height).toBeGreaterThan(0);
const { client } = app;
const title = await client.getTitle();
expect(title).toEqual("YouTube Music"); expect(title).toEqual("YouTube Music");
const url = window.url();
expect(url.startsWith("https://music.youtube.com")).toBe(true);
}); });
}); });

789
yarn.lock

File diff suppressed because it is too large Load Diff