Skip to content

Commit

Permalink
chore(ui): merge playwright configs into single config file (#496)
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanHoladay authored Nov 4, 2024
1 parent 6ae1097 commit 82a20d0
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 80 deletions.
8 changes: 4 additions & 4 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
21 changes: 0 additions & 21 deletions ui/playwright.config.in-cluster.ts

This file was deleted.

21 changes: 0 additions & 21 deletions ui/playwright.config.local-auth.ts

This file was deleted.

69 changes: 66 additions & 3 deletions ui/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -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}`,
Expand All @@ -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 }
31 changes: 0 additions & 31 deletions ui/playwright.reconnect.config.ts

This file was deleted.

0 comments on commit 82a20d0

Please sign in to comment.