From 6fef2df6b91129dee6735a233df4578a96aa9db9 Mon Sep 17 00:00:00 2001 From: Igor Lobanov Date: Wed, 5 Feb 2025 11:18:29 +0100 Subject: [PATCH] do not remove config on local e2e run --- Makefile | 2 +- bamboo-specs/test.yaml | 2 +- client/playwright.config.ts | 5 ++--- client/tests/e2e/globalSetup.ts | 10 ++++++++++ client/tests/e2e/globalTeardown.ts | 20 ++++++++++++++++++++ 5 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 client/tests/e2e/globalTeardown.ts diff --git a/Makefile b/Makefile index f28314f1..91c5682c 100644 --- a/Makefile +++ b/Makefile @@ -108,7 +108,7 @@ js-build: ; $(NPM) $(NPM_FLAGS) run build-prod js-deps: ; $(NPM) $(NPM_INSTALL_FLAGS) ci js-lint: ; $(NPM) $(NPM_FLAGS) run lint js-test: ; $(NPM) $(NPM_FLAGS) run test -js-test-e2e: ; npx $(NPM_FLAGS) playwright install --with-deps && $(NPM) $(NPM_FLAGS) run test:e2e +js-test-e2e: ; $(NPM) $(NPM_FLAGS) run test:e2e go-bench: ; $(ENV) "$(SHELL)" ./scripts/make/go-bench.sh go-build: ; $(ENV) "$(SHELL)" ./scripts/make/go-build.sh diff --git a/bamboo-specs/test.yaml b/bamboo-specs/test.yaml index 5dded53a..cd825541 100644 --- a/bamboo-specs/test.yaml +++ b/bamboo-specs/test.yaml @@ -199,7 +199,7 @@ mv /tmp/AdGuardHome/AdGuardHome ./AdGuardHome - make VERBOSE=1 js-deps js-test-e2e + make VERBOSE=1 js-test-e2e 'requirements': - 'adg-docker': 'true' diff --git a/client/playwright.config.ts b/client/playwright.config.ts index 32aa3bd6..40483eb8 100644 --- a/client/playwright.config.ts +++ b/client/playwright.config.ts @@ -8,6 +8,7 @@ import path from 'path'; export default defineConfig({ testDir: './tests/e2e', globalSetup: path.resolve('./tests/e2e/globalSetup.ts'), + globalTeardown: path.resolve('./tests/e2e/globalTeardown.ts'), timeout: 5000, /* Run tests in files in parallel */ fullyParallel: true, @@ -41,9 +42,7 @@ export default defineConfig({ webServer: { stdout: process.env.CI ? 'pipe' : 'ignore', - command: process.env.CI - ? './AdGuardHome --local-frontend -v' - : 'rm -f AdGuardHome.yaml && sudo ./AdGuardHome --local-frontend -v', + command: process.env.CI ? './AdGuardHome --local-frontend -v' : 'sudo ./AdGuardHome --local-frontend -v', url: 'http://127.0.0.1:3000', cwd: '..', reuseExistingServer: !process.env.CI, diff --git a/client/tests/e2e/globalSetup.ts b/client/tests/e2e/globalSetup.ts index ffd31ac5..4f5564ec 100644 --- a/client/tests/e2e/globalSetup.ts +++ b/client/tests/e2e/globalSetup.ts @@ -1,8 +1,18 @@ import { chromium, FullConfig } from '@playwright/test'; +import { existsSync, renameSync } from 'fs'; +import { join } from 'path'; import { ADMIN_USERNAME, ADMIN_PASSWORD, PORT } from '../constants'; +export const CONFIG_FILE = 'AdGuardHome.yaml'; +export const TEMP_CONFIG_FILE = 'AdGuardHome.yaml.temp'; + async function globalSetup(config: FullConfig) { + // Backup existing config file if it exists + if (existsSync(CONFIG_FILE)) { + renameSync(CONFIG_FILE, TEMP_CONFIG_FILE); + } + const browser = await chromium.launch({ slowMo: 100, }); diff --git a/client/tests/e2e/globalTeardown.ts b/client/tests/e2e/globalTeardown.ts new file mode 100644 index 00000000..38f994e5 --- /dev/null +++ b/client/tests/e2e/globalTeardown.ts @@ -0,0 +1,20 @@ +import { chromium, FullConfig } from '@playwright/test'; + +import { ADMIN_USERNAME, ADMIN_PASSWORD, PORT } from '../constants'; + +import { existsSync, renameSync, unlinkSync } from 'fs'; +import { CONFIG_FILE, TEMP_CONFIG_FILE } from './globalSetup'; + +async function globalTeardown() { + // Remove the test config file + if (existsSync(CONFIG_FILE)) { + unlinkSync(CONFIG_FILE); + } + + // Restore the original config file if it exists + if (existsSync(TEMP_CONFIG_FILE)) { + renameSync(TEMP_CONFIG_FILE, CONFIG_FILE); + } +} + +export default globalTeardown;