mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
Add jest config and test environment to launch app
This commit is contained in:
7
jest.config.js
Normal file
7
jest.config.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
module.exports = {
|
||||||
|
globals: {
|
||||||
|
__APP__: undefined, // A different app will be launched in each test environment
|
||||||
|
},
|
||||||
|
testEnvironment: "./tests/environment",
|
||||||
|
testTimeout: 30000, // 30s
|
||||||
|
};
|
||||||
45
tests/environment.js
Normal file
45
tests/environment.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
const getPort = require("get-port");
|
||||||
|
const NodeEnvironment = require("jest-environment-node");
|
||||||
|
const { Application } = require("spectron");
|
||||||
|
|
||||||
|
class TestEnvironment extends NodeEnvironment {
|
||||||
|
constructor(config) {
|
||||||
|
super(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
async setup() {
|
||||||
|
await super.setup();
|
||||||
|
|
||||||
|
const electronPath = path.resolve(
|
||||||
|
__dirname,
|
||||||
|
"..",
|
||||||
|
"node_modules",
|
||||||
|
".bin",
|
||||||
|
"electron"
|
||||||
|
);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
async teardown() {
|
||||||
|
await this.global.__APP__.stop();
|
||||||
|
await super.teardown();
|
||||||
|
}
|
||||||
|
|
||||||
|
runScript(script) {
|
||||||
|
return super.runScript(script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = TestEnvironment;
|
||||||
Reference in New Issue
Block a user