super-productivity/e2e/global-setup.ts
Johannes Millan 6394fa4363
Claude/fix failing e2e tests ov lxs (#6721)
* test(e2e): fix SuperSync encryption overlay and plugin build in CI

Two root causes for failing e2e tests:

1. Plugin build failure in global-setup.ts: The plugin manifest check
   only looked at the dev path (src/assets/bundled-plugins/) but not the
   CI pre-built path (.tmp/angular-dist/browser/assets/bundled-plugins/).
   In CI, the frontend is pre-built and downloaded as an artifact, so the
   dev path doesn't exist. This caused all WebDAV tests to fail.

2. SuperSync enableEncryption overlay blocking: The sync wrapper opens
   a mandatory encryption dialog with disableClose:true after a successful
   sync when encryption is not yet configured. ensureOverlaysClosed()
   uses Escape key which cannot dismiss disableClose dialogs.

   Fixes:
   - Add enableEncryptionDialog to the sync outcome race so the mandatory
     dialog is detected immediately instead of waiting for a 30s timeout
   - enableEncryption() now checks if the dialog is already open and
     handles it directly instead of trying to right-click the sync button
   - Extract _fillAndConfirmEncryptionDialog() and
     _waitForEncryptionSyncComplete() helpers for reuse
   - Improve enable encryption button lookup to check both top-level
     (SuperSync) and Advanced collapsible positions

https://claude.ai/code/session_01CnQXCAB3WYnYdKPbNEqUS3

* chore: update package-lock.json after npm install

Regenerated lock file to resolve workspace dependencies including
vite-plugin's devDependencies (@types/node, vite, typescript).

https://claude.ai/code/session_01CnQXCAB3WYnYdKPbNEqUS3

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-04 00:59:02 +01:00

74 lines
2.6 KiB
TypeScript

import { FullConfig } from '@playwright/test';
import { execSync } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
/**
* Warm up the dev server by fetching the app once before any tests start.
* This ensures Angular compilation is complete and cached, so all workers
* get instant responses instead of competing for the first compilation.
*/
const warmUpDevServer = async (baseURL: string): Promise<void> => {
console.log(`Warming up dev server at ${baseURL}...`);
const maxRetries = 3;
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
const response = await fetch(baseURL, { signal: AbortSignal.timeout(30000) });
if (response.ok) {
// Read the full body to ensure the server finishes compilation
await response.text();
console.log('Dev server warm-up complete');
return;
}
} catch {
if (attempt < maxRetries - 1) {
console.log(`Warm-up attempt ${attempt + 1} failed, retrying...`);
await new Promise((r) => setTimeout(r, 2000));
}
}
}
console.warn('Dev server warm-up failed — tests may be slow on first run');
};
const globalSetup = async (config: FullConfig): Promise<void> => {
// Set test environment variables
process.env.TZ = 'Europe/Berlin';
process.env.NODE_ENV = 'test';
console.log(`Running tests with ${config.workers} workers`);
// Build plugins before starting tests (skip if already built)
// Check both the dev path (src/assets/) and the CI pre-built path (.tmp/angular-dist/)
const pluginManifestPath = path.join(
process.cwd(),
'src/assets/bundled-plugins/api-test-plugin/manifest.json',
);
const ciBuildManifestPath = path.join(
process.cwd(),
'.tmp/angular-dist/browser/assets/bundled-plugins/api-test-plugin/manifest.json',
);
if (fs.existsSync(pluginManifestPath) || fs.existsSync(ciBuildManifestPath)) {
console.log('Plugins already built, skipping...');
} else {
console.log('Building bundled plugins...');
try {
execSync('npm run plugins:build', {
stdio: 'inherit',
cwd: process.cwd(),
});
console.log('Bundled plugins built successfully');
} catch (error) {
console.error('Failed to build plugins:', error);
throw error; // Fail fast if plugin build fails
}
}
// Warm up the dev server to pre-compile Angular bundles before workers start
const baseURL =
process.env.E2E_BASE_URL ||
config.projects[0]?.use?.baseURL ||
'http://localhost:4242';
await warmUpDevServer(baseURL);
};
export default globalSetup;