1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-11-04 08:17:24 -05:00

move playwright to typescript

This commit is contained in:
silverwind 2024-05-31 16:53:46 +02:00
parent 09e2dac12e
commit 108f5fa2f4
No known key found for this signature in database
GPG Key ID: 2E62B41C93869443
6 changed files with 44 additions and 18 deletions

View File

@ -58,6 +58,9 @@ overrides:
- files: ["*.config.*"] - files: ["*.config.*"]
rules: rules:
i/no-unused-modules: [0] i/no-unused-modules: [0]
- files: ["tests/e2e/**"]
plugins: [eslint-plugin-playwright]
extends: plugin:playwright/recommended
- files: ["**/*.test.*", "web_src/js/test/setup.js"] - files: ["**/*.test.*", "web_src/js/test/setup.js"]
env: env:
vitest-globals/env: true vitest-globals/env: true

25
package-lock.json generated
View File

@ -78,6 +78,7 @@
"eslint-plugin-jquery": "1.5.1", "eslint-plugin-jquery": "1.5.1",
"eslint-plugin-no-jquery": "2.7.0", "eslint-plugin-no-jquery": "2.7.0",
"eslint-plugin-no-use-extend-native": "0.5.0", "eslint-plugin-no-use-extend-native": "0.5.0",
"eslint-plugin-playwright": "1.6.2",
"eslint-plugin-regexp": "2.6.0", "eslint-plugin-regexp": "2.6.0",
"eslint-plugin-sonarjs": "1.0.3", "eslint-plugin-sonarjs": "1.0.3",
"eslint-plugin-unicorn": "53.0.0", "eslint-plugin-unicorn": "53.0.0",
@ -5810,6 +5811,30 @@
"node": ">=6.0.0" "node": ">=6.0.0"
} }
}, },
"node_modules/eslint-plugin-playwright": {
"version": "1.6.2",
"resolved": "https://registry.npmjs.org/eslint-plugin-playwright/-/eslint-plugin-playwright-1.6.2.tgz",
"integrity": "sha512-mraN4Em3b5jLt01q7qWPyLg0Q5v3KAWfJSlEWwldyUXoa7DSPrBR4k6B6LROLqipsG8ndkwWMdjl1Ffdh15tag==",
"dev": true,
"workspaces": [
"examples"
],
"dependencies": {
"globals": "^13.23.0"
},
"engines": {
"node": ">=16.6.0"
},
"peerDependencies": {
"eslint": ">=8.40.0",
"eslint-plugin-jest": ">=25"
},
"peerDependenciesMeta": {
"eslint-plugin-jest": {
"optional": true
}
}
},
"node_modules/eslint-plugin-prettier": { "node_modules/eslint-plugin-prettier": {
"version": "5.1.3", "version": "5.1.3",
"resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.1.3.tgz", "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.1.3.tgz",

View File

@ -77,6 +77,7 @@
"eslint-plugin-jquery": "1.5.1", "eslint-plugin-jquery": "1.5.1",
"eslint-plugin-no-jquery": "2.7.0", "eslint-plugin-no-jquery": "2.7.0",
"eslint-plugin-no-use-extend-native": "0.5.0", "eslint-plugin-no-use-extend-native": "0.5.0",
"eslint-plugin-playwright": "1.6.2",
"eslint-plugin-regexp": "2.6.0", "eslint-plugin-regexp": "2.6.0",
"eslint-plugin-sonarjs": "1.0.3", "eslint-plugin-sonarjs": "1.0.3",
"eslint-plugin-unicorn": "53.0.0", "eslint-plugin-unicorn": "53.0.0",

View File

@ -1,12 +1,8 @@
// @ts-check
import {devices} from '@playwright/test'; import {devices} from '@playwright/test';
import {env} from 'node:process';
const BASE_URL = process.env.GITEA_URL?.replace?.(/\/$/g, '') || 'http://localhost:3000'; const BASE_URL = env.GITEA_URL?.replace?.(/\/$/g, '') || 'http://localhost:3000';
/**
* @see https://playwright.dev/docs/test-configuration
* @type {import('@playwright/test').PlaywrightTestConfig}
*/
export default { export default {
testDir: './tests/e2e/', testDir: './tests/e2e/',
testMatch: /.*\.test\.e2e\.js/, // Match any .test.e2e.js files testMatch: /.*\.test\.e2e\.js/, // Match any .test.e2e.js files
@ -24,13 +20,13 @@ export default {
}, },
/* Fail the build on CI if you accidentally left test.only in the source code. */ /* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: Boolean(process.env.CI), forbidOnly: Boolean(env.CI),
/* Retry on CI only */ /* Retry on CI only */
retries: process.env.CI ? 2 : 0, retries: env.CI ? 2 : 0,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ /* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: process.env.CI ? 'list' : [['list'], ['html', {outputFolder: 'tests/e2e/reports/', open: 'never'}]], reporter: env.CI ? 'list' : [['list'], ['html', {outputFolder: 'tests/e2e/reports/', open: 'never'}]],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: { use: {

View File

@ -1,19 +1,19 @@
// @ts-check // @ts-check
import {test, expect} from '@playwright/test'; import {test, expect} from '@playwright/test';
import {login_user, save_visual, load_logged_in_context} from './utils_e2e.js'; import {login_user, save_visual, load_logged_in_context} from './utils_e2e.ts';
test.beforeAll(async ({browser}, workerInfo) => { test.beforeAll(async ({browser}, workerInfo) => {
await login_user(browser, workerInfo, 'user2'); await login_user(browser, workerInfo, 'user2');
}); });
test('Load Homepage', async ({page}) => { test('homepage', async ({page}) => {
const response = await page.goto('/'); const response = await page.goto('/');
await expect(response?.status()).toBe(200); // Status OK await expect(response?.status()).toBe(200); // Status OK
await expect(page).toHaveTitle(/^Gitea: Git with a cup of tea\s*$/); await expect(page).toHaveTitle(/^Gitea: Git with a cup of tea\s*$/);
await expect(page.locator('.logo')).toHaveAttribute('src', '/assets/img/logo.svg'); await expect(page.locator('.logo')).toHaveAttribute('src', '/assets/img/logo.svg');
}); });
test('Test Register Form', async ({page}, workerInfo) => { test('register', async ({page}, workerInfo) => {
const response = await page.goto('/user/sign_up'); const response = await page.goto('/user/sign_up');
await expect(response?.status()).toBe(200); // Status OK await expect(response?.status()).toBe(200); // Status OK
await page.type('input[name=user_name]', `e2e-test-${workerInfo.workerIndex}`); await page.type('input[name=user_name]', `e2e-test-${workerInfo.workerIndex}`);
@ -29,7 +29,7 @@ test('Test Register Form', async ({page}, workerInfo) => {
save_visual(page); save_visual(page);
}); });
test('Test Login Form', async ({page}, workerInfo) => { test('login', async ({page}, workerInfo) => {
const response = await page.goto('/user/login'); const response = await page.goto('/user/login');
await expect(response?.status()).toBe(200); // Status OK await expect(response?.status()).toBe(200); // Status OK
@ -37,14 +37,14 @@ test('Test Login Form', async ({page}, workerInfo) => {
await page.type('input[name=password]', `password`); await page.type('input[name=password]', `password`);
await page.click('form button.ui.primary.button:visible'); await page.click('form button.ui.primary.button:visible');
await page.waitForLoadState('networkidle'); await page.waitForLoadState('networkidle'); // eslint-disable-line playwright/no-networkidle
await expect(page.url()).toBe(`${workerInfo.project.use.baseURL}/`); await expect(page.url()).toBe(`${workerInfo.project.use.baseURL}/`);
save_visual(page); save_visual(page);
}); });
test('Test Logged In User', async ({browser}, workerInfo) => { test('logged in user', async ({browser}, workerInfo) => {
const context = await load_logged_in_context(browser, workerInfo, 'user2'); const context = await load_logged_in_context(browser, workerInfo, 'user2');
const page = await context.newPage(); const page = await context.newPage();

View File

@ -1,4 +1,5 @@
import {expect} from '@playwright/test'; import {expect} from '@playwright/test';
import {env} from 'node:process';
const ARTIFACTS_PATH = `tests/e2e/test-artifacts`; const ARTIFACTS_PATH = `tests/e2e/test-artifacts`;
const LOGIN_PASSWORD = 'password'; const LOGIN_PASSWORD = 'password';
@ -20,7 +21,7 @@ export async function login_user(browser, workerInfo, user) {
await page.type('input[name=password]', LOGIN_PASSWORD); await page.type('input[name=password]', LOGIN_PASSWORD);
await page.click('form button.ui.primary.button:visible'); await page.click('form button.ui.primary.button:visible');
await page.waitForLoadState('networkidle'); await page.waitForLoadState('networkidle'); // eslint-disable-line playwright/no-networkidle
await expect(page.url(), {message: `Failed to login user ${user}`}).toBe(`${workerInfo.project.use.baseURL}/`); await expect(page.url(), {message: `Failed to login user ${user}`}).toBe(`${workerInfo.project.use.baseURL}/`);
@ -44,8 +45,8 @@ export async function load_logged_in_context(browser, workerInfo, user) {
export async function save_visual(page) { export async function save_visual(page) {
// Optionally include visual testing // Optionally include visual testing
if (process.env.VISUAL_TEST) { if (env.VISUAL_TEST) {
await page.waitForLoadState('networkidle'); await page.waitForLoadState('networkidle'); // eslint-disable-line playwright/no-networkidle
// Mock page/version string // Mock page/version string
await page.locator('footer div.ui.left').evaluate((node) => node.innerHTML = 'MOCK'); await page.locator('footer div.ui.left').evaluate((node) => node.innerHTML = 'MOCK');
await expect(page).toHaveScreenshot({ await expect(page).toHaveScreenshot({