-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathtest_app.sh
More file actions
executable file
·86 lines (71 loc) · 2.79 KB
/
test_app.sh
File metadata and controls
executable file
·86 lines (71 loc) · 2.79 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
set -e
echo "Building the app..."
npm run build
echo "Checking for processes on port 3000 and killing them if found..."
# Kill any process listening on port 3000
lsof -ti tcp:3000 | xargs kill -9 || true
echo "Starting the app in the background..."
npm start &
APP_PID=$!
echo "App started with PID: $APP_PID"
echo "Waiting for the app to boot (max 30 seconds)..."
TIMEOUT=30
INTERVAL=2
ELAPSED=0
while ! nc -z localhost 3000; do
if [ $ELAPSED -ge $TIMEOUT ]; then
echo "App did not start within $TIMEOUT seconds. Exiting."
kill $APP_PID || true # Attempt to kill even if it's already gone
exit 1
fi
sleep $INTERVAL
ELAPSED=$((ELAPSED + INTERVAL))
echo "Waiting... ($ELAPSED/$TIMEOUT s)"
done
echo "App is running on http://localhost:3000"
echo "Running Lighthouse audit..."
npx lighthouse http://localhost:3000 --quiet --chrome-flags="--headless" --output=json --output-path=./lighthouse-report.json
echo "Killing the background app (PID: $APP_PID)..."
kill $APP_PID || true # Use || true to prevent script from exiting if process is already gone
echo "Parsing Lighthouse report..."
node -e '
const fs = require("fs");
const reportPath = "./lighthouse-report.json";
try {
const report = JSON.parse(fs.readFileSync(reportPath, "utf8"));
const getScore = (category) => (report.categories[category] ? Math.round(report.categories[category].score * 100) : "N/A");
const getMetric = (audit) => (report.audits[audit] ? report.audits[audit].displayValue : "N/A");
const performanceScore = getScore("performance");
const accessibilityScore = getScore("accessibility");
const bestPracticesScore = getScore("best-practices");
const seoScore = getScore("seo");
const fcp = getMetric("first-contentful-paint");
const tti = getMetric("interactive");
let failedAudits = [];
for (const auditKey in report.audits) {
const audit = report.audits[auditKey];
// Consider an audit "failed" if its score is less than 1 (100%) and not null
if (audit.score !== null && audit.score < 1) {
failedAudits.push(`${audit.title} (Score: ${Math.round(audit.score * 100)}%)`);
}
}
console.log("\n--- Lighthouse Audit Summary ---");
console.log(`Performance: ${performanceScore}`);
console.log(`Accessibility: ${accessibilityScore}`);
console.log(`Best Practices: ${bestPracticesScore}`);
console.log(`SEO: ${seoScore}`);
console.log(`First Contentful Paint: ${fcp}`);
console.log(`Time to Interactive: ${tti}`);
if (failedAudits.length > 0) {
console.log("\nFailed Audits:");
failedAudits.forEach(audit => console.log(`- ${audit}`));
} else {
console.log("\nNo failed audits found. Great job!");
}
console.log("------------------------------\n");
} catch (error) {
console.error(`Error parsing Lighthouse report: ${error.message}`);
process.exit(1);
}
'