mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 20:01:47 +00:00
@ -9,6 +9,8 @@ jobs:
|
|||||||
osx_image: xcode11.3
|
osx_image: xcode11.3
|
||||||
- os: linux
|
- os: linux
|
||||||
dist: xenial
|
dist: xenial
|
||||||
|
services:
|
||||||
|
- xvfb
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
yarn: false
|
yarn: false
|
||||||
@ -18,6 +20,7 @@ cache:
|
|||||||
|
|
||||||
script:
|
script:
|
||||||
- |
|
- |
|
||||||
|
yarn test
|
||||||
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
|
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
|
||||||
yarn run release:linux
|
yarn run release:linux
|
||||||
else
|
else
|
||||||
|
|||||||
@ -21,6 +21,11 @@ install:
|
|||||||
# # https://www.appveyor.com/docs/how-to/rdp-to-build-worker/
|
# # https://www.appveyor.com/docs/how-to/rdp-to-build-worker/
|
||||||
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
|
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
|
||||||
|
|
||||||
|
# @FIXME: tests disabled because app fails to launch on AppVeyor/Windows
|
||||||
|
# os: unstable # https://github.com/electron-userland/spectron#on-appveyor
|
||||||
|
# test_script:
|
||||||
|
# - yarn test
|
||||||
|
|
||||||
build_script:
|
build_script:
|
||||||
- yarn run release:win
|
- yarn run release:win
|
||||||
|
|
||||||
|
|||||||
3
index.js
3
index.js
@ -14,6 +14,7 @@ const {
|
|||||||
store,
|
store,
|
||||||
} = require("./store");
|
} = require("./store");
|
||||||
const { fileExists, injectCSS } = require("./plugins/utils");
|
const { fileExists, injectCSS } = require("./plugins/utils");
|
||||||
|
const { isTesting } = require("./utils/testing");
|
||||||
const { setUpTray } = require("./tray");
|
const { setUpTray } = require("./tray");
|
||||||
|
|
||||||
const app = electron.app;
|
const app = electron.app;
|
||||||
@ -49,7 +50,7 @@ function createMainWindow() {
|
|||||||
backgroundColor: "#000",
|
backgroundColor: "#000",
|
||||||
show: false,
|
show: false,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: false,
|
nodeIntegration: isTesting(), // Only necessary when testing with Spectron
|
||||||
preload: path.join(__dirname, "preload.js"),
|
preload: path.join(__dirname, "preload.js"),
|
||||||
nativeWindowOpen: true, // window.open return Window object(like in regular browsers), not BrowserWindowProxy
|
nativeWindowOpen: true, // window.open return Window object(like in regular browsers), not BrowserWindowProxy
|
||||||
affinity: "main-window", // main window, and addition windows should work in one process
|
affinity: "main-window", // main window, and addition windows should work in one process
|
||||||
|
|||||||
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
|
||||||
|
};
|
||||||
@ -26,7 +26,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "xo",
|
"test": "jest",
|
||||||
"start": "electron .",
|
"start": "electron .",
|
||||||
"icon": "rimraf assets/generated && electron-icon-maker --input=assets/youtube-music.png --output=assets/generated",
|
"icon": "rimraf assets/generated && electron-icon-maker --input=assets/youtube-music.png --output=assets/generated",
|
||||||
"generate:package": "node utils/generate-package-json.js",
|
"generate:package": "node utils/generate-package-json.js",
|
||||||
@ -61,7 +61,10 @@
|
|||||||
"electron-builder": "^22.4.1",
|
"electron-builder": "^22.4.1",
|
||||||
"electron-devtools-installer": "^3.0.0",
|
"electron-devtools-installer": "^3.0.0",
|
||||||
"electron-icon-maker": "0.0.4",
|
"electron-icon-maker": "0.0.4",
|
||||||
|
"get-port": "^5.1.1",
|
||||||
|
"jest": "^25.5.1",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
|
"spectron": "^10.0.1",
|
||||||
"xo": "^0.29.0"
|
"xo": "^0.29.0"
|
||||||
},
|
},
|
||||||
"xo": {
|
"xo": {
|
||||||
|
|||||||
@ -98,6 +98,14 @@ yarn run build
|
|||||||
|
|
||||||
Builds the app for macOS, Linux, and Windows, using [electron-builder](https://github.com/electron-userland/electron-builder).
|
Builds the app for macOS, Linux, and Windows, using [electron-builder](https://github.com/electron-userland/electron-builder).
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
|
||||||
|
```sh
|
||||||
|
yarn test
|
||||||
|
```
|
||||||
|
|
||||||
|
Uses [Spectron](https://www.electronjs.org/spectron) to test the app.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT © [th-ch](https://github.com/th-ch/youtube-music)
|
MIT © [th-ch](https://github.com/th-ch/youtube-music)
|
||||||
|
|||||||
47
tests/environment.js
Normal file
47
tests/environment.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
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() {
|
||||||
|
if (this.global.__APP__.isRunning()) {
|
||||||
|
await this.global.__APP__.stop();
|
||||||
|
}
|
||||||
|
await super.teardown();
|
||||||
|
}
|
||||||
|
|
||||||
|
runScript(script) {
|
||||||
|
return super.runScript(script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = TestEnvironment;
|
||||||
20
tests/index.test.js
Normal file
20
tests/index.test.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
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 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");
|
||||||
|
});
|
||||||
|
});
|
||||||
3
utils/testing.js
Normal file
3
utils/testing.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
const isTesting = () => process.env.NODE_ENV === "test";
|
||||||
|
|
||||||
|
module.exports = { isTesting };
|
||||||
Reference in New Issue
Block a user