-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-loading.mjs
More file actions
153 lines (131 loc) · 4.7 KB
/
Copy pathtest-loading.mjs
File metadata and controls
153 lines (131 loc) · 4.7 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
import { chromium } from 'playwright';
const browser = await chromium.launch({
headless: true,
args: ['--enable-features=SharedArrayBuffer']
});
// Create a fresh context to avoid cached data
const context = await browser.newContext({
// Clear storage to force fresh download
storageState: undefined
});
const page = await context.newPage();
// Clear IndexedDB to force fresh model download
await page.addInitScript(() => {
indexedDB.deleteDatabase('transformers-cache');
});
// Collect ALL console messages
page.on('console', msg => {
const text = msg.text();
console.log('[CONSOLE ' + msg.type() + '] ' + text);
});
// Catch page errors
page.on('pageerror', error => {
console.log('[PAGE ERROR] ' + error.message);
});
// Catch request failures
page.on('requestfailed', request => {
console.log('[REQUEST FAILED] ' + request.url() + ' - ' + request.failure().errorText);
});
// Monitor network requests
page.on('request', request => {
const url = request.url();
if (url.includes('huggingface') || url.includes('onnx') || url.includes('MiniLM')) {
console.log('[REQUEST] ' + request.method() + ' ' + url);
}
});
page.on('response', response => {
const url = response.url();
if (url.includes('huggingface') || url.includes('onnx') || url.includes('MiniLM')) {
console.log('[RESPONSE] ' + response.status() + ' ' + url + ' (' + (response.headers()['content-length'] || 'unknown') + ' bytes)');
}
});
console.log('Navigating to app (with fresh cache)...');
await page.goto('http://localhost:5175/', { waitUntil: 'domcontentloaded', timeout: 60000 });
const captureLoadingOnly = process.env.CAPTURE_LOADING === '1';
if (captureLoadingOnly) {
await page.waitForTimeout(1000);
const screenshotPath = process.env.SCREENSHOT_PATH || '/tmp/loading-screenshot.png';
await page.screenshot({ path: screenshotPath, fullPage: true });
console.log(`Screenshot saved to ${screenshotPath}`);
await browser.close();
process.exit(0);
}
// Wait for loading to complete or timeout
console.log('Waiting for model to load (max 120s)...');
const startTime = Date.now();
let lastProgress = '';
while (Date.now() - startTime < 120000) {
try {
// Check if ConfigPanel is visible (means loading is done)
const configPanel = await page.locator('[data-testid="config-panel"]').isVisible();
if (configPanel) {
console.log('SUCCESS: Loading complete! ConfigPanel is visible.');
break;
}
// Get current progress
const progressBar = await page.locator('[role="progressbar"]').textContent();
const elapsed = await page.locator('[data-testid="elapsed-timer"]').textContent();
if (progressBar !== lastProgress) {
console.log('UI Progress: ' + progressBar + ' ' + elapsed);
lastProgress = progressBar;
}
} catch (e) {
// Ignore selector errors
}
await page.waitForTimeout(1000);
}
const elapsed = Math.round((Date.now() - startTime) / 1000);
console.log('Test finished after ' + elapsed + 's');
const screenshotPath = process.env.SCREENSHOT_PATH || '/tmp/loading-screenshot.png';
const shouldStartSimulation =
process.env.SIM_START === '1' ||
Boolean(process.env.TARGET_CHAPTER) ||
Boolean(process.env.STEP_FORWARD) ||
process.env.HOVER_VECTOR === '1';
if (shouldStartSimulation) {
const beginButton = page.locator('[data-testid="begin-simulation"]');
if (await beginButton.isVisible()) {
await beginButton.click();
await page.waitForTimeout(500);
}
}
if (process.env.TARGET_CHAPTER) {
const chapterIndex = Number.parseInt(process.env.TARGET_CHAPTER, 10);
if (Number.isFinite(chapterIndex)) {
const marker = page.locator(`[data-testid="chapter-marker-${chapterIndex}"]`);
if (await marker.isVisible()) {
await marker.click();
await page.waitForTimeout(400);
}
}
}
if (process.env.STEP_FORWARD) {
const stepCount = Number.parseInt(process.env.STEP_FORWARD, 10);
if (Number.isFinite(stepCount)) {
const nextButton = page.getByRole('button', { name: /next/i });
for (let i = 0; i < stepCount; i += 1) {
if (await nextButton.isVisible()) {
await nextButton.click();
await page.waitForTimeout(300);
}
}
}
}
if (process.env.HOVER_VECTOR === '1') {
const candidate = page.locator('[data-testid="vector-space-candidate"]').first();
if (await candidate.isVisible()) {
await candidate.hover();
await page.waitForTimeout(300);
}
}
if (process.env.OPEN_CRT_CONTROLS === '1') {
const handle = page.locator('[data-testid="crt-controls-handle"]');
if (await handle.isVisible()) {
await handle.click();
await page.waitForTimeout(600);
}
}
// Take screenshot
await page.screenshot({ path: screenshotPath, fullPage: true });
console.log(`Screenshot saved to ${screenshotPath}`);
await browser.close();