added test script

This commit is contained in:
bhavik-m 2022-03-23 17:33:37 +05:30
parent 8932e8aa5e
commit 97c4f6dffa
3 changed files with 66 additions and 2 deletions

View File

@ -6,7 +6,7 @@ import "@nomiclabs/hardhat-web3";
import "hardhat-deploy";
import "hardhat-deploy-ethers";
import "@typechain/hardhat";
import "./scripts/tests/run_test_through_cmd"
import { resolve } from "path";
import { config as dotenvConfig } from "dotenv";
import { HardhatUserConfig } from "hardhat/config";

View File

@ -12,7 +12,8 @@
"test:runner": "hardhat run scripts/tests/run-tests.ts",
"typechain": "hardhat typechain",
"compile": "hardhat compile",
"deploy:runner": "hardhat run scripts/deployment/deployConnectorsFromCmd.ts"
"deploy:runner": "hardhat run scripts/deployment/deployConnectorsFromCmd.ts",
"tests": "hardhat run_tests"
},
"repository": {
"type": "git",

View File

@ -0,0 +1,63 @@
import { promises as fs } from "fs";
import { join } from "path";
import { execScript } from "./command";
import { task } from "hardhat/config";
let start: number, end: number;
task("run_tests", "runs specified test on a specified chain")
.addPositionalParam("chain")
.addPositionalParam("test")
.setAction(async (taskArgs) => {
const chain = taskArgs.chain;
const test = taskArgs.test;
await testRunner(chain,test)
.then(() =>
console.log(
`🙌 finished the test runner, time taken ${(end - start) / 1000} sec`
)
)
.catch((err) => console.error("❌ failed due to error: ", err));
});
async function testRunner(chain: string, testName: string) {
const testsPath = join(__dirname, "../../test", chain);
await fs.access(testsPath);
const availableTests = await fs.readdir(testsPath);
if (availableTests.length === 0) {
throw new Error(`No tests available for ${chain}`);
}
start = Date.now();
let path: string;
if (testName === "all") {
for (let test of availableTests) {
path = join(testsPath, test);
path += "/*";
await execScript({
cmd: "npx",
args: ["hardhat", "test", path],
env: {
networkType: chain,
},
}).catch((err)=>console.log(`failed ${test}`))
}
} else {
path = join(testsPath, testName);
path += "/*";
await execScript({
cmd: "npx",
args: ["hardhat", "test", path],
env: {
networkType: chain,
},
});
}
end = Date.now();
}