Skip to content

Commit e24b928

Browse files
Run tests in electron, add eslint plugin for playwright
1 parent 3149439 commit e24b928

File tree

10 files changed

+137
-78
lines changed

10 files changed

+137
-78
lines changed

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"syler.sass-indented",
77
"redhat.vscode-yaml",
88
"vue.volar",
9-
"eamodio.gitlens"
9+
"eamodio.gitlens",
10+
"ms-playwright.playwright"
1011
]
1112
}

_scripts/dev-runner.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ let manualRestart = null
1515

1616
const remoteDebugging = process.argv.indexOf('--remote-debug') !== -1
1717
const web = process.argv.indexOf('--web') !== -1
18-
const noopen = process.argv.indexOf('--no-open') !== -1
1918

2019
let mainConfig
2120
let rendererConfig
@@ -223,7 +222,7 @@ function startWeb () {
223222
})
224223

225224
const server = new WebpackDevServer({
226-
open: !noopen,
225+
open: true,
227226
static: {
228227
directory: path.resolve(__dirname, '..', 'static'),
229228
watch: {

e2e/Settings.e2e.mjs

Lines changed: 0 additions & 28 deletions
This file was deleted.

e2e/helpers.mjs

Lines changed: 0 additions & 28 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ import eslintPluginYml from 'eslint-plugin-yml'
1414
import { neostandard } from 'neostandard/lib/main.js'
1515
import jsdoc from 'eslint-plugin-jsdoc'
1616
import freetube from './_scripts/eslint-rules/plugin.mjs'
17+
import eslintPluginPlaywright from 'eslint-plugin-playwright'
1718

1819
import activeLocales from './static/locales/activeLocales.json' with { type: 'json' }
20+
import { defineConfig } from "eslint/config";
1921

20-
export default [
22+
export default defineConfig([
2123
{
2224
ignores: [
2325
'build/',
@@ -226,7 +228,7 @@ export default [
226228
}
227229
},
228230
{
229-
files: ['_scripts/**/*.mjs'],
231+
files: ['_scripts/**/*.mjs', 'tests/**/*.mjs'],
230232
languageOptions: {
231233
globals: globals.node,
232234
ecmaVersion: 'latest',
@@ -246,5 +248,24 @@ export default [
246248
'unicorn/prefer-date-now': 'error',
247249
'unicorn/prefer-array-index-of': 'error',
248250
}
251+
},
252+
{
253+
files: ['tests/playwright/helpers.mjs', 'tests/playwright/**/*spec.mjs'],
254+
extends: [eslintPluginPlaywright.configs['flat/recommended']],
255+
settings: {
256+
playwright: {
257+
globalAliases: {
258+
test: ["electronDesktopTest", "electronMobileTest", "electronTabletTest"],
259+
}
260+
}
261+
},
262+
rules: {
263+
"playwright/expect-expect": [
264+
"error",
265+
{
266+
"assertFunctionNames": ["validateAccessibility"],
267+
}
268+
]
269+
}
249270
}
250-
]
271+
])

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,15 @@
3030
"debug-runner": "node _scripts/dev-runner.js --remote-debug",
3131
"dev": "run-s patch-shaka dev-runner",
3232
"dev:web": "node _scripts/dev-runner.js --web",
33-
"dev:web-noopen": "node _scripts/dev-runner.js --web --no-open",
3433
"dev-runner": "node _scripts/dev-runner.js",
3534
"get-instances": "node _scripts/getInstances.js",
3635
"patch-shaka": "node _scripts/patchShaka.mjs",
3736
"get-regions": "node _scripts/getRegions.mjs",
3837
"lint-all": "run-p lint lint-json",
3938
"lint": "run-p eslint-lint lint-style",
4039
"lint-fix": "run-p eslint-lint-fix lint-style-fix",
41-
"eslint-lint": "eslint --config eslint.config.mjs \"src/**/*.js\" \"src/renderer/**/*.vue\" \"static/*.js\" \"_scripts/*.js\" \"_scripts/**/*.mjs\"",
42-
"eslint-lint-fix": "eslint --config eslint.config.mjs --fix \"src/**/*.js\" \"src/renderer/**/*.vue\" \"static/*.js\" \"_scripts/*.js\" \"_scripts/**/*.mjs\"",
40+
"eslint-lint": "eslint --config eslint.config.mjs \"src/**/*.js\" \"src/renderer/**/*.vue\" \"static/*.js\" \"_scripts/*.js\" \"_scripts/**/*.mjs\" \"tests/**/*.mjs\"",
41+
"eslint-lint-fix": "eslint --config eslint.config.mjs --fix \"src/**/*.js\" \"src/renderer/**/*.vue\" \"static/*.js\" \"_scripts/*.js\" \"_scripts/**/*.mjs\" \"tests/**/*.mjs\"",
4342
"lint-json": "eslint --config eslint.config.mjs \"static/**/*.json\"",
4443
"lint-style": "stylelint \"src/**/*.{css,scss}\"",
4544
"lint-style-fix": "stylelint --fix \"src/**/*.{css,scss}\"",
@@ -53,7 +52,8 @@
5352
"postinstall": "yarn run --silent patch-shaka",
5453
"checkforbadtemplates": "node _scripts/findMissingTemplates.mjs",
5554
"ci": "yarn install --silent --frozen-lockfile --network-concurrency 1",
56-
"test:e2e": "playwright test"
55+
"test:playwright": "run-s pack test:playwright-nopack",
56+
"test:playwright-nopack": "playwright test"
5757
},
5858
"dependencies": {
5959
"@fortawesome/fontawesome-svg-core": "^7.1.0",
@@ -94,6 +94,7 @@
9494
"eslint": "^9.39.2",
9595
"eslint-plugin-jsdoc": "^62.5.2",
9696
"eslint-plugin-jsonc": "^2.21.0",
97+
"eslint-plugin-playwright": "^2.5.1",
9798
"eslint-plugin-unicorn": "^62.0.0",
9899
"eslint-plugin-vue": "^10.7.0",
99100
"eslint-plugin-vuejs-accessibility": "^2.4.1",

playwright.config.mjs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
/** @type {import('@playwright/test').PlaywrightTestConfig} */
22
export default {
3-
testDir: './e2e',
4-
testMatch: '*.e2e.mjs',
5-
// retries: 1,
6-
fullyParallel: true,
7-
use: {
8-
headless: !!process.env.CI,
9-
baseURL: 'http://localhost:9080'
10-
},
11-
webServer: {
12-
command: 'npm run dev:web-noopen',
13-
url: 'http://localhost:9080',
14-
},
3+
testDir: './tests/playwright',
4+
testMatch: '*.spec.mjs',
5+
workers: 1,
6+
fullyParallel: false
157
}

tests/playwright/helpers.mjs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { devices, expect, test, _electron as electron } from '@playwright/test'
2+
import { join } from 'path'
3+
import { AxeBuilder } from '@axe-core/playwright'
4+
5+
const mainJs = join(import.meta.dirname, '../../dist/main.js')
6+
7+
/**
8+
*
9+
* @param {string} name
10+
* @param {import('@playwright/test').ViewportSize} viewPortSize
11+
* @param {(function({ app: import('@playwright/test').ElectronApplication, page: import('@playwright/test').Page }) : Promise<void>)} func
12+
*/
13+
const electronTest = async (name, viewPortSize, func) => {
14+
// eslint-disable-next-line playwright/expect-expect, playwright/valid-title
15+
test(name, async () => {
16+
const electronApp = await electron.launch({ args: [mainJs] })
17+
const page = await electronApp.firstWindow()
18+
page.setViewportSize(viewPortSize)
19+
20+
await func({ app: electronApp, page })
21+
22+
await electronApp.close()
23+
})
24+
}
25+
26+
/**
27+
* @param {string} name
28+
* @param {(function({ app: import('@playwright/test').ElectronApplication, page: import('@playwright/test').Page }) : Promise<void>)} func
29+
*/
30+
export const electronDesktopTest = async (name, func) => {
31+
await electronTest(name, devices['Desktop Firefox'].viewport, func)
32+
}
33+
34+
/**
35+
* @param {string} name
36+
* @param {(function({ app: import('@playwright/test').ElectronApplication, page: import('@playwright/test').Page }) : Promise<void>)} func
37+
*/
38+
export const electronMobileTest = async (name, func) => {
39+
await electronTest(name, devices['LG Optimus L70'].viewport, func)
40+
}
41+
42+
/**
43+
* @param {string} name
44+
* @param {(function({ app: import('@playwright/test').ElectronApplication, page: import('@playwright/test').Page }) : Promise<void>)} func
45+
*/
46+
export const electronTabletTest = async (name, func) => {
47+
await electronTest(name, devices['Galaxy Tab S9'].viewport, func)
48+
}
49+
50+
/**
51+
* @param {import('@playwright/test').Page} page
52+
*/
53+
export async function validateAccessibility (page) {
54+
const axeResults = await new AxeBuilder({ page })
55+
.setLegacyMode(true)
56+
.analyze()
57+
58+
expect(axeResults.violations).toHaveLength(0)
59+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { electronDesktopTest, electronMobileTest, electronTabletTest, validateAccessibility } from '../helpers.mjs'
2+
3+
electronDesktopTest('desktop - settings - accessibility test', async ({ page }) => {
4+
await page.waitForLoadState('load')
5+
await page.waitForLoadState('domcontentloaded')
6+
7+
// go to settings page
8+
await page.locator('a[href="#/settings"]').last().click()
9+
await page.waitForLoadState('load')
10+
await page.waitForLoadState('domcontentloaded')
11+
await validateAccessibility(page)
12+
})
13+
14+
electronMobileTest('mobile - settings - accessibility test', async ({ page }) => {
15+
await page.waitForLoadState('load')
16+
await page.waitForLoadState('domcontentloaded')
17+
18+
// go to settings page
19+
await page.locator('.moreOptionNav').click()
20+
await page.locator('a[href="#/settings"]').first().click()
21+
await page.waitForLoadState('load')
22+
await page.waitForLoadState('domcontentloaded')
23+
await validateAccessibility(page)
24+
})
25+
26+
electronTabletTest('tablet - settings - accessibility test', async ({ page }) => {
27+
await page.waitForLoadState('load')
28+
await page.waitForLoadState('domcontentloaded')
29+
30+
// go to settings page
31+
await page.locator('a[href="#/settings"]').last().click()
32+
await page.waitForLoadState('load')
33+
await page.waitForLoadState('domcontentloaded')
34+
await validateAccessibility(page)
35+
})

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4388,6 +4388,13 @@ eslint-plugin-n@^17.20.0:
43884388
semver "^7.6.3"
43894389
ts-declaration-location "^1.0.6"
43904390

4391+
eslint-plugin-playwright@^2.5.1:
4392+
version "2.5.1"
4393+
resolved "https://registry.yarnpkg.com/eslint-plugin-playwright/-/eslint-plugin-playwright-2.5.1.tgz#f4bdc721ecaab2dac4690208ebd48ae020513435"
4394+
integrity sha512-q7oqVQTTfa3VXJQ8E+ln0QttPGrs/XmSO1FjOMzQYBMYF3btih4FIrhEYh34JF184GYDmq3lJ/n7CMa49OHBvA==
4395+
dependencies:
4396+
globals "^16.4.0"
4397+
43914398
eslint-plugin-promise@^7.2.1:
43924399
version "7.2.1"
43934400
resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-7.2.1.tgz#a0652195700aea40b926dc3c74b38e373377bfb0"

0 commit comments

Comments
 (0)