Skip to content

Commit ceff6c4

Browse files
committed
test: add E2E and verification tests for WASM initialization
- Add e2e-test/ folder with Vite-based browser E2E tests - Add test-browser.html for manual browser testing - Add test-bundle.mjs for bundle verification - Add test-init-script.mjs for init script generation test - Add test-init.mjs for Node.js WASM initialization test These tests were created during issue #2 resolution to verify WASM initialization and compilation functionality.
1 parent 61d9156 commit ceff6c4

9 files changed

Lines changed: 1526 additions & 0 deletions

File tree

e2e-test/index.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>T-Ruby WASM E2E Test</title>
6+
<style>
7+
body { font-family: monospace; padding: 20px; background: #1e1e1e; color: #d4d4d4; }
8+
.success { color: #4ec9b0; }
9+
.error { color: #f14c4c; }
10+
.info { color: #569cd6; }
11+
#log { white-space: pre-wrap; line-height: 1.6; }
12+
button { padding: 10px 20px; margin: 10px 5px 10px 0; cursor: pointer; }
13+
</style>
14+
</head>
15+
<body>
16+
<h1>T-Ruby WASM E2E Test</h1>
17+
<div id="status">Ready</div>
18+
<button id="runTest">Run Test</button>
19+
<div id="log"></div>
20+
21+
<script type="module" src="./main.js"></script>
22+
</body>
23+
</html>

e2e-test/main.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { TRuby } from '../dist/index.js';
2+
3+
const logEl = document.getElementById('log');
4+
const statusEl = document.getElementById('status');
5+
6+
function log(msg, type = '') {
7+
const span = document.createElement('span');
8+
span.className = type;
9+
span.textContent = msg + '\n';
10+
logEl.appendChild(span);
11+
console.log(msg);
12+
}
13+
14+
function setStatus(msg, isError = false) {
15+
statusEl.textContent = msg;
16+
statusEl.style.color = isError ? '#f14c4c' : '#4ec9b0';
17+
}
18+
19+
async function runTest() {
20+
logEl.innerHTML = '';
21+
log('=== T-Ruby WASM E2E Test ===\n', 'info');
22+
23+
try {
24+
log('1. TRuby 인스턴스 생성...');
25+
const trb = new TRuby();
26+
log(' ✓ 인스턴스 생성 완료\n', 'success');
27+
28+
log('2. initialize() 호출 (WASM 로딩, 시간이 걸릴 수 있습니다)...');
29+
setStatus('Loading WASM...');
30+
const initStart = performance.now();
31+
await trb.initialize();
32+
const initTime = (performance.now() - initStart).toFixed(0);
33+
log(` ✓ 초기화 완료 (${initTime}ms)\n`, 'success');
34+
35+
log('3. getVersion() 호출...');
36+
const version = await trb.getVersion();
37+
log(` T-Ruby: ${version.tRuby}`, 'success');
38+
log(` Ruby: ${version.ruby}`, 'success');
39+
log(` Ruby WASM: ${version.rubyWasm}\n`, 'success');
40+
41+
// TRuby::VERSION이 제대로 정의되었는지 확인
42+
if (!version.tRuby || version.tRuby === 'nil' || version.tRuby === 'undefined') {
43+
throw new Error(`TRuby::VERSION이 올바르지 않음: ${version.tRuby}`);
44+
}
45+
46+
log('4. 간단한 컴파일 테스트...');
47+
const source1 = `def foo: Integer
48+
42
49+
end`;
50+
log(` 입력:\n${source1}\n`, 'info');
51+
52+
const result1 = await trb.compile(source1);
53+
if (result1.success) {
54+
log(' ✓ 컴파일 성공!', 'success');
55+
log(` 출력:\n${result1.ruby}\n`, 'info');
56+
} else {
57+
log(' ✗ 컴파일 실패', 'error');
58+
log(` 에러: ${JSON.stringify(result1.errors, null, 2)}`, 'error');
59+
throw new Error('기본 컴파일 실패');
60+
}
61+
62+
log('5. Ruby interpolation 포함 코드 테스트...');
63+
const source2 = `def greet(name: String): String
64+
"Hello, \#{name}!"
65+
end`;
66+
log(` 입력:\n${source2}\n`, 'info');
67+
68+
const result2 = await trb.compile(source2);
69+
if (result2.success) {
70+
log(' ✓ 컴파일 성공!', 'success');
71+
log(` 출력:\n${result2.ruby}\n`, 'info');
72+
} else {
73+
log(' ✗ 컴파일 실패', 'error');
74+
log(` 에러: ${JSON.stringify(result2.errors, null, 2)}`, 'error');
75+
throw new Error('interpolation 코드 컴파일 실패');
76+
}
77+
78+
log('6. 클래스 정의 테스트...');
79+
const source3 = `class User
80+
attr_reader name: String
81+
attr_reader age: Integer
82+
83+
def initialize(name: String, age: Integer)
84+
@name = name
85+
@age = age
86+
end
87+
88+
def greet: String
89+
"I am \#{@name}, \#{@age} years old"
90+
end
91+
end`;
92+
log(` 입력:\n${source3}\n`, 'info');
93+
94+
const result3 = await trb.compile(source3);
95+
if (result3.success) {
96+
log(' ✓ 컴파일 성공!', 'success');
97+
log(` 출력:\n${result3.ruby}\n`, 'info');
98+
} else {
99+
log(' ✗ 컴파일 실패', 'error');
100+
log(` 에러: ${JSON.stringify(result3.errors, null, 2)}`, 'error');
101+
throw new Error('클래스 정의 컴파일 실패');
102+
}
103+
104+
log('\n=== 모든 테스트 통과! ===', 'success');
105+
setStatus('All tests passed!');
106+
107+
// 자동화된 테스트를 위한 글로벌 결과
108+
window.__TEST_RESULT__ = { success: true, version };
109+
110+
} catch (error) {
111+
log('\n❌ 테스트 실패: ' + error.message, 'error');
112+
log('스택: ' + error.stack, 'error');
113+
setStatus('Test failed: ' + error.message, true);
114+
window.__TEST_RESULT__ = { success: false, error: error.message };
115+
}
116+
}
117+
118+
document.getElementById('runTest').addEventListener('click', runTest);
119+
120+
// 자동 실행 (Playwright 테스트용)
121+
if (new URLSearchParams(window.location.search).has('autorun')) {
122+
runTest();
123+
}

0 commit comments

Comments
 (0)