-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-runner.html
More file actions
160 lines (148 loc) · 4.55 KB
/
test-runner.html
File metadata and controls
160 lines (148 loc) · 4.55 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ClueChain Tests</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
max-width: 900px;
margin: 0 auto;
padding: 20px;
line-height: 1.6;
}
h1 {
text-align: center;
color: #333;
}
.test-container {
border: 1px solid #ccc;
border-radius: 5px;
padding: 20px;
margin-bottom: 20px;
background-color: #f9f9f9;
}
.test-output {
background-color: #f3f3f3;
border: 1px solid #ddd;
border-radius: 4px;
padding: 15px;
font-family: monospace;
white-space: pre-wrap;
max-height: 400px;
overflow-y: auto;
}
.test-controls {
margin-top: 20px;
text-align: center;
}
button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 4px;
}
button:hover {
background-color: #45a049;
}
.test-output .passed {
color: green;
}
.test-output .failed {
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<h1>ClueChain Tests</h1>
<div class="test-container">
<h2>Letter Marketplace Tests</h2>
<div class="test-controls">
<button id="run-letter-tests">Run Letter Marketplace Tests</button>
</div>
<div id="letter-test-output" class="test-output">Test output will appear here...</div>
</div>
<script type="module">
// Capture console.log output to display in the test container
const letterTestOutput = document.getElementById('letter-test-output');
// Override console methods to display in the test output
const originalConsole = {
log: console.log,
error: console.error,
warn: console.warn
};
function redirectConsole(outputElement) {
console.log = function(...args) {
originalConsole.log(...args);
const line = args.map(arg =>
typeof arg === 'object' ? JSON.stringify(arg, null, 2) : arg
).join(' ');
const div = document.createElement('div');
if (line.includes('PASSED:')) {
div.className = 'passed';
} else if (line.includes('FAILED:')) {
div.className = 'failed';
}
div.textContent = line;
outputElement.appendChild(div);
outputElement.scrollTop = outputElement.scrollHeight;
};
console.error = function(...args) {
originalConsole.error(...args);
const line = args.map(arg =>
typeof arg === 'object' ? JSON.stringify(arg, null, 2) : arg
).join(' ');
const div = document.createElement('div');
div.className = 'failed';
div.textContent = line;
outputElement.appendChild(div);
outputElement.scrollTop = outputElement.scrollHeight;
};
console.warn = function(...args) {
originalConsole.warn(...args);
const line = args.map(arg =>
typeof arg === 'object' ? JSON.stringify(arg, null, 2) : arg
).join(' ');
const div = document.createElement('div');
div.style.color = 'orange';
div.textContent = line;
outputElement.appendChild(div);
outputElement.scrollTop = outputElement.scrollHeight;
};
}
function resetConsole() {
console.log = originalConsole.log;
console.error = originalConsole.error;
console.warn = originalConsole.warn;
}
// Set up letter marketplace tests
document.getElementById('run-letter-tests').addEventListener('click', async () => {
letterTestOutput.innerHTML = 'Running tests...\n';
redirectConsole(letterTestOutput);
try {
// Dynamic import of the test module
try {
const module = await import('./js/tests/letter-marketplace.test.js?v=' + Date.now());
// Tests automatically run when the module is imported
} catch (err) {
console.error('Module import error:', err.message);
console.error('Stack trace:', err.stack);
}
} catch (error) {
console.error('Error running tests:', error);
} finally {
resetConsole();
}
});
</script>
</body>
</html>