mirror of
https://github.com/OpenBankProject/API-Explorer-II.git
synced 2026-02-06 10:47:04 +00:00
teardown express server after tests
This commit is contained in:
parent
4275e6879d
commit
64fc4566c2
4
.gitignore
vendored
4
.gitignore
vendored
@ -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/
|
||||
@ -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',
|
||||
|
||||
@ -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}`);
|
||||
|
||||
15
src/test/integration/global.teardown.ts
Normal file
15
src/test/integration/global.teardown.ts
Normal file
@ -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
|
||||
@ -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('/');
|
||||
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
12
src/test/integration/server-manager.ts
Normal file
12
src/test/integration/server-manager.ts
Normal file
@ -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;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user