Implement Core Performance Testing Engine (Phase 1 & 2)

- Added Lighthouse and Chrome Launcher dependencies
- Created lib/runner.js test runner service
- Implemented filesystem storage for test results
- Added API endpoints: POST /api/run-test and GET /api/history
This commit is contained in:
2025-12-27 22:18:41 +11:00
parent 26165461fd
commit 264325112e
4 changed files with 3900 additions and 3 deletions

View File

@@ -2,14 +2,17 @@ const express = require("express");
const path = require("path");
const fs = require("fs");
const { exec } = require("child_process");
const runner = require("./lib/runner");
const app = express();
const PORT = process.env.PORT || 3000;
// Serve static files
// Middleware
app.use(express.json());
app.use(express.static(__dirname));
app.use('/reports', express.static(path.join(__dirname, 'reports')));
// API endpoint to get Git commit info
// API Endpoint: Git Info
app.get("/api/git-info", (req, res) => {
exec('git log -1 --format="%H|%cr"', (error, stdout, stderr) => {
if (error) {
@@ -30,6 +33,26 @@ app.get("/api/git-info", (req, res) => {
});
});
// API Endpoint: Run Test
app.post("/api/run-test", async (req, res) => {
const { url, isMobile } = req.body;
if (!url) return res.status(400).json({ error: "URL is required" });
try {
const result = await runner.runTest(url, { isMobile });
res.json(result);
} catch (error) {
console.error("Test failed:", error);
res.status(500).json({ error: "Test failed", details: error.message });
}
});
// API Endpoint: History
app.get("/api/history", (req, res) => {
const history = runner.getHistory();
res.json(history);
});
// Serve index.html for all other routes
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "index.html"));