import * as path from 'path'; import { pathToFileURL } from 'url'; import { test } from '../../../playwright'; import { setSandboxMode, runCollection, validateRunnerResults, waitForReadyPage } from '../../utils/page'; import { startServers, stopServers, PAC_PORT, type TestServers } from './server'; test.describe.serial('PAC Proxy', () => { let servers: TestServers; test.beforeAll(async () => { servers = await startServers(); }); test.afterAll(async () => { if (servers) { await stopServers(servers); } }); /** * Verifies end-to-end PAC proxy resolution: * * - The PAC file routes /proxied paths to the local test proxy (port 18888). * - The local test proxy injects `x-proxied: test-proxy` into every response. * - /direct paths are returned DIRECT — no proxy header added. * * Both assertions live inside the collection's `tests {}` blocks, so * validateRunnerResults confirms the full flow passed. */ test('routes requests per PAC directive (PROXY and DIRECT) via HTTP URL', async ({ launchElectronApp }) => { const pacUrl = `http://localhost:${PAC_PORT}/test.pac`; const initUserDataPath = path.join(__dirname, 'init-user-data'); const app = await launchElectronApp({ initUserDataPath, templateVars: { pacUrl } }); const page = await waitForReadyPage(app); await setSandboxMode(page, 'pac-proxy-test', 'developer'); await runCollection(page, 'pac-proxy-test'); await validateRunnerResults(page, { totalRequests: 2, passed: 2, failed: 0, skipped: 0 }); }); test('routes requests via file:// PAC URL', async ({ launchElectronApp }) => { // Compute the file:// URL at runtime so it is correct on every OS: // Mac/Linux → file:///abs/path/to/test.pac // Windows → file:///C:/abs/path/to/test.pac const pacUrl = pathToFileURL(path.join(__dirname, 'fixtures', 'pac-files', 'test.pac')).href; const initUserDataPath = path.join(__dirname, 'init-user-data'); const app = await launchElectronApp({ initUserDataPath, templateVars: { pacUrl } }); const page = await waitForReadyPage(app); await setSandboxMode(page, 'pac-proxy-test', 'developer'); await runCollection(page, 'pac-proxy-test'); await validateRunnerResults(page, { totalRequests: 2, passed: 2, failed: 0, skipped: 0 }); }); });