Skip to content

Commit

Permalink
test: add playwright for e2e tests (#828)
Browse files Browse the repository at this point in the history
* test: add playwright for e2e tests

fix :#688

* test: add gallery search/module addition

* test: fix gallery item locator

* test: add waitUntilModVReady function

* test: refactor waitUntilModVReady to reduce promise creation

* test: refactor waitUntilModVReady to remove useless else

* test: refactor waitUntilModVReady to remove useless if

* test: tidy up

* test: add preset generation test

* test: add evaluateWorkerState

* test: add new group test

* test: fix typo

* test: add test:e2e script to package.json

* test: split group tests into their own file

* test: add group enabled toggle test

* test: improve backspace removes focused group

* test: add group clearing and pipeline tests

* test: add inheritance test

* test: add alpha state test

* test: add blend mode test

* refactor: remove console.log

* test: add group name test

* test: consolidate name locators

* test: add group rearrangement test

* test: tidy up

* test: fix scope

* test: add input link test

* test: split up test files to avoid worker overlap

* test: remove unneeded reload and wait

* test: remove useless code

* test: remove unused deps

* fix: update title to name and fix keyboard event

* test: significantly speed up tests on slower machines

* test: remove page.waitForTimeout
  • Loading branch information
2xAA authored Jun 11, 2023
1 parent e5f7c7b commit 2cad1e0
Show file tree
Hide file tree
Showing 39 changed files with 1,044 additions and 38 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps && patch-package",
"postuninstall": "electron-builder install-app-deps"
"postuninstall": "electron-builder install-app-deps",
"test:e2e": "npx playwright test"
},
"main": "background.js",
"dependencies": {
Expand Down Expand Up @@ -70,6 +71,7 @@
"@babel/core": "^7.0.0-0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
"@playwright/test": "^1.31.2",
"@semantic-release/git": "^9.0.0",
"@vue/cli-plugin-babel": "^4.5.15",
"@vue/cli-plugin-eslint": "^3.12.1",
Expand All @@ -81,11 +83,14 @@
"electron": "^23.1.2",
"electron-builder": "^22.9.1",
"electron-notarize": "^1.2.2",
"electron-playwright-helpers": "^1.5.3",
"eslint": "^5.16.0",
"eslint-plugin-no-for-each": "^0.1.14",
"eslint-plugin-vue": "^5.2.3",
"lint-staged": "^8.2.1",
"node-loader": "^0.6.0",
"playwright": "^1.31.2",
"playwright-core": "^1.31.2",
"sass-loader": "^7.3.1",
"text-loader": "0.0.1",
"vue-cli-plugin-electron-builder": "^2.0.0",
Expand Down
9 changes: 9 additions & 0 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig, expect } from "@playwright/test";
import extensions from "./tests/e2e/extentions";

expect.extend(extensions);

export default defineConfig({
testDir: "./tests/e2e/spec",
workers: process.env.CI ? 1 : 2
});
3 changes: 3 additions & 0 deletions src/application/worker/index.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ async function start() {
const grabCanvasPlugin = require("../plugins/grab-canvas").default;
const get = require("lodash.get");

// For Playwright
self._get = get;

const { tick: frameTick } = require("./frame-counter");
const { getFeatures, setFeatures } = require("./audio-features");
// const featureAssignmentPlugin = require("../plugins/feature-assignment");
Expand Down
8 changes: 5 additions & 3 deletions src/background/background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, protocol } from "electron";
import { app, ipcMain, protocol } from "electron";
import { APP_SCHEME } from "./background-constants";
import { getMediaManager } from "./media-manager";
import { openFile } from "./open-file";
Expand Down Expand Up @@ -73,8 +73,10 @@ app.on("ready", async () => {
);

createWindow({ windowName: "mainWindow" });
createWindow({ windowName: "splashScreen" });
createWindow({ windowName: "colorPicker", options: { show: false } });
ipcMain.once("main-window-created", () => {
createWindow({ windowName: "splashScreen" });
createWindow({ windowName: "colorPicker", options: { show: false } });
});
});

// Exit cleanly on request from parent process in development mode.
Expand Down
11 changes: 9 additions & 2 deletions src/background/window-prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { closeWindow, createWindow, windows } from "./windows";
import { updateMenu } from "./menu-bar";
import { getMediaManager } from "./media-manager";

const isDevelopment = process.env.NODE_ENV !== "production";
const isDevelopment = process.env.NODE_ENV === "development";
const isTest = process.env.CI === "e2e";
let shouldCloseMainWindowAndQuit = false;
let modVReady = false;

const windowPrefs = {
colorPicker: {
Expand Down Expand Up @@ -65,6 +67,8 @@ const windowPrefs = {
beforeCreate() {
const { width, height } = screen.getPrimaryDisplay().workAreaSize;

modVReady = false;

return {
options: {
width,
Expand All @@ -76,6 +80,8 @@ const windowPrefs = {
async create(window) {
require("@electron/remote/main").enable(window.webContents);

ipcMain.handle("is-modv-ready", () => modVReady);

// Configure child windows to open without a menubar (windows/linux)
window.webContents.on(
"new-window",
Expand Down Expand Up @@ -114,6 +120,7 @@ const windowPrefs = {
});

ipcMain.on("modv-ready", () => {
modVReady = true;
mm.start();
});

Expand Down Expand Up @@ -144,7 +151,7 @@ const windowPrefs = {
window.webContents.send("input-update", message);
});

if (!isDevelopment || process.env.IS_TEST) {
if (!isDevelopment && !isTest) {
window.on("close", async e => {
if (shouldCloseMainWindowAndQuit) {
app.quit();
Expand Down
9 changes: 5 additions & 4 deletions src/components/ActiveModule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
@focus="clickActiveModule"
ref="activeModule"
:class="{ focused }"
:id="`active-module-${id}`"
>
<div
class="active-module__title handle"
class="active-module__name handle"
:class="{ grabbing }"
@mousedown="titleMouseDown"
>
Expand Down Expand Up @@ -264,7 +265,7 @@ export default {
outline: #c4c4c4 2px solid;
}
.active-module__title {
.active-module__name {
background: #9a9a9a;
width: 100%;
overflow: hidden;
Expand All @@ -273,7 +274,7 @@ export default {
cursor: grab;
}
.active-module__title.grabbing {
.active-module__name.grabbing {
cursor: grabbing;
}
Expand All @@ -285,7 +286,7 @@ export default {
}
.active-module__controls grid,
.active-module__title {
.active-module__name {
box-sizing: border-box;
padding: 0 4px;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Control.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
columns="4"
@mousedown="focusInput"
:class="{ 'has-link': hasLink, focused: inputIsFocused }"
:id="`module-control-${inputId}`"
>
<c span="1">
<label v-context-menu="menuOptions">{{ title }}</label>
Expand Down
53 changes: 32 additions & 21 deletions src/components/Group.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div
class="group"
:id="`group-${groupId}`"
v-searchTerms="{
terms: ['group'],
title: name,
Expand Down Expand Up @@ -44,6 +45,7 @@
<c span="4">
<Select
v-model="inheritanceSelection"
class="group__inheritSelect"
:class="{ light: isFocused(group.inheritInputId) }"
>
<option :value="-2">Don't Inherit</option>
Expand Down Expand Up @@ -72,6 +74,7 @@
<c span="4">
<Checkbox
v-model="clearing"
class="group__clearingCheckbox"
:class="{ light: isFocused(group.clearingInputId) }"
/>
</c>
Expand All @@ -91,6 +94,7 @@
<c span="4">
<Checkbox
v-model="pipeline"
class="group__pipelineCheckbox"
:class="{ light: isFocused(group.pipelineInputId) }"
/>
</c>
Expand All @@ -108,7 +112,13 @@
>
<c span="2">Alpha</c>
<c span="4">
<Range value="1" max="1" step="0.001" v-model="alpha" />
<Range
class="group__alphaRange"
value="1"
max="1"
step="0.001"
v-model="alpha"
/>
</c>
</grid>
</c>
Expand All @@ -128,6 +138,7 @@
<c span="4">
<Select
v-model="blendMode"
class="group__blendModeSelect"
:class="{ light: isFocused(group.compositeOperationInputId) }"
>
<optgroup
Expand Down Expand Up @@ -180,19 +191,19 @@
</div>
<div class="group__right">
<div
class="group__title"
class="group__name"
:class="{ grabbing }"
@click.self="endTitleEditable"
@click.self="endNameEditable"
@mousedown="titleMouseDown"
>
<span v-if="!titleEditable" @dblclick="toggleTitleEditable">{{
<span v-if="!nameEditable" @dblclick="toggleNameEditable">{{
name
}}</span>
<TextInput
v-model="localName"
ref="titleInput"
ref="nameInput"
v-else
@keypress.enter="endTitleEditable"
@keypress.enter="endNameEditable"
/>
</div>
<figure
Expand Down Expand Up @@ -268,7 +279,7 @@ export default {
data() {
return {
compositeOperations,
titleEditable: false,
nameEditable: false,
localName: "",
controlsShown: false,
Arrow,
Expand All @@ -287,7 +298,7 @@ export default {
},
beforeDestroy() {
window.removeEventListener("mousedown", this.endTitleEditable);
window.removeEventListener("mousedown", this.endNameEditable);
},
computed: {
Expand Down Expand Up @@ -485,24 +496,24 @@ export default {
}
},
toggleTitleEditable() {
this.titleEditable = !this.titleEditable;
toggleNameEditable() {
this.nameEditable = !this.nameEditable;
if (this.titleEditable) {
window.addEventListener("mousedown", this.endTitleEditable);
if (this.nameEditable) {
window.addEventListener("mousedown", this.endNameEditable);
this.$nextTick(() => {
this.$refs.titleInput.$el.focus();
this.$refs.titleInput.$el.select();
this.$refs.nameInput.$el.focus();
this.$refs.nameInput.$el.select();
});
}
},
endTitleEditable(e) {
if (e.target === this.$refs.titleInput.$el) {
endNameEditable(e) {
if (e instanceof MouseEvent && e.target === this.$refs.nameInput.$el) {
return;
}
window.removeEventListener("mousedown", this.endTitleEditable);
window.removeEventListener("mousedown", this.endNameEditable);
const { localName } = this;
const trimmedName = localName.trim();
Expand All @@ -516,7 +527,7 @@ export default {
this.localName = this.name;
}
this.titleEditable = false;
this.nameEditable = false;
},
focusInput(id, title) {
Expand Down Expand Up @@ -678,19 +689,19 @@ export default {
align-items: center;
}
.group__title {
.group__name {
background: #363636;
color: white;
padding: 8px;
line-height: 1;
cursor: grab;
}
.group__title.grabbing {
.group__name.grabbing {
cursor: grabbing;
}
.group__title input {
.group__name input {
max-width: 120px;
}
Expand Down
6 changes: 4 additions & 2 deletions src/components/Groups.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}"
>
<Container
drag-handle-selector=".group__title"
drag-handle-selector=".group__name"
lock-axis="y"
group-name="groups"
:should-animate-drop="() => false"
Expand All @@ -23,7 +23,9 @@
</Draggable>
</Container>

<Button class="light" @click="createGroup">New Group</Button>
<Button id="new-group-button" class="light" @click="createGroup">
New Group
</Button>
</div>
</template>

Expand Down
4 changes: 2 additions & 2 deletions src/components/InputConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div v-if="inputConfig">
<grid class="borders">
<c span="1.."
><div class="title">{{ focusedInputTitle }}</div></c
><div class="input-config__title">{{ focusedInputTitle }}</div></c
>
<c span="1..">
<grid columns="4">
Expand Down Expand Up @@ -196,7 +196,7 @@ grid.borders > c:not(:last-child):not(:first-child) {
border-bottom: 1px solid var(--foreground-color-2);
}
.title {
.input-config__title {
font-size: 24px;
}
</style>
Expand Down
10 changes: 7 additions & 3 deletions src/components/ModuleInspector.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<template>
<grid v-if="module.props" ref="moduleInspector">
<grid
v-if="module.props"
ref="moduleInspector"
:id="`module-inspector-${module.$id}`"
>
<c span="1.." class="hidden">
<button class="pin-button" @click="toggleModulePin(module.$id)">
({{ isPinned(module.$id) ? "Unpin" : "Pin" }})
</button>
</c>
<c span="1..">
<div class="title">{{ module.meta.name }}</div>
<div class="module-inspector__title">{{ module.meta.name }}</div>
</c>
<c span="1..">
<ModuleControl
Expand Down Expand Up @@ -90,7 +94,7 @@ grid {
margin: -8px;
}
.title {
.module-inspector__title {
font-size: 24px;
padding: 8px;
}
Expand Down
Loading

0 comments on commit 2cad1e0

Please sign in to comment.