Add global api reachable check (#1404)

This commit is contained in:
Leendert de Borst
2025-12-10 17:55:13 +01:00
parent 2f01de47cf
commit 0687dbcf00
4 changed files with 74 additions and 14 deletions

View File

@@ -70,6 +70,11 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Setup Node.js
uses: actions/setup-node@v4
with:
@@ -77,7 +82,40 @@ jobs:
cache: 'npm'
cache-dependency-path: apps/browser-extension/package-lock.json
- name: Install dependencies
- name: Install .NET dependencies
working-directory: apps/server
run: dotnet workload install wasm-tools
- name: Build API server
working-directory: apps/server
run: dotnet build AliasVault.Api
- name: Start dev database
run: ./install.sh configure-dev-db start
- name: Start API server
working-directory: apps/server/AliasVault.Api
run: |
dotnet run --no-build &
# Wait for API to be ready
echo "Waiting for API to start..."
for i in {1..30}; do
if curl -s http://localhost:5092/v1/Auth/status > /dev/null 2>&1; then
echo "API is ready!"
break
fi
echo "Attempt $i: API not ready yet..."
sleep 2
done
env:
ConnectionStrings__AliasServerDbContext: "Host=localhost;Port=5433;Database=aliasdb_e2e_extension;Username=aliasvault;Password=password"
JWT_KEY: "12345678901234567890123456789012"
DATA_PROTECTION_CERT_PASS: "Development"
PUBLIC_REGISTRATION_ENABLED: "true"
ADMIN_PASSWORD_HASH: "AQAAAAIAAYagAAAAEKWfKfa2gh9Z72vjAlnNP1xlME7FsunRznzyrfqFte40FToufRwa3kX8wwDwnEXZag=="
ADMIN_PASSWORD_GENERATED: "2024-01-01T00:00:00Z"
- name: Install browser extension dependencies
run: npm ci
working-directory: apps/browser-extension
@@ -88,6 +126,8 @@ jobs:
- name: Build and run E2E tests
run: xvfb-run --auto-servernum npm run test:e2e:build
working-directory: apps/browser-extension
env:
ALIASVAULT_API_URL: "http://localhost:5092"
- name: Upload Playwright report
if: always()

View File

@@ -14,6 +14,9 @@ import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests/e2e',
// Global setup to check API availability before tests
globalSetup: './tests/global-setup.ts',
// Global teardown to clean up browser contexts
globalTeardown: './tests/global-teardown.ts',

View File

@@ -2,7 +2,7 @@ import { test as base, chromium, type BrowserContext, type Page } from '@playwri
import path from 'path';
import { fileURLToPath } from 'url';
import { createTestUser, isApiAvailable, type TestUser } from '../helpers/test-api';
import { createTestUser, type TestUser } from '../helpers/test-api';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@@ -100,18 +100,7 @@ export const test = base.extend<TestFixtures>({
},
testUser: async ({ apiUrl }, use) => {
// Check if the API is available
const apiAvailable = await isApiAvailable(apiUrl);
if (!apiAvailable) {
console.warn(`API not available at ${apiUrl}. Tests requiring authentication will fail.`);
// Return a placeholder user - tests should handle this gracefully
await use({
username: 'api_unavailable',
password: 'api_unavailable',
});
return;
}
// API availability is checked in global setup
// Create a test user for this test run
const testUser = await createTestUser(apiUrl);
await use(testUser);

View File

@@ -0,0 +1,28 @@
/**
* Global setup for E2E tests.
*
* Runs before any tests to ensure prerequisites are met.
*/
import { isApiAvailable } from './helpers/test-api';
/**
* Default API URL for local development.
*/
const DEFAULT_API_URL = process.env.ALIASVAULT_API_URL || 'http://localhost:5092';
export default async function globalSetup(): Promise<void> {
console.log(`Checking API availability at ${DEFAULT_API_URL}...`);
const apiAvailable = await isApiAvailable(DEFAULT_API_URL);
if (!apiAvailable) {
throw new Error(
`API is not available at ${DEFAULT_API_URL}. ` +
'Please ensure the AliasVault API server is running before running E2E tests. ' +
'You can set a custom API URL via the ALIASVAULT_API_URL environment variable.'
);
}
console.log('API is available. Proceeding with tests...');
}