Skip to content

Commit

Permalink
add test.js | fix test.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
whonion committed Aug 28, 2023
1 parent 79b3a7d commit fc13604
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
name: Test

on: [push] # You can customize the trigger event based on your needs
on: [push]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: ['18.x', '19.x', '20.x']

env: # Set environment variables from repository secrets
ETHERSCANKEY: ${{ secrets.ETHERSCANKEY }}
RPCURL: ${{ secrets.RPCURL }}
EXP_URL: 'https://etherscan.io'

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 20 # You can specify your desired Node.js version
node-version: ${{ matrix.node-version }}

- name: Install Dependencies
run: npm install
- name: Run JavaScript Script
run: node main.js
run: npm i

- name: Test Run
run: node test.js
43 changes: 43 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const childProcess = require("child_process");

const MAX_TEST_DURATION_MS = 120000; // Test duration in milliseconds (e.g., 60 seconds)
const SCRIPT_FILE = "main.js"; // Change this to match your main.js filename

// Function to run the main.js script for a specific duration
function runMainScriptForDuration() {
return new Promise((resolve, reject) => {
const process = childProcess.spawn("node", [SCRIPT_FILE]);

setTimeout(() => {
process.kill(); // Terminate the script after the specified duration
resolve();
}, MAX_TEST_DURATION_MS);

process.stdout.on("data", data => {
console.log(data.toString());
});

process.stderr.on("data", data => {
console.error(data.toString());
reject("Error occurred while running main.js");
});

process.on("close", code => {
if (code === 0) {
resolve();
} else {
reject(`main.js 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 fc13604

Please sign in to comment.