mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-09 17:51:46 +00:00
Switch from spectron to playwright to fix tests
This commit is contained in:
@ -97,10 +97,9 @@
|
||||
"electron-builder": "^22.10.5",
|
||||
"electron-devtools-installer": "^3.1.1",
|
||||
"electron-icon-maker": "0.0.5",
|
||||
"get-port": "^5.1.1",
|
||||
"jest": "^27.3.1",
|
||||
"playwright": "^1.17.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"spectron": "^14.0.0",
|
||||
"xo": "^0.45.0"
|
||||
},
|
||||
"resolutions": {
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
const path = require("path");
|
||||
|
||||
const getPort = require("get-port");
|
||||
const NodeEnvironment = require("jest-environment-node");
|
||||
const electronPath = require("electron");
|
||||
const { Application } = require("spectron");
|
||||
const { _electron: electron } = require("playwright");
|
||||
|
||||
class TestEnvironment extends NodeEnvironment {
|
||||
constructor(config) {
|
||||
@ -14,21 +12,12 @@ class TestEnvironment extends NodeEnvironment {
|
||||
await super.setup();
|
||||
|
||||
const appPath = path.resolve(__dirname, "..");
|
||||
const port = await getPort();
|
||||
|
||||
this.global.__APP__ = new Application({
|
||||
path: electronPath,
|
||||
args: [appPath],
|
||||
port,
|
||||
});
|
||||
await this.global.__APP__.start();
|
||||
const { client } = this.global.__APP__;
|
||||
await client.waitUntilWindowLoaded();
|
||||
this.global.__APP__ = await electron.launch({ args: [appPath] });
|
||||
}
|
||||
|
||||
async teardown() {
|
||||
if (this.global.__APP__.isRunning()) {
|
||||
await this.global.__APP__.stop();
|
||||
if (this.global.__APP__) {
|
||||
await this.global.__APP__.close();
|
||||
}
|
||||
await super.teardown();
|
||||
}
|
||||
|
||||
@ -6,22 +6,11 @@ describe("YouTube Music App", () => {
|
||||
const app = global.__APP__;
|
||||
|
||||
test("With default settings, app is launched and visible", async () => {
|
||||
expect(app.isRunning()).toBe(true);
|
||||
|
||||
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();
|
||||
const window = await app.firstWindow();
|
||||
const title = await window.title();
|
||||
expect(title).toEqual("YouTube Music");
|
||||
|
||||
const url = window.url();
|
||||
expect(url.startsWith("https://music.youtube.com")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user