Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests twice #2140

Merged
merged 2 commits into from Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thirty-olives-laugh.md
@@ -0,0 +1,5 @@
---
"hardhat": patch
---

Fix running the `test` task multiple times in a script (issue #1720)
4 changes: 2 additions & 2 deletions packages/e2e/package.json
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"@types/chai": "^4.2.0",
"@types/fs-extra": "^5.1.0",
"@types/mocha": "^5.2.6",
"@types/mocha": "^9.0.0",
"@types/node": "^12.0.0",
"@types/shelljs": "^0.8.6",
"@typescript-eslint/eslint-plugin": "4.29.2",
Expand All @@ -32,7 +32,7 @@
"eslint-plugin-import": "2.24.1",
"eslint-plugin-prettier": "3.4.0",
"fs-extra": "^7.0.1",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"shelljs": "^0.8.3",
Expand Down
@@ -0,0 +1,25 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const hre = require("hardhat");

async function main() {
const code = await hre.run("test");

if (code > 0) {
console.error("Failed first test run");
process.exit(1);
}

const secondCode = await hre.run("test");

if (secondCode > 0) {
console.error("Failed second test run");
process.exit(1);
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
@@ -0,0 +1,5 @@
describe("simple", () => {
it("should pass", () => {
// throw new Error("not equal");
kanej marked this conversation as resolved.
Show resolved Hide resolved
});
});
27 changes: 27 additions & 0 deletions packages/e2e/test/index.ts
Expand Up @@ -39,6 +39,33 @@ describe("e2e tests", function () {
const { code: hhCleanCode2 } = shell.exec(`${hardhatBinary} clean`);
assert.equal(hhCleanCode2, 0);
});

it("should test programmatically", function () {
// hh clean
const { code: hhCleanCode1 } = shell.exec(`${hardhatBinary} clean`);
assert.equal(hhCleanCode1, 0);

// hh compile
const { code: testRunCode, stdout } = shell.exec(
`${hardhatBinary} run ./scripts/multi-run-test.js`
);
assert.equal(testRunCode, 0);

// check stdout

// check we get passing runs
assert.match(stdout, /1 passing/);
// check we get no runs without tests
assert.notMatch(
stdout,
/0 passing/,
"A test run occured with 0 tests - potential caching issue"
);

// hh clean
const { code: hhCleanCode2 } = shell.exec(`${hardhatBinary} clean`);
assert.equal(hhCleanCode2, 0);
});
});

describe("sample projects", function () {
Expand Down
6 changes: 3 additions & 3 deletions packages/hardhat-core/package.json
Expand Up @@ -63,7 +63,7 @@
"@types/fs-extra": "^5.1.0",
"@types/glob": "^7.1.1",
"@types/lodash": "^4.14.123",
"@types/mocha": "^5.2.6",
"@types/mocha": "^9.0.0",
"@types/node": "^12.0.0",
"@types/node-fetch": "^2.3.7",
"@types/qs": "^6.5.3",
Expand All @@ -81,7 +81,7 @@
"eslint-plugin-import": "2.24.1",
"eslint-plugin-prettier": "3.4.0",
"ethers": "^5.0.0",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"prettier": "2.4.1",
"proxy": "^1.0.2",
"rimraf": "^3.0.2",
Expand Down Expand Up @@ -124,7 +124,7 @@
"lodash": "^4.17.11",
"merkle-patricia-tree": "^4.2.0",
"mnemonist": "^0.38.0",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"node-fetch": "^2.6.0",
"qs": "^6.7.0",
"raw-body": "^2.4.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/hardhat-core/src/builtin-tasks/test.ts
Expand Up @@ -57,6 +57,8 @@ subtask(TASK_TEST_RUN_MOCHA_TESTS)
mocha.run(resolve);
});

mocha.dispose();

return testFailures;
});

Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-docker/package.json
Expand Up @@ -31,7 +31,7 @@
"@types/chai": "^4.2.0",
"@types/dockerode": "^2.5.19",
"@types/fs-extra": "^5.1.0",
"@types/mocha": "^5.2.6",
"@types/mocha": "^9.0.0",
"@types/node-fetch": "^2.3.7",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "4.29.2",
Expand All @@ -41,7 +41,7 @@
"eslint-config-prettier": "8.3.0",
"eslint-plugin-import": "2.24.1",
"eslint-plugin-prettier": "3.4.0",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-ethers/package.json
Expand Up @@ -38,7 +38,7 @@
],
"devDependencies": {
"@types/chai": "^4.2.0",
"@types/mocha": "^5.2.6",
"@types/mocha": "^9.0.0",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "4.29.2",
"@typescript-eslint/parser": "4.29.2",
Expand All @@ -49,7 +49,7 @@
"eslint-plugin-prettier": "3.4.0",
"ethers": "^5.0.0",
"hardhat": "^2.0.0",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-etherscan/package.json
Expand Up @@ -48,7 +48,7 @@
"@types/cbor": "^5.0.1",
"@types/chai": "^4.2.0",
"@types/fs-extra": "^5.1.0",
"@types/mocha": "^5.2.6",
"@types/mocha": "^9.0.0",
"@types/node-fetch": "^2.3.7",
"@types/node": "^12.0.0",
"@types/semver": "^6.0.2",
Expand All @@ -61,7 +61,7 @@
"eslint-plugin-prettier": "3.4.0",
"ethers": "^5.0.8",
"hardhat": "^2.0.4",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"nock": "^13.0.5",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-ganache/package.json
Expand Up @@ -40,7 +40,7 @@
"@types/chai": "^4.2.0",
"@types/debug": "^4.1.4",
"@types/fs-extra": "^5.1.0",
"@types/mocha": "^5.2.6",
"@types/mocha": "^9.0.0",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "4.29.2",
"@typescript-eslint/parser": "4.29.2",
Expand All @@ -50,7 +50,7 @@
"eslint-plugin-import": "2.24.1",
"eslint-plugin-prettier": "3.4.0",
"hardhat": "^2.0.0",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-interface-builder": "^0.2.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-shorthand/package.json
Expand Up @@ -34,7 +34,7 @@
"devDependencies": {
"@types/chai": "^4.2.0",
"@types/fs-extra": "^5.1.0",
"@types/mocha": "^5.2.6",
"@types/mocha": "^9.0.0",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "4.29.2",
"@typescript-eslint/parser": "4.29.2",
Expand All @@ -44,7 +44,7 @@
"eslint-plugin-import": "2.24.1",
"eslint-plugin-prettier": "3.4.0",
"hardhat": "^2.0.0",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-solhint/package.json
Expand Up @@ -38,7 +38,7 @@
"devDependencies": {
"@types/chai": "^4.2.0",
"@types/fs-extra": "^5.1.0",
"@types/mocha": "^5.2.6",
"@types/mocha": "^9.0.0",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "4.29.2",
"@typescript-eslint/parser": "4.29.2",
Expand All @@ -49,7 +49,7 @@
"eslint-plugin-prettier": "3.4.0",
"fs-extra": "^7.0.1",
"hardhat": "^2.0.0",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-solpp/package.json
Expand Up @@ -39,7 +39,7 @@
"devDependencies": {
"@types/chai": "^4.2.0",
"@types/fs-extra": "^5.1.0",
"@types/mocha": "^5.2.6",
"@types/mocha": "^9.0.0",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "4.29.2",
"@typescript-eslint/parser": "4.29.2",
Expand All @@ -49,7 +49,7 @@
"eslint-plugin-import": "2.24.1",
"eslint-plugin-prettier": "3.4.0",
"hardhat": "^2.0.0",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-truffle4/package.json
Expand Up @@ -42,7 +42,7 @@
"@nomiclabs/hardhat-web3-legacy": "^2.0.0",
"@types/fs-extra": "^5.1.0",
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.6",
"@types/mocha": "^9.0.0",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "4.29.2",
"@typescript-eslint/parser": "4.29.2",
Expand All @@ -52,7 +52,7 @@
"eslint-plugin-import": "2.24.1",
"eslint-plugin-prettier": "3.4.0",
"hardhat": "^2.6.4",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-truffle5/package.json
Expand Up @@ -42,7 +42,7 @@
"@nomiclabs/hardhat-web3": "^2.0.0",
"@types/fs-extra": "^5.1.0",
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.6",
"@types/mocha": "^9.0.0",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "4.29.2",
"@typescript-eslint/parser": "4.29.2",
Expand All @@ -52,7 +52,7 @@
"eslint-plugin-import": "2.24.1",
"eslint-plugin-prettier": "3.4.0",
"hardhat": "^2.6.4",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-vyper/package.json
Expand Up @@ -40,7 +40,7 @@
"@types/chai": "^4.2.0",
"@types/fs-extra": "^5.1.0",
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.6",
"@types/mocha": "^9.0.0",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "4.29.2",
"@typescript-eslint/parser": "4.29.2",
Expand All @@ -50,7 +50,7 @@
"eslint-plugin-import": "2.24.1",
"eslint-plugin-prettier": "3.4.0",
"hardhat": "^2.0.0",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-waffle/package.json
Expand Up @@ -34,7 +34,7 @@
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@types/chai": "^4.2.0",
"@types/fs-extra": "^5.1.0",
"@types/mocha": "^5.2.6",
"@types/mocha": "^9.0.0",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "4.29.2",
"@typescript-eslint/parser": "4.29.2",
Expand All @@ -46,7 +46,7 @@
"ethereum-waffle": "^3.2.0",
"ethers": "^5.0.0",
"hardhat": "^2.0.0",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-web3-legacy/package.json
Expand Up @@ -33,7 +33,7 @@
],
"devDependencies": {
"@types/chai": "^4.2.0",
"@types/mocha": "^5.2.6",
"@types/mocha": "^9.0.0",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "4.29.2",
"@typescript-eslint/parser": "4.29.2",
Expand All @@ -43,7 +43,7 @@
"eslint-plugin-import": "2.24.1",
"eslint-plugin-prettier": "3.4.0",
"hardhat": "^2.0.0",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-web3/package.json
Expand Up @@ -33,7 +33,7 @@
],
"devDependencies": {
"@types/chai": "^4.2.0",
"@types/mocha": "^5.2.6",
"@types/mocha": "^9.0.0",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "4.29.2",
"@typescript-eslint/parser": "4.29.2",
Expand All @@ -43,7 +43,7 @@
"eslint-plugin-import": "2.24.1",
"eslint-plugin-prettier": "3.4.0",
"hardhat": "^2.0.0",
"mocha": "^7.1.2",
"mocha": "^7.2.0",
"prettier": "2.4.1",
"rimraf": "^3.0.2",
"ts-node": "^8.1.0",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Expand Up @@ -2147,10 +2147,10 @@
dependencies:
"@types/node" "*"

"@types/mocha@^5.2.6":
version "5.2.7"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.7.tgz#315d570ccb56c53452ff8638738df60726d5b6ea"
integrity sha512-NYrtPht0wGzhwe9+/idPaBB+TqkY9AhTvOLMkThm0IoEfLaiVQZwBwyJ5puCkO3AUCWrmcoePjp2mbFocKy4SQ==
"@types/mocha@^9.0.0":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-9.0.0.tgz#3205bcd15ada9bc681ac20bef64e9e6df88fd297"
integrity sha512-scN0hAWyLVAvLR9AyW7HoFF5sJZglyBsbPuHO4fv7JRvfmPBMfp1ozWqOf/e4wwPNxezBZXRfWzMb6iFLgEVRA==

"@types/node-fetch@^2.3.7", "@types/node-fetch@^2.5.5":
version "2.5.11"
Expand Down Expand Up @@ -10476,7 +10476,7 @@ mnemonist@^0.38.0:
dependencies:
obliterator "^1.6.1"

mocha@^7.1.2:
mocha@^7.2.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-7.2.0.tgz#01cc227b00d875ab1eed03a75106689cfed5a604"
integrity sha512-O9CIypScywTVpNaRrCAgoUnJgozpIofjKUYmJhiCIJMiuYnLI6otcb1/kpW9/n/tJODHGZ7i8aLQoDVsMtOKQQ==
Expand Down