-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tests.cjs
More file actions
180 lines (156 loc) · 5.65 KB
/
Copy pathrun-tests.cjs
File metadata and controls
180 lines (156 loc) · 5.65 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
const http = require('http');
const fs = require('fs');
const path = require('path');
const { chromium } = require('playwright');
const ROOT = path.join(__dirname);
const PORT = 9876;
// Simple static file server
const server = http.createServer((req, res) => {
let filePath = path.join(ROOT, decodeURIComponent(req.url));
if (filePath.endsWith('/')) filePath += 'index.html';
const ext = path.extname(filePath);
const mimeTypes = {
'.html': 'text/html',
'.js': 'application/javascript',
'.css': 'text/css',
'.png': 'image/png',
'.svg': 'image/svg+xml',
'.json': 'application/json',
};
fs.readFile(filePath, (err, data) => {
if (err) {
res.writeHead(404);
res.end('Not found');
return;
}
res.writeHead(200, { 'Content-Type': mimeTypes[ext] || 'text/plain' });
res.end(data);
});
});
async function run() {
await new Promise(resolve => server.listen(PORT, resolve));
console.log(`Server started on port ${PORT}`);
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({ viewport: { width: 1400, height: 900 } });
const page = await context.newPage();
// Collect console logs
const consoleLogs = [];
page.on('console', msg => {
const text = msg.text();
consoleLogs.push(text);
if (text.startsWith('TEST_RESULTS_JSON:')) {
// Will be processed after page is done
}
});
// Collect page errors
const pageErrors = [];
page.on('pageerror', err => {
pageErrors.push(err.message);
});
console.log('Loading test suite...');
await page.goto(`http://localhost:${PORT}/tests/test-suite.html?autorun`, {
waitUntil: 'networkidle',
timeout: 30000,
});
// Wait for test results - poll for completion
console.log('Waiting for tests to complete...');
let testResults = null;
const maxWait = 120000; // 2 minutes max
const startTime = Date.now();
while (Date.now() - startTime < maxWait) {
// Check if tests are done by looking for the JSON output
const resultLine = consoleLogs.find(l => l.startsWith('TEST_RESULTS_JSON:'));
if (resultLine) {
testResults = JSON.parse(resultLine.replace('TEST_RESULTS_JSON:', ''));
break;
}
// Also check if the status element shows completion
const statusText = await page.textContent('#status').catch(() => '');
if (statusText && statusText.startsWith('Done')) {
// Give a moment for the console log to arrive
await page.waitForTimeout(500);
const resultLine2 = consoleLogs.find(l => l.startsWith('TEST_RESULTS_JSON:'));
if (resultLine2) {
testResults = JSON.parse(resultLine2.replace('TEST_RESULTS_JSON:', ''));
}
break;
}
// Check for load failure
if (statusText && statusText.startsWith('FAILED')) {
console.error('App failed to load:', statusText);
break;
}
await page.waitForTimeout(1000);
}
// Scrape detailed results from the page
const detailedResults = await page.evaluate(() => {
const groups = document.querySelectorAll('.group');
const results = [];
groups.forEach(group => {
const header = group.querySelector('.group-header h2');
const badge = group.querySelector('.badge');
const tests = [];
group.querySelectorAll('.test-row').forEach(row => {
const name = row.querySelector('.name');
const time = row.querySelector('.time');
const error = row.querySelector('.error');
tests.push({
name: name ? name.childNodes[0].textContent.trim() : 'Unknown',
status: row.classList.contains('pass') ? 'PASS' : row.classList.contains('fail') ? 'FAIL' : 'UNKNOWN',
time: time ? time.textContent.trim() : '',
error: error ? error.textContent.trim() : null,
});
});
results.push({
group: header ? header.textContent.trim() : 'Unknown',
badge: badge ? badge.textContent.trim() : '',
tests,
});
});
return results;
});
// Print results
console.log('\n' + '='.repeat(80));
console.log('CHART STUDIO TEST SUITE RESULTS');
console.log('='.repeat(80));
if (testResults) {
console.log(`\nTimestamp: ${testResults.timestamp}`);
console.log(`Total: ${testResults.total} | Passed: ${testResults.passed} | Failed: ${testResults.failed} | Skipped: ${testResults.skipped}`);
console.log(`Overall: ${testResults.success ? 'SUCCESS ✓' : 'FAILURE ✗'}\n`);
} else {
console.log('\nWARNING: Could not extract JSON test results from console\n');
}
for (const group of detailedResults) {
console.log(`\n--- ${group.group} [${group.badge}] ---`);
for (const test of group.tests) {
const icon = test.status === 'PASS' ? '✓' : test.status === 'FAIL' ? '✗' : '?';
console.log(` ${icon} ${test.name} (${test.time})`);
if (test.error) {
console.log(` ERROR: ${test.error}`);
}
}
}
if (pageErrors.length > 0) {
console.log('\n--- Page Errors ---');
pageErrors.forEach(e => console.log(` ERROR: ${e}`));
}
console.log('\n' + '='.repeat(80));
// Write JSON results to file
const outputPath = path.join(ROOT, 'test-results', 'results.json');
const fullResults = {
summary: testResults || { total: 0, passed: 0, failed: 0, skipped: 0, success: false },
details: detailedResults,
pageErrors,
timestamp: new Date().toISOString(),
};
fs.writeFileSync(outputPath, JSON.stringify(fullResults, null, 2));
console.log(`Results written to ${outputPath}`);
await browser.close();
server.close();
process.exit(testResults && testResults.success ? 0 : 1);
}
run().catch(err => {
console.error('Test runner error:', err);
server.close();
process.exit(1);
});