mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
added test script
This commit is contained in:
parent
8932e8aa5e
commit
97c4f6dffa
|
@ -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";
|
||||
|
|
|
@ -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",
|
||||
|
|
63
scripts/tests/run_test_through_cmd.ts
Normal file
63
scripts/tests/run_test_through_cmd.ts
Normal 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();
|
||||
}
|
Loading…
Reference in New Issue
Block a user