2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-27 19:16:44 +00:00

Revert some playwright changes (#9419)

* Revert some playwright changes

- Use vite dev server all the time

* Simplify test
This commit is contained in:
Oliver 2025-03-31 20:12:26 +11:00 committed by GitHub
parent f7a4469590
commit fcc6709b3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 59 deletions

View File

@ -584,6 +584,7 @@ jobs:
INVENTREE_DB_PASSWORD: inventree_password
INVENTREE_DEBUG: true
INVENTREE_PLUGINS_ENABLED: false
VITE_COVERAGE_BUILD: true
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4.2.2
@ -605,12 +606,6 @@ jobs:
run: |
invoke int.frontend-compile
cd src/frontend && npx playwright install --with-deps
- name: Set Production Mode
if: github.event_name == 'pull_request'
run: echo "VITE_PRODUCTION_BUILD=true" >> $GITHUB_ENV
- name: Set Coverage Mode
if: github.event_name != 'pull_request'
run: echo "VITE_COVERAGE_BUILD=true" >> $GITHUB_ENV
- name: Run Playwright tests
id: tests
run: cd src/frontend && npx nyc playwright test

View File

@ -1,17 +1,10 @@
import { defineConfig, devices } from '@playwright/test';
import type TestConfigWebServer from '@playwright/test';
// Detect if running in CI
const IS_CI = !!process.env.CI;
const IS_COVERAGE = !!process.env.VITE_COVERAGE_BUILD;
// If specified, tests will be run against the production build
const IS_PRODUCTION = !!process.env.VITE_PRODUCTION_BUILD;
console.log('Running Playwright tests:');
console.log(` - CI Mode: ${IS_CI}`);
console.log(` - Coverage Mode: ${IS_COVERAGE}`);
console.log(` - Production Mode: ${IS_PRODUCTION}`);
const MAX_WORKERS: number = 3;
const MAX_RETRIES: number = 3;
@ -37,59 +30,19 @@ const MAX_RETRIES: number = 3;
* - WORKERS = 1 (to avoid conflicts with HMR)
*/
const devServer: TestConfigWebServer = {
command: 'yarn run dev --host --port 5173',
url: 'http://localhost:5173',
reuseExistingServer: IS_CI,
stdout: 'pipe',
stderr: 'pipe',
timeout: 120 * 1000
};
const WEB_BUILD_CMD: string =
'yarn run extract && yarn run compile && yarn run build';
// Command to spin-up the backend server
// In production mode, we want a stronger webserver to handle multiple requests
const WEB_SERVER_CMD: string = IS_PRODUCTION
? `${WEB_BUILD_CMD} && gunicorn --chdir ../backend/InvenTree --workers 8 --thread 8 --bind 127.0.0.1:8000 InvenTree.wsgi`
const WEB_SERVER_CMD: string = IS_CI
? 'gunicorn --chdir ../backend/InvenTree --workers 8 --thread 8 --bind 127.0.0.1:8000 InvenTree.wsgi'
: 'invoke dev.server -a 127.0.0.1:8000';
const webServer: TestConfigWebServer = {
// If running in production mode, we need to build the frontend first
command: WEB_SERVER_CMD,
env: {
INVENTREE_DEBUG: 'True',
INVENTREE_PLUGINS_ENABLED: 'True',
INVENTREE_ADMIN_URL: 'test-admin',
INVENTREE_SITE_URL: 'http://localhost:8000',
INVENTREE_FRONTEND_API_HOST: 'http://localhost:8000',
INVENTREE_CORS_ORIGIN_ALLOW_ALL: 'True',
INVENTREE_COOKIE_SAMESITE: 'Lax',
INVENTREE_LOGIN_ATTEMPTS: '100'
},
url: 'http://localhost:8000/api/',
reuseExistingServer: IS_CI,
stdout: 'pipe',
stderr: 'pipe',
timeout: 120 * 1000
};
const serverList: TestConfigWebServer[] = [];
if (!IS_PRODUCTION) {
serverList.push(devServer);
}
serverList.push(webServer);
export default defineConfig({
testDir: './tests',
fullyParallel: false,
timeout: 90000,
forbidOnly: !!IS_CI,
retries: IS_CI ? MAX_RETRIES : 0,
workers: IS_PRODUCTION ? MAX_WORKERS : 1,
workers: IS_CI ? MAX_WORKERS : 1,
reporter: IS_CI ? [['html', { open: 'never' }], ['github']] : 'list',
/* Configure projects for major browsers */
@ -109,11 +62,38 @@ export default defineConfig({
],
/* Run your local dev server before starting the tests */
webServer: serverList,
webServer: [
{
command: 'yarn run dev --host --port 5173',
url: 'http://localhost:5173',
reuseExistingServer: IS_CI,
stdout: 'pipe',
stderr: 'pipe',
timeout: 120 * 1000
},
{
command: WEB_SERVER_CMD,
env: {
INVENTREE_DEBUG: 'True',
INVENTREE_PLUGINS_ENABLED: 'True',
INVENTREE_ADMIN_URL: 'test-admin',
INVENTREE_SITE_URL: 'http://localhost:8000',
INVENTREE_FRONTEND_API_HOST: 'http://localhost:8000',
INVENTREE_CORS_ORIGIN_ALLOW_ALL: 'True',
INVENTREE_COOKIE_SAMESITE: 'Lax',
INVENTREE_LOGIN_ATTEMPTS: '100'
},
url: 'http://localhost:8000/api/',
reuseExistingServer: IS_CI,
stdout: 'pipe',
stderr: 'pipe',
timeout: 120 * 1000
}
],
globalSetup: './playwright/global-setup.ts',
use: {
baseURL: IS_PRODUCTION ? 'http://localhost:8000' : 'http://localhost:5173',
headless: IS_PRODUCTION ? true : undefined,
baseURL: 'http://localhost:5173',
headless: IS_CI ? true : undefined,
trace: 'on-first-retry'
}
});