-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-final.js
More file actions
59 lines (52 loc) · 1.59 KB
/
Copy pathtest-final.js
File metadata and controls
59 lines (52 loc) · 1.59 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
const http = require('http');
const languages = [
'JavaScript', 'TypeScript', 'Python', 'C', 'C++', 'C#', 'Java',
'Go', 'Rust', 'PHP', 'Ruby', 'Kotlin', 'Swift'
];
async function testLanguage(lang) {
return new Promise((resolve) => {
const body = JSON.stringify({
language: lang.toLowerCase(),
files: [{ content: 'test-code' }]
});
const req = http.request({
hostname: 'localhost',
port: 3000,
path: '/api/v2/piston/execute',
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Content-Length': body.length }
}, (res) => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => {
try {
const result = JSON.parse(data);
const output = (result.run?.stdout || result.run?.output || '').slice(0, 50);
console.log(`✓ ${lang.padEnd(12)} ${output || '(no output)'}`);
} catch (e) {
console.log(`✗ ${lang.padEnd(12)} ERROR: ${e.message}`);
}
resolve();
});
});
req.on('error', (e) => {
console.log(`✗ ${lang.padEnd(12)} CONNECTION: ${e.message}`);
resolve();
});
req.setTimeout(3000, () => {
req.destroy();
console.log(`✗ ${lang.padEnd(12)} TIMEOUT`);
resolve();
});
req.write(body);
req.end();
});
}
(async () => {
console.log('\n=== All Languages Test ===\n');
for (const lang of languages) {
await testLanguage(lang);
await new Promise(r => setTimeout(r, 300));
}
console.log('\n');
})();