diff --git a/.gitignore b/.gitignore index 13e57da..621ee63 100644 --- a/.gitignore +++ b/.gitignore @@ -50,7 +50,9 @@ public_key.pem __snapshots__/ # Playwright auth -*.playwright/.auth +src/test/integration/playwright/.auth +src/test/integration/playwright/.auth/ +**/playwright/.auth/ test-results/ playwright-report/ playwright-coverage/ \ No newline at end of file diff --git a/playwright.config.ts b/playwright.config.ts index f9dbf25..55dad0b 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -10,6 +10,8 @@ export default defineConfig({ testDir: 'src/test/integration', globalSetup: require.resolve('./src/test/integration/global.setup.ts'), + + globalTeardown: require.resolve('./src/test/integration/global.teardown.ts'), // Reporter to use reporter: 'html', @@ -24,7 +26,12 @@ export default defineConfig({ projects: [ { name: 'setup', - testMatch: /.*\.setup\.ts/ + testMatch: /.*\.setup\.ts/, + teardown: 'teardown', + }, + { + name: 'teardown', + testMatch: /.*\.teardown\.ts/ }, { name: 'chromium', diff --git a/src/test/integration/global.setup.ts b/src/test/integration/global.setup.ts index 8f7c41e..9781a5c 100644 --- a/src/test/integration/global.setup.ts +++ b/src/test/integration/global.setup.ts @@ -1,6 +1,7 @@ import { spawn, ChildProcess } from 'child_process'; import type { FullConfig } from '@playwright/test'; +import { setExpressServer } from './server-manager'; // Ports for our test servers const EXPRESS_PORT = 8085; @@ -9,8 +10,7 @@ export const servers = { expressUrl: `http://localhost:${EXPRESS_PORT}`, } -let expressServer: ChildProcess; - +export let expressServer: ChildProcess; /** * Starts the Express server before running tests @@ -26,6 +26,9 @@ async function globalSetup(config: FullConfig) { env: { ...process.env, PORT: EXPRESS_PORT.toString() } }); + // Store in shared manager + setExpressServer(expressServer); + // Log server output for debugging expressServer.stdout?.on('data', (data) => { console.log(`Express server: ${data}`); diff --git a/src/test/integration/global.teardown.ts b/src/test/integration/global.teardown.ts new file mode 100644 index 0000000..4608f69 --- /dev/null +++ b/src/test/integration/global.teardown.ts @@ -0,0 +1,15 @@ +import { getExpressServer } from './server-manager' + +async function globalTeardown() { + + console.log('Tearing down global setup...') + + const expressServer = getExpressServer() + // Kill the express server + if (expressServer) { + expressServer.kill('SIGTERM') + console.log('Express server killed') + } +} + +export default globalTeardown \ No newline at end of file diff --git a/src/test/integration/opey.integration.test.ts b/src/test/integration/opey.integration.test.ts index c74330b..63e9930 100644 --- a/src/test/integration/opey.integration.test.ts +++ b/src/test/integration/opey.integration.test.ts @@ -1,9 +1,21 @@ import { describe,beforeAll, beforeEach, afterAll, afterEach } from 'vitest'; -import { useIntegrationTestHooks } from './global.setup'; import { chromium, Browser, Page, BrowserContext } from 'playwright'; import {test, expect} from '@playwright/test'; test.describe('Opey Integration Tests in API Explorer', () => { - + + test.beforeAll(async ({ page }) => { + // Open the chat widget + await page.goto('/'); + const chatButton = await page.waitForSelector('.chat-widget-button'); + await chatButton.click(); + + }) + + test('Opey is running', async ({ page }) => { + await page.goto('/'); + + + }) }) \ No newline at end of file diff --git a/src/test/integration/server-manager.ts b/src/test/integration/server-manager.ts new file mode 100644 index 0000000..ea070a4 --- /dev/null +++ b/src/test/integration/server-manager.ts @@ -0,0 +1,12 @@ +import { ChildProcess } from 'child_process'; + +// Global state to store server instance +let expressServerProcess: ChildProcess | null = null; + +export function setExpressServer(server: ChildProcess): void { + expressServerProcess = server; +} + +export function getExpressServer(): ChildProcess | null { + return expressServerProcess; +} \ No newline at end of file