Skip to content

Commit

Permalink
✅ update test.yml | add test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
whonion committed Dec 23, 2023
1 parent 0848d91 commit 116925c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ jobs:
run: npm i

- name: Test Running
run: npm run start
run: npm run test
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"start": "js/main.js",
"author": "https://github.com/whonion",
"scripts": {
"start": "ts-node main.ts"
"start": "ts-node main.ts",
"test": "ts-node test.ts"

},
"dependencies": {
Expand Down
36 changes: 36 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { spawn } from 'child_process';

const MAX_TEST_DURATION_MS = 120000; // 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
runMainScriptForDuration()
.then(() => {
console.log('Test completed successfully.');
})
.catch((error) => {
console.error('Test failed:', error);
process.exit(1);
});

0 comments on commit 116925c

Please sign in to comment.