-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime-test.html
More file actions
193 lines (163 loc) · 5.49 KB
/
runtime-test.html
File metadata and controls
193 lines (163 loc) · 5.49 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
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SDK Kit - Browser Runtime Test</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 800px;
margin: 40px auto;
padding: 20px;
background: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
margin-top: 0;
}
.test {
padding: 12px;
margin: 10px 0;
border-radius: 4px;
font-family: 'Monaco', 'Courier New', monospace;
font-size: 14px;
}
.pass {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.fail {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.info {
background: #d1ecf1;
color: #0c5460;
border: 1px solid #bee5eb;
}
.summary {
margin-top: 20px;
padding: 20px;
background: #e9ecef;
border-radius: 4px;
font-weight: bold;
}
#output {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>🧪 SDK Kit - Browser Runtime Test</h1>
<div class="info">Testing Core SDK in browser environment...</div>
<div id="output"></div>
</div>
<script type="module">
// Import the SDK from the built package
import { SDK } from '../../packages/core/dist/index.js';
const output = document.getElementById('output');
const results = [];
function log(message, type = 'info') {
const div = document.createElement('div');
div.className = `test ${type}`;
div.textContent = message;
output.appendChild(div);
}
function test(name, fn) {
try {
fn();
results.push({ name, status: 'pass' });
log(`✅ PASS: ${name}`, 'pass');
} catch (error) {
results.push({ name, status: 'fail', error: error.message });
log(`❌ FAIL: ${name} - ${error.message}`, 'fail');
}
}
// Create test plugin
function browserPlugin(plugin, instance, config) {
plugin.ns('browser');
plugin.defaults({
browser: { feature: 'test' }
});
plugin.expose({
getFeature() {
return config.get('browser.feature');
},
testEmit(data) {
plugin.emit('browser:test', data);
}
});
instance.on('sdk:ready', () => {
log('📦 Browser plugin initialized', 'info');
});
}
// Run tests
log('Starting browser runtime tests...', 'info');
test('SDK Creation', () => {
const sdk = new SDK();
if (!(sdk instanceof SDK)) throw new Error('SDK not created');
});
test('Plugin Registration', () => {
const sdk = new SDK();
sdk.use(browserPlugin);
});
let sdk;
test('SDK Initialization', () => {
sdk = new SDK({ browser: { feature: 'enabled' } });
sdk.use(browserPlugin);
sdk.init();
});
test('Configuration', () => {
const feature = sdk.getFeature();
if (feature !== 'enabled') {
throw new Error(`Expected 'enabled', got '${feature}'`);
}
});
test('Event Handling', () => {
let eventReceived = false;
sdk.on('browser:test', (_data) => {
eventReceived = true;
});
sdk.testEmit({ test: true });
if (!eventReceived) throw new Error('Event not received');
});
test('Wildcard Events', () => {
let wildcardReceived = false;
sdk.on('browser:*', () => {
wildcardReceived = true;
});
sdk.testEmit({ wildcard: true });
if (!wildcardReceived) throw new Error('Wildcard not matched');
});
test('Lifecycle', () => {
let destroyed = false;
sdk.on('sdk:destroy', () => { destroyed = true; });
sdk.destroy();
if (!destroyed) throw new Error('Destroy event not fired');
});
// Summary
const passed = results.filter(r => r.status === 'pass').length;
const failed = results.filter(r => r.status === 'fail').length;
const summary = document.createElement('div');
summary.className = 'summary';
summary.innerHTML = `
<div>📊 Results: ${results.length} tests</div>
<div style="color: #28a745;">✅ Passed: ${passed}</div>
<div style="color: #dc3545;">❌ Failed: ${failed}</div>
<div style="margin-top: 10px;">${failed === 0 ? '🎉 All tests passed!' : '⚠️ Some tests failed'}</div>
`;
output.appendChild(summary);
console.log('Browser runtime tests complete:', { passed, failed, total: results.length });
</script>
</body>
</html>