forked from emerteroglu/evm-contract-sniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
42 lines (36 loc) · 1.13 KB
/
test.ts
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
// test.ts
import { spawn } from 'child_process';
const MAX_TEST_DURATION_MS = 60000; // Test duration in milliseconds (e.g., 120 seconds)
const SCRIPT_FILE = 'main.ts'; // Change this to match your main.ts filename
// Function to run the main.ts script for a specific duration
function runMainScriptForDuration() {
return new Promise<void>((resolve, reject) => {
const process = spawn('ts-node', [SCRIPT_FILE], {
stdio: 'inherit', // Inherit stdio from the parent process
});
setTimeout(() => {
process.kill(); // Terminate the script after the specified duration
resolve();
}, MAX_TEST_DURATION_MS);
process.on('close', (code) => {
if (code === 0) {
resolve();
} else {
reject(`main.ts exited with code ${code}`);
}
});
});
}
// Run the test
(async () => {
try {
await runMainScriptForDuration();
console.log('Test completed successfully.');
} catch (error:any) {
if (error.message === 'The operation was canceled.') {
console.log('Test was canceled due to timeout.');
} else {
console.error('Test failed:', error);
}
}
})();