Skip to content

Commit 66a47a3

Browse files
hackall360claude
andcommitted
fix: convert Playwright config and server to ES modules
Convert playwright.config.js and playwright-server.js to ES modules (.mjs) to fix "require is not defined" errors in GitHub Actions E2E tests. This resolves the blank page issue that was blocking deployment to GitHub Pages. Changes: - playwright.config.js → playwright.config.mjs (ESM with import/export) - playwright-server.js → playwright-server.mjs (ESM) - Updated config to reference new .mjs server file This enables GitHub Actions to successfully complete E2E tests and deploy. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a9f60b4 commit 66a47a3

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

playwright-server.mjs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import http from 'http';
2+
import fs from 'fs';
3+
import path from 'path';
4+
import { fileURLToPath } from 'url';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
const PORT = 4173;
10+
const DIST_DIR = path.join(__dirname, 'dist');
11+
12+
const MIME_TYPES = {
13+
'.html': 'text/html',
14+
'.js': 'application/javascript',
15+
'.css': 'text/css',
16+
'.json': 'application/json',
17+
'.png': 'image/png',
18+
'.jpg': 'image/jpeg',
19+
'.gif': 'image/gif',
20+
'.svg': 'image/svg+xml',
21+
'.ico': 'image/x-icon',
22+
'.txt': 'text/plain'
23+
};
24+
25+
const server = http.createServer((req, res) => {
26+
let filePath = path.join(DIST_DIR, req.url === '/' ? 'index.html' : req.url);
27+
28+
if (!fs.existsSync(filePath) || fs.statSync(filePath).isDirectory()) {
29+
filePath = path.join(DIST_DIR, 'index.html');
30+
}
31+
32+
const ext = path.extname(filePath);
33+
const contentType = MIME_TYPES[ext] || 'application/octet-stream';
34+
35+
fs.readFile(filePath, (err, data) => {
36+
if (err) {
37+
res.writeHead(500);
38+
res.end(`Error: ${err.message}`);
39+
return;
40+
}
41+
42+
res.writeHead(200, { 'Content-Type': contentType });
43+
res.end(data);
44+
});
45+
});
46+
47+
server.listen(PORT, '127.0.0.1', () => {
48+
console.log(`Preview server running at http://127.0.0.1:${PORT}/`);
49+
});
50+
51+
process.on('SIGTERM', () => {
52+
server.close(() => {
53+
console.log('Server stopped');
54+
process.exit(0);
55+
});
56+
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { defineConfig } = require('@playwright/test');
1+
import { defineConfig } from '@playwright/test';
22

3-
module.exports = defineConfig({
3+
export default defineConfig({
44
testDir: './tests',
55
timeout: 60_000,
66
expect: {
@@ -13,7 +13,7 @@ module.exports = defineConfig({
1313
viewport: { width: 1280, height: 720 }
1414
},
1515
webServer: {
16-
command: 'node playwright-server.js',
16+
command: 'node playwright-server.mjs',
1717
port: 4173,
1818
reuseExistingServer: !process.env.CI,
1919
timeout: 120_000

0 commit comments

Comments
 (0)