-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathe2e.ts
47 lines (41 loc) · 1.2 KB
/
e2e.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { chromium } from '@playwright/test';
import { exec } from 'child_process';
import http from 'http';
import path from 'path';
import handler from 'serve-handler';
import { promisify } from 'util';
const execAsync = promisify(exec);
async function runE2E() {
console.log('Building example project...');
await execAsync('pnpm run build', {
cwd: path.join(process.cwd(), 'examples/normal'),
});
const server = http.createServer((req, res) => {
handler(req, res, {
public: path.join(process.cwd(), 'examples/normal/dist'),
});
});
const port = 3000;
server.listen(port);
console.log(`Server running at http://localhost:${port}`);
try {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto(`http://localhost:${port}`);
const content = await page.textContent('body');
if (!content) {
throw new Error('Page content not found');
}
console.log('E2E tests passed!');
process.exit(0);
} catch (error) {
console.error('E2E tests failed:', error);
process.exit(1);
} finally {
server.close();
}
}
runE2E().catch((error) => {
console.error('E2E test script failed:', error);
process.exit(1);
});