diff --git a/ui/package.json b/ui/package.json index d9b12888..7a1e1977 100644 --- a/ui/package.json +++ b/ui/package.json @@ -12,10 +12,10 @@ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "lint": "prettier --check . && eslint .", "format": "prettier --write .", - "test:local-auth": "playwright test tests/local-auth.spec.ts --config=playwright.config.local-auth.ts", - "test:reconnect": "playwright test tests/reconnect.spec.ts --config=playwright.reconnect.config.ts", - "test:e2e": "playwright test", - "test:e2e-in-cluster": "playwright test --config=playwright.config.in-cluster.ts", + "test:local-auth": "TEST_CFG=localAuth playwright test", + "test:reconnect": "TEST_CFG=reconnect playwright test", + "test:e2e": "TEST_CFG=default playwright test", + "test:e2e-in-cluster": "TEST_CFG=inCluster playwright test", "test:install": "playwright install", "test:unit": "vitest run" }, diff --git a/ui/playwright.config.in-cluster.ts b/ui/playwright.config.in-cluster.ts deleted file mode 100644 index d325d000..00000000 --- a/ui/playwright.config.in-cluster.ts +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2024 Defense Unicorns -// SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial - -import { defineConfig } from '@playwright/test' - -const protocol = 'https' -const host = 'runtime.admin.uds.dev' - -export default defineConfig({ - globalSetup: './tests/global-setup', - timeout: 10 * 1000, - testDir: 'tests', - /* Run tests in files in parallel */ - fullyParallel: true, - retries: process.env.CI ? 2 : 1, - testMatch: /^(?!.*local-auth|.*reconnect)(.+\.)?(test|spec)\.[jt]s$/, - use: { - baseURL: `${protocol}://${host}/`, - storageState: './tests/state.json', - }, -}) diff --git a/ui/playwright.config.local-auth.ts b/ui/playwright.config.local-auth.ts deleted file mode 100644 index 663d378c..00000000 --- a/ui/playwright.config.local-auth.ts +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2024 Defense Unicorns -// SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial - -import { defineConfig } from '@playwright/test' -import { loadEnv } from 'vite' - -const { VITE_PORT_ENV } = loadEnv('dev', process.cwd()) -const port = VITE_PORT_ENV ?? '8443' - -export default defineConfig({ - timeout: 60 * 1000, - testDir: 'tests', - fullyParallel: false, - retries: process.env.CI ? 2 : 1, - testMatch: /^(?!.*in-cluster|.*reconnect)(.+\.)?(test|spec)\.[jt]s$/, - use: { - baseURL: `https://runtime-local.uds.dev:${port}/`, - }, -}) - -export { port } diff --git a/ui/playwright.config.ts b/ui/playwright.config.ts index 4cb96c42..0fbab79b 100644 --- a/ui/playwright.config.ts +++ b/ui/playwright.config.ts @@ -1,17 +1,22 @@ // Copyright 2024 Defense Unicorns // SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial -import { defineConfig } from '@playwright/test' +import { defineConfig, PlaywrightTestConfig } from '@playwright/test' import { loadEnv } from 'vite' const { VITE_PORT_ENV } = loadEnv('dev', process.cwd()) +type TestConfig = keyof typeof configs +const TEST_CONFIG: TestConfig = (process.env.TEST_CFG as TestConfig) || 'default' + // use port 8443 because by default we use TLS when running locally const port = VITE_PORT_ENV ?? '8443' const protocol = 'https' const host = 'runtime-local.uds.dev' -export default defineConfig({ +// For all default E2E tests +const defaultConfig: PlaywrightTestConfig = { + name: 'default', webServer: { command: '../build/uds-runtime', url: `${protocol}://${host}:${port}`, @@ -27,6 +32,64 @@ export default defineConfig({ use: { baseURL: `${protocol}://${host}:${port}/`, }, -}) +} + +// For testing reconnecting to the cluster +const reconnect: PlaywrightTestConfig = { + name: 'reconnect', + webServer: { + command: '../build/uds-runtime', + url: `${protocol}://${host}:${port}`, + reuseExistingServer: !process.env.CI, + env: { LOCAL_AUTH_ENABLED: 'false' }, + }, + timeout: 10 * 1000, + testDir: 'tests', + fullyParallel: false, + retries: process.env.CI ? 2 : 1, + testMatch: 'reconnect.spec.ts', + use: { + baseURL: `https://runtime-local.uds.dev:${port}/`, + }, +} + +// For testing local auth only +const localAuth: PlaywrightTestConfig = { + name: 'local-auth', + timeout: 60 * 1000, + testDir: 'tests', + fullyParallel: false, + retries: process.env.CI ? 2 : 1, + testMatch: 'local-auth.spec.ts', + use: { + baseURL: `https://runtime-local.uds.dev:${port}/`, + }, +} + +// For running E2E tests against Runtime in-cluster +const inCluster: PlaywrightTestConfig = { + name: 'in-cluster', + globalSetup: './tests/global-setup', + timeout: 10 * 1000, + testDir: 'tests', + /* Run tests in files in parallel */ + fullyParallel: true, + retries: process.env.CI ? 2 : 1, + testMatch: /^(?!.*local-auth|.*reconnect)(.+\.)?(test|spec)\.[jt]s$/, + use: { + baseURL: `${protocol}://runtime.admin.uds.dev/`, + storageState: './tests/state.json', + }, +} + +// Use configs object for selecting desired config based on TEST_CONFIG, which is set by caller script in package.json +const configs = { + default: defaultConfig, + localAuth, + inCluster, + reconnect, +} + +export default defineConfig({ ...configs[TEST_CONFIG] }) export { port } diff --git a/ui/playwright.reconnect.config.ts b/ui/playwright.reconnect.config.ts deleted file mode 100644 index bd5ca976..00000000 --- a/ui/playwright.reconnect.config.ts +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2024 Defense Unicorns -// SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial - -import { defineConfig } from '@playwright/test' -import { loadEnv } from 'vite' - -const { VITE_PORT_ENV } = loadEnv('dev', process.cwd()) - -// use port 8443 because by default we use TLS when running locally -const port = VITE_PORT_ENV ?? '8443' -const protocol = 'https' -const host = 'runtime-local.uds.dev' - -export default defineConfig({ - webServer: { - command: '../build/uds-runtime', - url: `${protocol}://${host}:${port}`, - reuseExistingServer: !process.env.CI, - env: { LOCAL_AUTH_ENABLED: 'false' }, - }, - timeout: 10 * 1000, - testDir: 'tests', - fullyParallel: false, - retries: process.env.CI ? 2 : 1, - testMatch: 'reconnect.spec.ts', - use: { - baseURL: `https://runtime-local.uds.dev:${port}/`, - }, -}) - -export { port }