From 928f2e7c64147e63d77a27e6082b42a927769293 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Fri, 6 Jan 2023 11:30:27 +0100 Subject: [PATCH 01/17] Upgrade typescript and ts-node --- package.json | 2 +- packages/e2e/package.json | 4 +- packages/hardhat-chai-matchers/package.json | 4 +- packages/hardhat-core/package.json | 4 +- .../internal/core/config/config-loading.ts | 2 + .../stack-traces/consoleLogger.ts | 2 +- packages/hardhat-docker/package.json | 4 +- packages/hardhat-ethers/package.json | 4 +- packages/hardhat-etherscan/package.json | 4 +- packages/hardhat-ganache/package.json | 4 +- packages/hardhat-network-helpers/package.json | 4 +- packages/hardhat-shorthand/package.json | 4 +- packages/hardhat-solhint/package.json | 4 +- packages/hardhat-solpp/package.json | 4 +- packages/hardhat-toolbox/package.json | 4 +- packages/hardhat-truffle4/package.json | 4 +- packages/hardhat-truffle5/package.json | 4 +- packages/hardhat-vyper/package.json | 4 +- packages/hardhat-waffle/package.json | 4 +- packages/hardhat-web3-legacy/package.json | 4 +- packages/hardhat-web3/package.json | 4 +- yarn.lock | 89 +++++++++++++++++++ 22 files changed, 129 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index 13c8032335..d728a63605 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "@changesets/cli": "^2.16.0", "prettier": "2.4.1", "shelljs": "^0.8.5", - "typescript": "~4.5.2", + "typescript": "~4.7.4", "wsrun": "^5.2.2" }, "scripts": { diff --git a/packages/e2e/package.json b/packages/e2e/package.json index 497a6a489a..492cbb1ea0 100644 --- a/packages/e2e/package.json +++ b/packages/e2e/package.json @@ -37,7 +37,7 @@ "prettier": "2.4.1", "rimraf": "^3.0.2", "shelljs": "^0.8.5", - "ts-node": "^8.1.0", - "typescript": "~4.5.2" + "ts-node": "^10.8.0", + "typescript": "~4.7.4" } } diff --git a/packages/hardhat-chai-matchers/package.json b/packages/hardhat-chai-matchers/package.json index c5f99a277a..18949439a0 100644 --- a/packages/hardhat-chai-matchers/package.json +++ b/packages/hardhat-chai-matchers/package.json @@ -58,8 +58,8 @@ "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", - "ts-node": "^8.1.0", - "typescript": "~4.5.2" + "ts-node": "^10.8.0", + "typescript": "~4.7.4" }, "peerDependencies": { "@nomiclabs/hardhat-ethers": "^2.0.0", diff --git a/packages/hardhat-core/package.json b/packages/hardhat-core/package.json index 9ace313176..6e866fd7a7 100644 --- a/packages/hardhat-core/package.json +++ b/packages/hardhat-core/package.json @@ -94,8 +94,8 @@ "rimraf": "^3.0.2", "sinon": "^9.0.0", "time-require": "^0.1.2", - "ts-node": "^8.1.0", - "typescript": "~4.5.2" + "ts-node": "^10.8.0", + "typescript": "~4.7.4" }, "dependencies": { "@ethersproject/abi": "^5.1.2", diff --git a/packages/hardhat-core/src/internal/core/config/config-loading.ts b/packages/hardhat-core/src/internal/core/config/config-loading.ts index b17f15afa6..dd948c3e8d 100644 --- a/packages/hardhat-core/src/internal/core/config/config-loading.ts +++ b/packages/hardhat-core/src/internal/core/config/config-loading.ts @@ -165,6 +165,8 @@ export function analyzeModuleNotFoundError(error: any, configPath: string) { const throwingFile = stackTrace .filter((x) => x.file !== null) .map((x) => x.file!) + // ignore frames related to source map support + .filter((x) => !x.includes(path.join("@cspotcode", "source-map-support"))) .find((x) => path.isAbsolute(x)); if (throwingFile === null || throwingFile === undefined) { diff --git a/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts b/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts index 529b5627db..e5e9f92236 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts @@ -139,7 +139,7 @@ export class ConsoleLogger { private _decode(data: Buffer, types: string[]): ConsoleLogs { return types.map((type, i) => { - const position = i * 32; + const position: number = i * 32; switch (types[i]) { case Uint256Ty: return bufferToBigInt( diff --git a/packages/hardhat-docker/package.json b/packages/hardhat-docker/package.json index 5eebd61c8b..1eb15e273c 100644 --- a/packages/hardhat-docker/package.json +++ b/packages/hardhat-docker/package.json @@ -45,8 +45,8 @@ "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", - "ts-node": "^8.1.0", - "typescript": "~4.5.2" + "ts-node": "^10.8.0", + "typescript": "~4.7.4" }, "peerDependencies": {}, "dependencies": { diff --git a/packages/hardhat-ethers/package.json b/packages/hardhat-ethers/package.json index 1502dff3f2..5de6bf9e7d 100644 --- a/packages/hardhat-ethers/package.json +++ b/packages/hardhat-ethers/package.json @@ -56,8 +56,8 @@ "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", - "ts-node": "^8.1.0", - "typescript": "~4.5.2" + "ts-node": "^10.8.0", + "typescript": "~4.7.4" }, "peerDependencies": { "ethers": "^5.0.0", diff --git a/packages/hardhat-etherscan/package.json b/packages/hardhat-etherscan/package.json index 1adf4ef8e7..74e7cf6201 100644 --- a/packages/hardhat-etherscan/package.json +++ b/packages/hardhat-etherscan/package.json @@ -67,8 +67,8 @@ "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", - "ts-node": "^8.1.0", - "typescript": "~4.5.2" + "ts-node": "^10.8.0", + "typescript": "~4.7.4" }, "peerDependencies": { "hardhat": "^2.0.4" diff --git a/packages/hardhat-ganache/package.json b/packages/hardhat-ganache/package.json index 6b18c69905..b53a515eca 100644 --- a/packages/hardhat-ganache/package.json +++ b/packages/hardhat-ganache/package.json @@ -56,8 +56,8 @@ "prettier": "2.4.1", "rimraf": "^3.0.2", "ts-interface-builder": "^0.2.0", - "ts-node": "^8.1.0", - "typescript": "~4.5.2" + "ts-node": "^10.8.0", + "typescript": "~4.7.4" }, "peerDependencies": { "hardhat": "^2.0.0" diff --git a/packages/hardhat-network-helpers/package.json b/packages/hardhat-network-helpers/package.json index ab6ae24b45..158356df56 100644 --- a/packages/hardhat-network-helpers/package.json +++ b/packages/hardhat-network-helpers/package.json @@ -57,8 +57,8 @@ "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", - "ts-node": "^8.1.0", - "typescript": "~4.5.2" + "ts-node": "^10.8.0", + "typescript": "~4.7.4" }, "peerDependencies": { "hardhat": "^2.9.5" diff --git a/packages/hardhat-shorthand/package.json b/packages/hardhat-shorthand/package.json index a57adb4ff2..e89e19494b 100644 --- a/packages/hardhat-shorthand/package.json +++ b/packages/hardhat-shorthand/package.json @@ -49,8 +49,8 @@ "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", - "ts-node": "^8.1.0", - "typescript": "~4.5.2" + "ts-node": "^10.8.0", + "typescript": "~4.7.4" }, "dependencies": { "@fvictorio/tabtab": "^0.0.3", diff --git a/packages/hardhat-solhint/package.json b/packages/hardhat-solhint/package.json index c77727c8e2..55e062f069 100644 --- a/packages/hardhat-solhint/package.json +++ b/packages/hardhat-solhint/package.json @@ -54,8 +54,8 @@ "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", - "ts-node": "^8.1.0", - "typescript": "~4.5.2" + "ts-node": "^10.8.0", + "typescript": "~4.7.4" }, "peerDependencies": { "hardhat": "^2.0.0" diff --git a/packages/hardhat-solpp/package.json b/packages/hardhat-solpp/package.json index feecd83854..4410058d2a 100644 --- a/packages/hardhat-solpp/package.json +++ b/packages/hardhat-solpp/package.json @@ -54,8 +54,8 @@ "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", - "ts-node": "^8.1.0", - "typescript": "~4.5.2" + "ts-node": "^10.8.0", + "typescript": "~4.7.4" }, "peerDependencies": { "hardhat": "^2.0.0" diff --git a/packages/hardhat-toolbox/package.json b/packages/hardhat-toolbox/package.json index 4bb566dd61..bc740f42ec 100644 --- a/packages/hardhat-toolbox/package.json +++ b/packages/hardhat-toolbox/package.json @@ -61,9 +61,9 @@ "prettier": "2.4.1", "rimraf": "^3.0.2", "solidity-coverage": "^0.8.1", - "ts-node": "^8.1.0", + "ts-node": "^10.8.0", "typechain": "^8.1.0", - "typescript": "~4.5.2" + "typescript": "~4.7.4" }, "peerDependencies": { "@ethersproject/abi": "^5.4.7", diff --git a/packages/hardhat-truffle4/package.json b/packages/hardhat-truffle4/package.json index 0c5b00703d..40c53c44d6 100644 --- a/packages/hardhat-truffle4/package.json +++ b/packages/hardhat-truffle4/package.json @@ -57,8 +57,8 @@ "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", - "ts-node": "^8.1.0", - "typescript": "~4.5.2", + "ts-node": "^10.8.0", + "typescript": "~4.7.4", "web3": "^0.20.0" }, "peerDependencies": { diff --git a/packages/hardhat-truffle5/package.json b/packages/hardhat-truffle5/package.json index 4286500334..3c21c059cb 100644 --- a/packages/hardhat-truffle5/package.json +++ b/packages/hardhat-truffle5/package.json @@ -57,8 +57,8 @@ "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", - "ts-node": "^8.1.0", - "typescript": "~4.5.2", + "ts-node": "^10.8.0", + "typescript": "~4.7.4", "web3": "^1.0.0-beta.36" }, "peerDependencies": { diff --git a/packages/hardhat-vyper/package.json b/packages/hardhat-vyper/package.json index 4dc44a6e53..7e3b8337e2 100644 --- a/packages/hardhat-vyper/package.json +++ b/packages/hardhat-vyper/package.json @@ -56,8 +56,8 @@ "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", - "ts-node": "^8.1.0", - "typescript": "~4.5.2" + "ts-node": "^10.8.0", + "typescript": "~4.7.4" }, "peerDependencies": { "hardhat": "^2.8.3" diff --git a/packages/hardhat-waffle/package.json b/packages/hardhat-waffle/package.json index 58099ea647..f7f2ddd724 100644 --- a/packages/hardhat-waffle/package.json +++ b/packages/hardhat-waffle/package.json @@ -51,8 +51,8 @@ "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", - "ts-node": "^8.1.0", - "typescript": "~4.5.2" + "ts-node": "^10.8.0", + "typescript": "~4.7.4" }, "peerDependencies": { "@nomiclabs/hardhat-ethers": "^2.0.0", diff --git a/packages/hardhat-web3-legacy/package.json b/packages/hardhat-web3-legacy/package.json index e5d06bc8b4..593bcab773 100644 --- a/packages/hardhat-web3-legacy/package.json +++ b/packages/hardhat-web3-legacy/package.json @@ -48,8 +48,8 @@ "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", - "ts-node": "^8.1.0", - "typescript": "~4.5.2", + "ts-node": "^10.8.0", + "typescript": "~4.7.4", "web3": "^0.20.0" }, "peerDependencies": { diff --git a/packages/hardhat-web3/package.json b/packages/hardhat-web3/package.json index 16b308730b..cd5cc17b9d 100644 --- a/packages/hardhat-web3/package.json +++ b/packages/hardhat-web3/package.json @@ -48,8 +48,8 @@ "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", - "ts-node": "^8.1.0", - "typescript": "~4.5.2", + "ts-node": "^10.8.0", + "typescript": "~4.7.4", "web3": "^1.0.0-beta.36" }, "peerDependencies": { diff --git a/yarn.lock b/yarn.lock index 59a16d4696..a03051a2be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -236,6 +236,13 @@ human-id "^1.0.2" prettier "^1.19.1" +"@cspotcode/source-map-support@^0.8.0": + version "0.8.1" + resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1" + integrity sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw== + dependencies: + "@jridgewell/trace-mapping" "0.3.9" + "@ensdomains/address-encoder@^0.1.7": version "0.1.9" resolved "https://registry.yarnpkg.com/@ensdomains/address-encoder/-/address-encoder-0.1.9.tgz#f948c485443d9ef7ed2c0c4790e931c33334d02d" @@ -945,6 +952,24 @@ "@types/istanbul-reports" "^1.1.1" "@types/yargs" "^13.0.0" +"@jridgewell/resolve-uri@^3.0.3": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz#2203b118c157721addfe69d47b70465463066d78" + integrity sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w== + +"@jridgewell/sourcemap-codec@^1.4.10": + version "1.4.14" + resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24" + integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw== + +"@jridgewell/trace-mapping@0.3.9": + version "0.3.9" + resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz#6534fd5933a53ba7cbf3a17615e273a0d1273ff9" + integrity sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ== + dependencies: + "@jridgewell/resolve-uri" "^3.0.3" + "@jridgewell/sourcemap-codec" "^1.4.10" + "@manypkg/find-root@^1.1.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@manypkg/find-root/-/find-root-1.1.0.tgz#a62d8ed1cd7e7d4c11d9d52a8397460b5d4ad29f" @@ -1495,6 +1520,26 @@ strip-ansi "^4.0.0" strip-indent "^2.0.0" +"@tsconfig/node10@^1.0.7": + version "1.0.9" + resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.9.tgz#df4907fc07a886922637b15e02d4cebc4c0021b2" + integrity sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA== + +"@tsconfig/node12@^1.0.7": + version "1.0.11" + resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.11.tgz#ee3def1f27d9ed66dac6e46a295cffb0152e058d" + integrity sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag== + +"@tsconfig/node14@^1.0.0": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.3.tgz#e4386316284f00b98435bf40f72f75a09dabf6c1" + integrity sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow== + +"@tsconfig/node16@^1.0.2": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.3.tgz#472eaab5f15c1ffdd7f8628bd4c4f753995ec79e" + integrity sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ== + "@typechain/ethers-v5@^10.1.0": version "10.1.0" resolved "https://registry.yarnpkg.com/@typechain/ethers-v5/-/ethers-v5-10.1.0.tgz#068d7dc7014502354696dab59590a7841091e951" @@ -2069,6 +2114,11 @@ acorn-jsx@^5.0.0, acorn-jsx@^5.3.1: resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937" integrity sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ== +acorn-walk@^8.1.1: + version "8.2.0" + resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1" + integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA== + acorn@^6.0.7: version "6.4.2" resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.4.2.tgz#35866fd710528e92de10cf06016498e47e39e1e6" @@ -2079,6 +2129,11 @@ acorn@^7.4.0: resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa" integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== +acorn@^8.4.1: + version "8.8.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.0.tgz#88c0187620435c7f6015803f5539dae05a9dbea8" + integrity sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w== + address@^1.0.1: version "1.2.0" resolved "https://registry.yarnpkg.com/address/-/address-1.2.0.tgz#d352a62c92fee90f89a693eccd2a8b2139ab02d9" @@ -4112,6 +4167,11 @@ create-hmac@^1.1.0, create-hmac@^1.1.4, create-hmac@^1.1.7: safe-buffer "^5.0.1" sha.js "^2.4.8" +create-require@^1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" + integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== + cross-fetch@^2.1.0, cross-fetch@^2.1.1: version "2.2.6" resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-2.2.6.tgz#2ef0bb39a24ac034787965c457368a28730e220a" @@ -11328,6 +11388,25 @@ ts-interface-checker@^0.1.9: resolved "https://registry.yarnpkg.com/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz#784fd3d679722bc103b1b4b8030bcddb5db2a699" integrity sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA== +ts-node@^10.8.0: + version "10.9.1" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b" + integrity sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw== + dependencies: + "@cspotcode/source-map-support" "^0.8.0" + "@tsconfig/node10" "^1.0.7" + "@tsconfig/node12" "^1.0.7" + "@tsconfig/node14" "^1.0.0" + "@tsconfig/node16" "^1.0.2" + acorn "^8.4.1" + acorn-walk "^8.1.1" + arg "^4.1.0" + create-require "^1.1.0" + diff "^4.0.1" + make-error "^1.1.1" + v8-compile-cache-lib "^3.0.1" + yn "3.1.1" + ts-node@^8.1.0: version "8.10.2" resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.10.2.tgz#eee03764633b1234ddd37f8db9ec10b75ec7fb8d" @@ -11524,6 +11603,11 @@ typescript@~4.5.2: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.5.tgz#d8c953832d28924a9e3d37c73d729c846c5896f3" integrity sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA== +typescript@~4.7.4: + version "4.7.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235" + integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ== + typewise-core@^1.2, typewise-core@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/typewise-core/-/typewise-core-1.2.0.tgz#97eb91805c7f55d2f941748fa50d315d991ef195" @@ -11767,6 +11851,11 @@ uuid@^8.3.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== +v8-compile-cache-lib@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf" + integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg== + v8-compile-cache@^2.0.3: version "2.3.0" resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee" From 3aaf59e97b1f05420f35f905c21ce1f15c5a21f8 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Fri, 6 Jan 2023 11:14:04 +0100 Subject: [PATCH 02/17] Add support for cjs config files --- .../hardhat-core/src/builtin-tasks/test.ts | 32 +++++++++++++++++-- .../internal/core/config/config-loading.ts | 17 ++++++++-- .../src/internal/core/errors-list.ts | 18 +++++++++++ .../src/internal/core/project-structure.ts | 8 +++++ .../src/internal/util/packageInfo.ts | 15 +++++++++ packages/hardhat-toolbox/src/index.ts | 3 +- 6 files changed, 88 insertions(+), 5 deletions(-) diff --git a/packages/hardhat-core/src/builtin-tasks/test.ts b/packages/hardhat-core/src/builtin-tasks/test.ts index 0bf35e22e9..35c4ae217f 100644 --- a/packages/hardhat-core/src/builtin-tasks/test.ts +++ b/packages/hardhat-core/src/builtin-tasks/test.ts @@ -5,11 +5,14 @@ import path from "path"; import { HARDHAT_NETWORK_NAME } from "../internal/constants"; import { subtask, task } from "../internal/core/config/config-env"; +import { HardhatError } from "../internal/core/errors"; +import { ERRORS } from "../internal/core/errors-list"; import { isRunningWithTypescript } from "../internal/core/typescript-support"; import { getForkCacheDirPath } from "../internal/hardhat-network/provider/utils/disk-cache"; import { showForkRecommendationsBannerIfNecessary } from "../internal/hardhat-network/provider/utils/fork-recomendations-banner"; import { pluralize } from "../internal/util/strings"; import { getAllFilesMatching } from "../internal/util/fs-utils"; +import { getProjectPackageJson } from "../internal/util/packageInfo"; import { TASK_COMPILE, @@ -35,8 +38,9 @@ subtask(TASK_TEST_GET_TEST_FILES) return testFilesAbsolutePaths; } - const jsFiles = await getAllFilesMatching(config.paths.tests, (f) => - f.endsWith(".js") + const jsFiles = await getAllFilesMatching( + config.paths.tests, + (f) => f.endsWith(".js") || f.endsWith(".cjs") || f.endsWith(".mjs") ); if (!isRunningWithTypescript(config)) { @@ -52,6 +56,7 @@ subtask(TASK_TEST_GET_TEST_FILES) subtask(TASK_TEST_SETUP_TEST_ENVIRONMENT, async () => {}); +let testsAlreadyRun = false; subtask(TASK_TEST_RUN_MOCHA_TESTS) .addFlag("parallel", "Run tests in parallel") .addFlag("bail", "Stop running tests after the first test failure") @@ -99,6 +104,29 @@ subtask(TASK_TEST_RUN_MOCHA_TESTS) const mocha = new Mocha(mochaConfig); taskArgs.testFiles.forEach((file) => mocha.addFile(file)); + // if the project is of type "module" or if there's some ESM test file, + // we call loadFilesAsync to enable Mocha's ESM support + const projectPackageJson = await getProjectPackageJson(); + const isTypeModule = projectPackageJson.type === "module"; + const hasEsmTest = taskArgs.testFiles.some((file) => + file.endsWith(".mjs") + ); + if (isTypeModule || hasEsmTest) { + // Because of the way the ESM cache works, loadFilesAsync doesn't work + // correctly if used twice within the same process, so we throw an error + // in that case + if (testsAlreadyRun) { + throw new HardhatError( + ERRORS.BUILTIN_TASKS.TEST_TASK_ESM_TESTS_RUN_TWICE + ); + } + testsAlreadyRun = true; + + // This instructs Mocha to use the more verbose file loading infrastructure + // which supports both ESM and CJS + await mocha.loadFilesAsync(); + } + const testFailures = await new Promise((resolve) => { mocha.run(resolve); }); diff --git a/packages/hardhat-core/src/internal/core/config/config-loading.ts b/packages/hardhat-core/src/internal/core/config/config-loading.ts index dd948c3e8d..6f97a2811e 100644 --- a/packages/hardhat-core/src/internal/core/config/config-loading.ts +++ b/packages/hardhat-core/src/internal/core/config/config-loading.ts @@ -25,8 +25,21 @@ import { DEFAULT_SOLC_VERSION } from "./default-config"; const log = debug("hardhat:core:config"); function importCsjOrEsModule(filePath: string): any { - const imported = require(filePath); - return imported.default !== undefined ? imported.default : imported; + try { + const imported = require(filePath); + return imported.default !== undefined ? imported.default : imported; + } catch (e: any) { + if (e.code === "ERR_REQUIRE_ESM") { + throw new HardhatError( + ERRORS.GENERAL.ESM_PROJECT_WITHOUT_CJS_CONFIG, + {}, + e + ); + } + + // eslint-disable-next-line @nomiclabs/hardhat-internal-rules/only-hardhat-error + throw e; + } } export function resolveConfigPath(configPath: string | undefined) { diff --git a/packages/hardhat-core/src/internal/core/errors-list.ts b/packages/hardhat-core/src/internal/core/errors-list.ts index f03367ba76..212f482197 100644 --- a/packages/hardhat-core/src/internal/core/errors-list.ts +++ b/packages/hardhat-core/src/internal/core/errors-list.ts @@ -252,6 +252,16 @@ To avoid it, please delete both your node_modules and package-lock.json, and rei Note that you don't need to do this every time you install a new dependency, but please make sure to delete your node_modules every time you delete your package-lock.json.`, shouldBeReported: false, }, + ESM_PROJECT_WITHOUT_CJS_CONFIG: { + number: 19, + message: `Your project is an ESM project (you have "type": "module" set in your package.json) but your Hardhat config file uses a .js or .ts extension. + +Rename the file to use a .cjs to fix this problem.`, + title: "Hardhat config with .js or .ts extension in an ESM project", + description: + "Your project is an ESM project but your Hardhat config uses an .js or .ts extension. Hardhat config files cannot be an ES module. To fix this, rename your Hardhat config to use the .cjs extension.", + shouldBeReported: false, + }, }, NETWORK: { CONFIG_NOT_FOUND: { @@ -983,6 +993,14 @@ The first supported version is %firstSupportedVersion%`, Please use a newer, supported version.`, shouldBeReported: true, }, + TEST_TASK_ESM_TESTS_RUN_TWICE: { + number: 609, + message: `Your project uses ESM and you've programmatically run your tests twice. This is not supported yet.`, + title: "Running tests twice in an ESM project", + description: + 'You have run your tests twice programmatically and your project is an ESM project (you have `"type": "module"` in your `package.json`, or some of your files have an `.mjs` extension). This is not supported by Mocha yet.', + shouldBeReported: true, + }, }, ARTIFACTS: { NOT_FOUND: { diff --git a/packages/hardhat-core/src/internal/core/project-structure.ts b/packages/hardhat-core/src/internal/core/project-structure.ts index 459367907f..450173357d 100644 --- a/packages/hardhat-core/src/internal/core/project-structure.ts +++ b/packages/hardhat-core/src/internal/core/project-structure.ts @@ -6,12 +6,15 @@ import { getPackageRoot } from "../util/packageInfo"; import { HardhatError } from "./errors"; import { ERRORS } from "./errors-list"; + const JS_CONFIG_FILENAME = "hardhat.config.js"; +const CJS_CONFIG_FILENAME = "hardhat.config.cjs"; const TS_CONFIG_FILENAME = "hardhat.config.ts"; export function isCwdInsideProject() { return ( findUp.sync(TS_CONFIG_FILENAME) !== null || + findUp.sync(CJS_CONFIG_FILENAME) !== null || findUp.sync(JS_CONFIG_FILENAME) !== null ); } @@ -22,6 +25,11 @@ export function getUserConfigPath() { return tsConfigPath; } + const cjsConfigPath = findUp.sync(CJS_CONFIG_FILENAME); + if (cjsConfigPath !== null) { + return cjsConfigPath; + } + const pathToConfigFile = findUp.sync(JS_CONFIG_FILENAME); if (pathToConfigFile === null) { throw new HardhatError(ERRORS.GENERAL.NOT_INSIDE_PROJECT); diff --git a/packages/hardhat-core/src/internal/util/packageInfo.ts b/packages/hardhat-core/src/internal/util/packageInfo.ts index 1360bdb376..b2f678a8a4 100644 --- a/packages/hardhat-core/src/internal/util/packageInfo.ts +++ b/packages/hardhat-core/src/internal/util/packageInfo.ts @@ -17,6 +17,7 @@ export function getPackageRoot(): string { export interface PackageJson { name: string; version: string; + type?: "commonjs" | "module"; engines: { node: string; }; @@ -51,3 +52,17 @@ export function getHardhatVersion(): string { const packageJson = fsExtra.readJsonSync(packageJsonPath); return packageJson.version; } + +/** + * Return the contents of the package.json in the user's project + */ +export function getProjectPackageJson(): Promise { + const packageJsonPath = findup.sync("package.json"); + + assertHardhatInvariant( + packageJsonPath !== null, + "Expected a package.json file in the current directory or in an ancestor directory" + ); + + return fsExtra.readJson(packageJsonPath); +} diff --git a/packages/hardhat-toolbox/src/index.ts b/packages/hardhat-toolbox/src/index.ts index 3f6c5759a2..8efa0d2902 100644 --- a/packages/hardhat-toolbox/src/index.ts +++ b/packages/hardhat-toolbox/src/index.ts @@ -39,6 +39,7 @@ extendConfig((config, userConfig) => { // We don't generate types for js projects if (userConfig?.typechain?.dontOverrideCompile === undefined) { config.typechain.dontOverrideCompile = - config.paths.configFile.endsWith(".js"); + config.paths.configFile.endsWith(".js") || + config.paths.configFile.endsWith(".cjs"); } }); From 7d7c13e7e61fdcc9f5473efcea6635ad3813a838 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Fri, 6 Jan 2023 11:14:26 +0100 Subject: [PATCH 03/17] Add tests for esm/cjs --- .../hardhat-core/test/builtin-tasks/run.ts | 88 +++++- .../hardhat-core/test/builtin-tasks/test.ts | 298 +++++++++++++++++- .../esm-project-with-scripts/.gitignore | 2 + .../assert-hardhat-arguments.js | 5 + .../esm-project-with-scripts/async-script.js | 7 + .../esm-project-with-scripts/contracts/a.sol | 2 + .../env-var-script.js | 5 + .../failing-script.js | 3 + .../hardhat.config.cjs | 8 + .../esm-project-with-scripts/package.json | 3 + .../esm-project-with-scripts/params-script.js | 10 + .../successful-script.js | 5 + .../hardhat.config.cjs} | 0 .../bail-config-false-overriden/package.json | 3 + .../bail-config-false-overriden/test/test.js | 11 + .../bail/bail-config-false/hardhat.config.cjs | 10 + .../bail/bail-config-false/package.json | 3 + .../bail/bail-config-false/test/test.js | 11 + .../bail/bail-config-true/hardhat.config.cjs} | 0 .../bail/bail-config-true/package.json | 3 + .../bail/bail-config-true/test/test.js | 11 + .../bail/default/hardhat.config.cjs} | 0 .../esm-test-task/bail/default/package.json | 3 + .../esm-test-task/bail/default/test/test.js | 11 + .../bail/with-bail-flag/hardhat.config.cjs} | 0 .../bail/with-bail-flag/package.json | 3 + .../bail/with-bail-flag/test/test.js | 11 + .../failing-tests/hardhat.config.cjs | 9 + .../esm-test-task/failing-tests/package.json | 3 + .../esm-test-task/failing-tests/test/test.js | 13 + .../minimal-config/hardhat.config.cjs | 9 + .../esm-test-task/minimal-config/package.json | 3 + .../esm-test-task/minimal-config/test/test.js | 18 ++ .../mixed-test-files/hardhat.config.cjs | 9 + .../mixed-test-files/package.json | 3 + .../mixed-test-files/test/test.cjs | 7 + .../mixed-test-files/test/test.js | 7 + .../mixed-test-files/test/test.mjs | 7 + .../hardhat.config.cjs} | 0 .../package.json | 3 + .../test/check-parallel.js | 7 + .../parallel-config-false/hardhat.config.cjs | 10 + .../parallel-config-false/package.json | 3 + .../test/check-parallel.js | 7 + .../parallel-config-true/hardhat.config.cjs} | 0 .../parallel-config-true/package.json | 3 + .../test/check-parallel.js | 7 + .../parallel/hardhat.config.cjs | 9 + .../parallel-tests/parallel/package.json | 3 + .../parallel/test/check-parallel.js | 7 + .../parallel-tests/serial/hardhat.config.cjs | 9 + .../parallel-tests/serial/package.json | 3 + .../serial/test/check-parallel.js | 7 + .../run-tests-twice/hardhat.config.cjs | 16 + .../run-tests-twice/package.json | 3 + .../run-tests-twice/test/test.js | 18 ++ .../esm/cjs-config/contracts/Foo.sol | 4 + .../esm/cjs-config/hardhat.config.cjs | 10 + .../esm/cjs-config/package.json | 3 + .../esm/js-config/hardhat.config.js | 1 + .../esm/js-config/package.json | 3 + .../hardhat.config.js | 10 + .../config-bail-false-overriden/package.json | 1 + .../test/test.js | 0 .../bail/config-bail-false/hardhat.config.js | 10 + .../bail/config-bail-false/package.json | 1 + .../bail/config-bail-false/test/test.js | 11 + .../bail/config-bail-true/hardhat.config.js | 10 + .../bail/config-bail-true/package.json | 1 + .../bail/config-bail-true/test/test.js | 11 + .../default-with-bail-flag/hardhat.config.js | 9 + .../bail/default-with-bail-flag/package.json | 1 + .../bail/default-with-bail-flag/test/test.js | 11 + .../test-task/bail/default/hardhat.config.js | 9 + .../test-task/bail/default/package.json | 1 + .../test-task/bail/default/test/test.js | 11 + .../test-task/failing-tests/package.json | 1 + .../test-task/minimal-config/package.json | 1 + .../mixed-test-files/hardhat.config.js | 9 + .../test-task/mixed-test-files/package.json | 1 + .../test-task/mixed-test-files/test/test.cjs | 7 + .../test-task/mixed-test-files/test/test.js | 7 + .../test-task/mixed-test-files/test/test.mjs | 7 + .../hardhat.config.js | 10 + .../package.json | 1 + .../test/check-parallel.js | 0 .../parallel-config-false/hardhat.config.js | 10 + .../parallel-config-false/package.json | 1 + .../test/check-parallel.js | 7 + .../parallel-config-true/hardhat.config.js | 10 + .../parallel-config-true/package.json | 1 + .../test/check-parallel.js | 7 + .../parallel-tests/parallel/hardhat.config.js | 9 + .../parallel-tests/parallel/package.json | 1 + .../parallel/test/check-parallel.js | 7 + .../parallel-tests/serial/hardhat.config.js | 9 + .../parallel-tests/serial/package.json | 1 + .../serial/test/check-parallel.js | 7 + .../run-tests-twice-mjs/hardhat.config.js | 16 + .../run-tests-twice-mjs/package.json | 1 + .../run-tests-twice-mjs/test/test.js | 18 ++ .../run-tests-twice-mjs/test/test.mjs | 18 ++ .../run-tests-twice/hardhat.config.js | 16 + .../test-task/run-tests-twice/package.json | 1 + .../test-task/run-tests-twice/test/test.js | 18 ++ .../internal/core/config/config-loading.ts | 49 +++ .../test/internal/core/project-structure.ts | 20 ++ .../test/internal/util/scripts-runner.ts | 87 ++++- 108 files changed, 1183 insertions(+), 12 deletions(-) create mode 100644 packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/.gitignore create mode 100644 packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/assert-hardhat-arguments.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/async-script.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/contracts/a.sol create mode 100644 packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/env-var-script.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/failing-script.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/hardhat.config.cjs create mode 100644 packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/params-script.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/successful-script.js rename packages/hardhat-core/test/fixture-projects/{test-task/bail/hardhat.config-bail-false.js => esm-test-task/bail/bail-config-false-overriden/hardhat.config.cjs} (100%) create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false-overriden/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false-overriden/test/test.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false/hardhat.config.cjs create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false/test/test.js rename packages/hardhat-core/test/fixture-projects/{test-task/bail/hardhat.config-bail-true.js => esm-test-task/bail/bail-config-true/hardhat.config.cjs} (100%) create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-true/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-true/test/test.js rename packages/hardhat-core/test/fixture-projects/{test-task/bail/hardhat.config.js => esm-test-task/bail/default/hardhat.config.cjs} (100%) create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/bail/default/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/bail/default/test/test.js rename packages/hardhat-core/test/fixture-projects/{test-task/parallel-tests/hardhat.config.js => esm-test-task/bail/with-bail-flag/hardhat.config.cjs} (100%) create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/bail/with-bail-flag/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/bail/with-bail-flag/test/test.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/failing-tests/hardhat.config.cjs create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/failing-tests/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/failing-tests/test/test.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/minimal-config/hardhat.config.cjs create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/minimal-config/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/minimal-config/test/test.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/hardhat.config.cjs create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/test/test.cjs create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/test/test.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/test/test.mjs rename packages/hardhat-core/test/fixture-projects/{test-task/parallel-tests/hardhat.config-parallel-false.js => esm-test-task/parallel-tests/parallel-config-false-overriden/hardhat.config.cjs} (100%) create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false-overriden/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false-overriden/test/check-parallel.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false/hardhat.config.cjs create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false/test/check-parallel.js rename packages/hardhat-core/test/fixture-projects/{test-task/parallel-tests/hardhat.config-parallel-true.js => esm-test-task/parallel-tests/parallel-config-true/hardhat.config.cjs} (100%) create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-true/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-true/test/check-parallel.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel/hardhat.config.cjs create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel/test/check-parallel.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/serial/hardhat.config.cjs create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/serial/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/serial/test/check-parallel.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/run-tests-twice/hardhat.config.cjs create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/run-tests-twice/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm-test-task/run-tests-twice/test/test.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm/cjs-config/contracts/Foo.sol create mode 100644 packages/hardhat-core/test/fixture-projects/esm/cjs-config/hardhat.config.cjs create mode 100644 packages/hardhat-core/test/fixture-projects/esm/cjs-config/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/esm/js-config/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/esm/js-config/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false-overriden/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false-overriden/package.json rename packages/hardhat-core/test/fixture-projects/test-task/bail/{ => config-bail-false-overriden}/test/test.js (100%) create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false/test/test.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-true/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-true/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-true/test/test.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/bail/default-with-bail-flag/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/bail/default-with-bail-flag/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/bail/default-with-bail-flag/test/test.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/bail/default/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/bail/default/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/bail/default/test/test.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/failing-tests/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/minimal-config/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/test/test.cjs create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/test/test.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/test/test.mjs create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false-overriden/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false-overriden/package.json rename packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/{ => parallel-config-false-overriden}/test/check-parallel.js (100%) create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false/test/check-parallel.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-true/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-true/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-true/test/check-parallel.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel/test/check-parallel.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/serial/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/serial/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/serial/test/check-parallel.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/test/test.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/test/test.mjs create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice/package.json create mode 100644 packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice/test/test.js diff --git a/packages/hardhat-core/test/builtin-tasks/run.ts b/packages/hardhat-core/test/builtin-tasks/run.ts index 8bbc5561d6..4e864f36f3 100644 --- a/packages/hardhat-core/test/builtin-tasks/run.ts +++ b/packages/hardhat-core/test/builtin-tasks/run.ts @@ -8,7 +8,7 @@ import { useEnvironment } from "../helpers/environment"; import { expectHardhatErrorAsync } from "../helpers/errors"; import { useFixtureProject } from "../helpers/project"; -describe("run task", function () { +describe("run task (CJS)", function () { useFixtureProject("project-with-scripts"); useEnvironment(); @@ -93,3 +93,89 @@ describe("run task", function () { (process as any).exitCode = undefined; }); }); + +describe("run task (ESM)", function () { + useFixtureProject("esm-project-with-scripts"); + useEnvironment(); + + it("Should fail if a script doesn't exist", async function () { + await expectHardhatErrorAsync( + () => + this.env.run("run", { script: "./does-not-exist", noCompile: true }), + ERRORS.BUILTIN_TASKS.RUN_FILE_NOT_FOUND + ); + }); + + it("Should run the scripts to completion", async function () { + await this.env.run("run", { + script: "./async-script.js", + noCompile: true, + }); + + assert.equal(process.exitCode, 0); + (process as any).exitCode = undefined; + }); + + it("Should compile before running", async function () { + if (await fsExtra.pathExists("cache")) { + await fsExtra.remove("cache"); + } + + if (await fsExtra.pathExists("artifacts")) { + await fsExtra.remove("artifacts"); + } + + await this.env.run("run", { + script: "./successful-script.js", + }); + assert.equal(process.exitCode, 0); + (process as any).exitCode = undefined; + + const artifacts = new Artifacts(path.join(process.cwd(), "artifacts")); + const files = await artifacts.getArtifactPaths(); + const expectedFile = path.join( + process.cwd(), + "artifacts/contracts/a.sol/A.json" + ); + assert.sameMembers(files, [expectedFile]); + + await fsExtra.remove("artifacts"); + }); + + it("Shouldn't compile if asked not to", async function () { + if (await fsExtra.pathExists("cache")) { + await fsExtra.remove("cache"); + } + + if (await fsExtra.pathExists("artifacts")) { + await fsExtra.remove("artifacts"); + } + + await this.env.run("run", { + script: "./successful-script.js", + noCompile: true, + }); + assert.equal(process.exitCode, 0); + (process as any).exitCode = undefined; + + assert.isFalse(await fsExtra.pathExists("artifacts")); + }); + + it("Should return the script's status code on success", async function () { + await this.env.run("run", { + script: "./successful-script.js", + noCompile: true, + }); + assert.equal(process.exitCode, 0); + (process as any).exitCode = undefined; + }); + + it("Should return the script's status code on failure", async function () { + await this.env.run("run", { + script: "./failing-script.js", + noCompile: true, + }); + assert.notEqual(process.exitCode, 0); + (process as any).exitCode = undefined; + }); +}); diff --git a/packages/hardhat-core/test/builtin-tasks/test.ts b/packages/hardhat-core/test/builtin-tasks/test.ts index bc21f8477a..f448b572de 100644 --- a/packages/hardhat-core/test/builtin-tasks/test.ts +++ b/packages/hardhat-core/test/builtin-tasks/test.ts @@ -1,9 +1,20 @@ import { assert } from "chai"; +import { ERRORS } from "../../src/internal/core/errors-list"; import { useFixtureProject } from "../helpers/project"; import { useEnvironment } from "../helpers/environment"; - -describe("test task", function () { +import { expectHardhatErrorAsync } from "../helpers/errors"; + +// This file and the associated fixture projects have a lot of duplication. The +// reason is that some fixture projects use Mocha in ESM mode, which doesn't +// support cleaning the cache. +// +// To work around that, this suite uses a different +// fixture project for each test. There shouldn't be two `useFixtureProject` +// calls with the same argument, and each `it` should have its own fixture +// project. + +describe("test task (CJS)", function () { describe("default config project", function () { useFixtureProject("test-task/minimal-config"); useEnvironment(); @@ -33,9 +44,8 @@ describe("test task", function () { }); describe("parallel tests", function () { - useFixtureProject("test-task/parallel-tests"); - - describe("with the default config", function () { + describe("with the default config in serial mode", function () { + useFixtureProject("test-task/parallel-tests/serial"); useEnvironment(); it("should fail in serial mode", async function () { @@ -46,6 +56,11 @@ describe("test task", function () { assert.equal(process.exitCode, 1); (process as any).exitCode = undefined; }); + }); + + describe("with the default config in parallel mode", function () { + useFixtureProject("test-task/parallel-tests/parallel"); + useEnvironment(); it("should pass in parallel mode", async function () { await this.env.run("test", { @@ -59,7 +74,8 @@ describe("test task", function () { }); describe("when the config has parallel: true", function () { - useEnvironment("hardhat.config-parallel-true.js"); + useFixtureProject("test-task/parallel-tests/parallel-config-true"); + useEnvironment(); it("use parallel by default", async function () { await this.env.run("test", { @@ -72,7 +88,8 @@ describe("test task", function () { }); describe("when the config has parallel: false", function () { - useEnvironment("hardhat.config-parallel-false.js"); + useFixtureProject("test-task/parallel-tests/parallel-config-false"); + useEnvironment(); it("use serial by default", async function () { await this.env.run("test", { @@ -82,6 +99,13 @@ describe("test task", function () { assert.equal(process.exitCode, 1); (process as any).exitCode = undefined; }); + }); + + describe("when the config has parallel: false and it's overriden", function () { + useFixtureProject( + "test-task/parallel-tests/parallel-config-false-overriden" + ); + useEnvironment(); it("should be overridable", async function () { await this.env.run("test", { @@ -96,9 +120,225 @@ describe("test task", function () { }); describe("bail", function () { - useFixtureProject("test-task/bail"); + describe("with the default config and no --bail", function () { + useFixtureProject("test-task/bail/default"); + useEnvironment(); + + it("should have two failures if all tests are run", async function () { + await this.env.run("test", { + noCompile: true, + }); + + assert.equal(process.exitCode, 2); + (process as any).exitCode = undefined; + }); + }); + + describe("with the default config and no --bail", function () { + useFixtureProject("test-task/bail/default-with-bail-flag"); + useEnvironment(); + + it("should stop at the first failure if --bail is used", async function () { + await this.env.run("test", { + noCompile: true, + bail: true, + }); + + assert.equal(process.exitCode, 1); + (process as any).exitCode = undefined; + }); + }); + + describe("when the config has bail: true", function () { + useFixtureProject("test-task/bail/config-bail-true"); + useEnvironment(); + + it("use bail by default", async function () { + await this.env.run("test", { + noCompile: true, + }); + + assert.equal(process.exitCode, 1); + (process as any).exitCode = undefined; + }); + }); + + describe("when the config has bail: false", function () { + useFixtureProject("test-task/bail/config-bail-false"); + useEnvironment(); + + it("don't bail by default", async function () { + await this.env.run("test", { + noCompile: true, + }); + + assert.equal(process.exitCode, 2); + (process as any).exitCode = undefined; + }); + }); + + describe("when the config has bail: false and it's overriden", function () { + useFixtureProject("test-task/bail/config-bail-false-overriden"); + useEnvironment(); + + it("should be overridable", async function () { + await this.env.run("test", { + noCompile: true, + bail: true, + }); + + assert.equal(process.exitCode, 1); + (process as any).exitCode = undefined; + }); + }); + }); + + describe("mixed files", function () { + useFixtureProject("test-task/mixed-test-files"); + useEnvironment(); + + it("should run .js, .cjs and .mjs files", async function () { + await this.env.run("test", { + noCompile: true, + }); + + // each file has a single failing test, so the exit code should be 3 + assert.equal(process.exitCode, 3); + (process as any).exitCode = undefined; + }); + }); + + describe("running tests programmatically twice", function () { + useFixtureProject("test-task/run-tests-twice"); + useEnvironment(); + + it("should run tests twice without an error", async function () { + const result = await this.env.run("twice"); + + assert.isTrue(result); + }); + }); + + describe("running tests programmatically twice, one test is .mjs", function () { + useFixtureProject("test-task/run-tests-twice-mjs"); + useEnvironment(); + + it("should throw an error", async function () { + await expectHardhatErrorAsync(async () => { + await this.env.run("twice"); + }, ERRORS.BUILTIN_TASKS.TEST_TASK_ESM_TESTS_RUN_TWICE); + }); + }); +}); + +describe("test task (ESM)", function () { + describe("default config project", function () { + useFixtureProject("esm-test-task/minimal-config"); + useEnvironment(); + + it("should run tests", async function () { + await this.env.run("test", { + noCompile: true, + }); + + assert.equal(process.exitCode, 0); + (process as any).exitCode = undefined; + }); + }); + + describe("failing tests", function () { + useFixtureProject("esm-test-task/failing-tests"); + useEnvironment(); + + it("should have a return code equal to the number of failing tests", async function () { + await this.env.run("test", { + noCompile: true, + }); + + assert.equal(process.exitCode, 2); + (process as any).exitCode = undefined; + }); + }); + + describe("parallel tests", function () { + describe("with the default config in serial mode", function () { + useFixtureProject("esm-test-task/parallel-tests/serial"); + useEnvironment(); + + it("should fail in serial mode", async function () { + await this.env.run("test", { + noCompile: true, + }); + + assert.equal(process.exitCode, 1); + (process as any).exitCode = undefined; + }); + }); + + describe("with the default config in parallel mode", function () { + useFixtureProject("esm-test-task/parallel-tests/parallel"); + useEnvironment(); + + it("should pass in parallel mode", async function () { + await this.env.run("test", { + noCompile: true, + parallel: true, + }); + assert.equal(process.exitCode, 0); + (process as any).exitCode = undefined; + }); + }); + + describe("when the config has parallel: true", function () { + useFixtureProject("esm-test-task/parallel-tests/parallel-config-true"); + useEnvironment(); + + it("use parallel by default", async function () { + await this.env.run("test", { + noCompile: true, + }); + + assert.equal(process.exitCode, 0); + (process as any).exitCode = undefined; + }); + }); + + describe("when the config has parallel: false", function () { + useFixtureProject("esm-test-task/parallel-tests/parallel-config-false"); + useEnvironment(); + + it("use serial by default", async function () { + await this.env.run("test", { + noCompile: true, + }); + + assert.equal(process.exitCode, 1); + (process as any).exitCode = undefined; + }); + }); + + describe("when the config has parallel: false and it's overriden", function () { + useFixtureProject( + "esm-test-task/parallel-tests/parallel-config-false-overriden" + ); + useEnvironment(); + + it("should be overridable", async function () { + await this.env.run("test", { + noCompile: true, + parallel: true, + }); + + assert.equal(process.exitCode, 0); + (process as any).exitCode = undefined; + }); + }); + }); + + describe("bail", function () { describe("with the default config", function () { + useFixtureProject("esm-test-task/bail/default"); useEnvironment(); it("should have two failures if all tests are run", async function () { @@ -109,6 +349,11 @@ describe("test task", function () { assert.equal(process.exitCode, 2); (process as any).exitCode = undefined; }); + }); + + describe("with the default config", function () { + useFixtureProject("esm-test-task/bail/with-bail-flag"); + useEnvironment(); it("should stop at the first failure if --bail is used", async function () { await this.env.run("test", { @@ -122,7 +367,8 @@ describe("test task", function () { }); describe("when the config has bail: true", function () { - useEnvironment("hardhat.config-bail-true.js"); + useFixtureProject("esm-test-task/bail/bail-config-true"); + useEnvironment(); it("use bail by default", async function () { await this.env.run("test", { @@ -135,7 +381,8 @@ describe("test task", function () { }); describe("when the config has bail: false", function () { - useEnvironment("hardhat.config-bail-false.js"); + useFixtureProject("esm-test-task/bail/bail-config-false"); + useEnvironment(); it("don't bail by default", async function () { await this.env.run("test", { @@ -145,6 +392,11 @@ describe("test task", function () { assert.equal(process.exitCode, 2); (process as any).exitCode = undefined; }); + }); + + describe("when the config has bail: false and it's overriden", function () { + useFixtureProject("esm-test-task/bail/bail-config-false-overriden"); + useEnvironment(); it("should be overridable", async function () { await this.env.run("test", { @@ -157,4 +409,30 @@ describe("test task", function () { }); }); }); + + describe("mixed files", function () { + useFixtureProject("esm-test-task/mixed-test-files"); + useEnvironment(); + + it("should run .js, .cjs and .mjs files", async function () { + await this.env.run("test", { + noCompile: true, + }); + + // each file has a single failing test, so the exit code should be 3 + assert.equal(process.exitCode, 3); + (process as any).exitCode = undefined; + }); + }); + + describe("running tests programmatically twice", function () { + useFixtureProject("esm-test-task/run-tests-twice"); + useEnvironment(); + + it("should throw an error", async function () { + await expectHardhatErrorAsync(async () => { + await this.env.run("twice"); + }, ERRORS.BUILTIN_TASKS.TEST_TASK_ESM_TESTS_RUN_TWICE); + }); + }); }); diff --git a/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/.gitignore b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/.gitignore new file mode 100644 index 0000000000..3ad8c33935 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/.gitignore @@ -0,0 +1,2 @@ +/cache +/artifacts \ No newline at end of file diff --git a/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/assert-hardhat-arguments.js b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/assert-hardhat-arguments.js new file mode 100644 index 0000000000..806a9eb783 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/assert-hardhat-arguments.js @@ -0,0 +1,5 @@ +import * as process from "process"; + +if (hardhatArguments.network !== "custom") { + process.exit(1); +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/async-script.js b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/async-script.js new file mode 100644 index 0000000000..85b0cdcae0 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/async-script.js @@ -0,0 +1,7 @@ +import * as process from "process"; + +setTimeout(() => { + if (global.config === undefined || global.config.solidity === undefined) { + process.exit(123); + } +}, 100); diff --git a/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/contracts/a.sol b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/contracts/a.sol new file mode 100644 index 0000000000..19d44c5f96 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/contracts/a.sol @@ -0,0 +1,2 @@ +contract A {} + diff --git a/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/env-var-script.js b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/env-var-script.js new file mode 100644 index 0000000000..5cd51b8314 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/env-var-script.js @@ -0,0 +1,5 @@ +import * as process from "process"; + +if (process.env.TEST_ENV_VAR !== "test") { + process.exit(123); +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/failing-script.js b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/failing-script.js new file mode 100644 index 0000000000..912d01363e --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/failing-script.js @@ -0,0 +1,3 @@ +import * as process from "process"; + +process.exit(123); diff --git a/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/hardhat.config.cjs b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/hardhat.config.cjs new file mode 100644 index 0000000000..5b58e4b87a --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/hardhat.config.cjs @@ -0,0 +1,8 @@ +module.exports = { + solidity: "0.5.15", + networks: { + custom: { + url: "asd", + }, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/package.json b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/params-script.js b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/params-script.js new file mode 100644 index 0000000000..cd2627b95f --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/params-script.js @@ -0,0 +1,10 @@ +import * as process from "process"; + +if ( + process.argv.length !== 5 || + process.argv[2] !== "a" || + process.argv[3] !== "b" || + process.argv[4] !== "c" +) { + process.exit(12); +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/successful-script.js b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/successful-script.js new file mode 100644 index 0000000000..3d91e0fe56 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-project-with-scripts/successful-script.js @@ -0,0 +1,5 @@ +import * as process from "process"; + +if (global.config === undefined || global.config.solidity === undefined) { + process.exit(123123); +} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/hardhat.config-bail-false.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false-overriden/hardhat.config.cjs similarity index 100% rename from packages/hardhat-core/test/fixture-projects/test-task/bail/hardhat.config-bail-false.js rename to packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false-overriden/hardhat.config.cjs diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false-overriden/package.json b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false-overriden/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false-overriden/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false-overriden/test/test.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false-overriden/test/test.js new file mode 100644 index 0000000000..4437ccdae6 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false-overriden/test/test.js @@ -0,0 +1,11 @@ +import assert from "assert"; + +describe("test suite 1", function () { + it("should fail", async function () { + assert(false); + }); + + it("should also fail", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false/hardhat.config.cjs b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false/hardhat.config.cjs new file mode 100644 index 0000000000..a76ce88866 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false/hardhat.config.cjs @@ -0,0 +1,10 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + bail: false, + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false/package.json b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false/test/test.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false/test/test.js new file mode 100644 index 0000000000..4437ccdae6 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-false/test/test.js @@ -0,0 +1,11 @@ +import assert from "assert"; + +describe("test suite 1", function () { + it("should fail", async function () { + assert(false); + }); + + it("should also fail", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/hardhat.config-bail-true.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-true/hardhat.config.cjs similarity index 100% rename from packages/hardhat-core/test/fixture-projects/test-task/bail/hardhat.config-bail-true.js rename to packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-true/hardhat.config.cjs diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-true/package.json b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-true/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-true/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-true/test/test.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-true/test/test.js new file mode 100644 index 0000000000..4437ccdae6 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/bail-config-true/test/test.js @@ -0,0 +1,11 @@ +import assert from "assert"; + +describe("test suite 1", function () { + it("should fail", async function () { + assert(false); + }); + + it("should also fail", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/default/hardhat.config.cjs similarity index 100% rename from packages/hardhat-core/test/fixture-projects/test-task/bail/hardhat.config.js rename to packages/hardhat-core/test/fixture-projects/esm-test-task/bail/default/hardhat.config.cjs diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/default/package.json b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/default/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/default/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/default/test/test.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/default/test/test.js new file mode 100644 index 0000000000..4437ccdae6 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/default/test/test.js @@ -0,0 +1,11 @@ +import assert from "assert"; + +describe("test suite 1", function () { + it("should fail", async function () { + assert(false); + }); + + it("should also fail", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/with-bail-flag/hardhat.config.cjs similarity index 100% rename from packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/hardhat.config.js rename to packages/hardhat-core/test/fixture-projects/esm-test-task/bail/with-bail-flag/hardhat.config.cjs diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/with-bail-flag/package.json b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/with-bail-flag/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/with-bail-flag/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/with-bail-flag/test/test.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/with-bail-flag/test/test.js new file mode 100644 index 0000000000..4437ccdae6 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/bail/with-bail-flag/test/test.js @@ -0,0 +1,11 @@ +import assert from "assert"; + +describe("test suite 1", function () { + it("should fail", async function () { + assert(false); + }); + + it("should also fail", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/failing-tests/hardhat.config.cjs b/packages/hardhat-core/test/fixture-projects/esm-test-task/failing-tests/hardhat.config.cjs new file mode 100644 index 0000000000..6b6b617b59 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/failing-tests/hardhat.config.cjs @@ -0,0 +1,9 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/failing-tests/package.json b/packages/hardhat-core/test/fixture-projects/esm-test-task/failing-tests/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/failing-tests/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/failing-tests/test/test.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/failing-tests/test/test.js new file mode 100644 index 0000000000..866d825e91 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/failing-tests/test/test.js @@ -0,0 +1,13 @@ +import assert from "assert"; + +describe("test suite", function () { + it("should pass", async function () {}); + + it("should fail, 1", async function () { + assert(false); + }); + + it("should fail, 2", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/minimal-config/hardhat.config.cjs b/packages/hardhat-core/test/fixture-projects/esm-test-task/minimal-config/hardhat.config.cjs new file mode 100644 index 0000000000..6b6b617b59 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/minimal-config/hardhat.config.cjs @@ -0,0 +1,9 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/minimal-config/package.json b/packages/hardhat-core/test/fixture-projects/esm-test-task/minimal-config/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/minimal-config/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/minimal-config/test/test.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/minimal-config/test/test.js new file mode 100644 index 0000000000..26b3453344 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/minimal-config/test/test.js @@ -0,0 +1,18 @@ +import assert from "assert"; + +describe("test suite 2", function () { + it("should start with block number 0", async function () { + const blockNumber = await network.provider.send("eth_blockNumber"); + + assert(blockNumber === "0x0"); + + // send a tx to increase the block number + const [a] = await network.provider.send("eth_accounts"); + await network.provider.send("eth_sendTransaction", [ + { + from: a, + to: a, + }, + ]); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/hardhat.config.cjs b/packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/hardhat.config.cjs new file mode 100644 index 0000000000..6b6b617b59 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/hardhat.config.cjs @@ -0,0 +1,9 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/package.json b/packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/test/test.cjs b/packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/test/test.cjs new file mode 100644 index 0000000000..a7ef47e270 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/test/test.cjs @@ -0,0 +1,7 @@ +const assert = require("assert"); + +describe("test suite", function () { + it("should fail", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/test/test.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/test/test.js new file mode 100644 index 0000000000..3bdaacb121 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/test/test.js @@ -0,0 +1,7 @@ +import assert from "assert"; + +describe("test suite", function () { + it("should fail", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/test/test.mjs b/packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/test/test.mjs new file mode 100644 index 0000000000..3bdaacb121 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/mixed-test-files/test/test.mjs @@ -0,0 +1,7 @@ +import assert from "assert"; + +describe("test suite", function () { + it("should fail", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/hardhat.config-parallel-false.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false-overriden/hardhat.config.cjs similarity index 100% rename from packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/hardhat.config-parallel-false.js rename to packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false-overriden/hardhat.config.cjs diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false-overriden/package.json b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false-overriden/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false-overriden/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false-overriden/test/check-parallel.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false-overriden/test/check-parallel.js new file mode 100644 index 0000000000..d193ea14d8 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false-overriden/test/check-parallel.js @@ -0,0 +1,7 @@ +import assert from "assert"; + +describe("parallel tests", function () { + it("pass if run in parallel mode", async function () { + assert(process.env.MOCHA_WORKER_ID !== undefined); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false/hardhat.config.cjs b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false/hardhat.config.cjs new file mode 100644 index 0000000000..20bb0a7c18 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false/hardhat.config.cjs @@ -0,0 +1,10 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + parallel: false, + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false/package.json b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false/test/check-parallel.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false/test/check-parallel.js new file mode 100644 index 0000000000..d193ea14d8 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-false/test/check-parallel.js @@ -0,0 +1,7 @@ +import assert from "assert"; + +describe("parallel tests", function () { + it("pass if run in parallel mode", async function () { + assert(process.env.MOCHA_WORKER_ID !== undefined); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/hardhat.config-parallel-true.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-true/hardhat.config.cjs similarity index 100% rename from packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/hardhat.config-parallel-true.js rename to packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-true/hardhat.config.cjs diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-true/package.json b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-true/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-true/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-true/test/check-parallel.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-true/test/check-parallel.js new file mode 100644 index 0000000000..d193ea14d8 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel-config-true/test/check-parallel.js @@ -0,0 +1,7 @@ +import assert from "assert"; + +describe("parallel tests", function () { + it("pass if run in parallel mode", async function () { + assert(process.env.MOCHA_WORKER_ID !== undefined); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel/hardhat.config.cjs b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel/hardhat.config.cjs new file mode 100644 index 0000000000..6b6b617b59 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel/hardhat.config.cjs @@ -0,0 +1,9 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel/package.json b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel/test/check-parallel.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel/test/check-parallel.js new file mode 100644 index 0000000000..d193ea14d8 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/parallel/test/check-parallel.js @@ -0,0 +1,7 @@ +import assert from "assert"; + +describe("parallel tests", function () { + it("pass if run in parallel mode", async function () { + assert(process.env.MOCHA_WORKER_ID !== undefined); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/serial/hardhat.config.cjs b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/serial/hardhat.config.cjs new file mode 100644 index 0000000000..6b6b617b59 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/serial/hardhat.config.cjs @@ -0,0 +1,9 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/serial/package.json b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/serial/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/serial/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/serial/test/check-parallel.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/serial/test/check-parallel.js new file mode 100644 index 0000000000..d193ea14d8 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/parallel-tests/serial/test/check-parallel.js @@ -0,0 +1,7 @@ +import assert from "assert"; + +describe("parallel tests", function () { + it("pass if run in parallel mode", async function () { + assert(process.env.MOCHA_WORKER_ID !== undefined); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/run-tests-twice/hardhat.config.cjs b/packages/hardhat-core/test/fixture-projects/esm-test-task/run-tests-twice/hardhat.config.cjs new file mode 100644 index 0000000000..5c621b1ab2 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/run-tests-twice/hardhat.config.cjs @@ -0,0 +1,16 @@ +task("twice", async (_, hre) => { + await hre.run("test", { noCompile: true }); + await hre.run("test", { noCompile: true }); + + return true; +}); + +module.exports = { + solidity: "0.8.3", + mocha: { + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/run-tests-twice/package.json b/packages/hardhat-core/test/fixture-projects/esm-test-task/run-tests-twice/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/run-tests-twice/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm-test-task/run-tests-twice/test/test.js b/packages/hardhat-core/test/fixture-projects/esm-test-task/run-tests-twice/test/test.js new file mode 100644 index 0000000000..26b3453344 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm-test-task/run-tests-twice/test/test.js @@ -0,0 +1,18 @@ +import assert from "assert"; + +describe("test suite 2", function () { + it("should start with block number 0", async function () { + const blockNumber = await network.provider.send("eth_blockNumber"); + + assert(blockNumber === "0x0"); + + // send a tx to increase the block number + const [a] = await network.provider.send("eth_accounts"); + await network.provider.send("eth_sendTransaction", [ + { + from: a, + to: a, + }, + ]); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/esm/cjs-config/contracts/Foo.sol b/packages/hardhat-core/test/fixture-projects/esm/cjs-config/contracts/Foo.sol new file mode 100644 index 0000000000..5b48a4de59 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm/cjs-config/contracts/Foo.sol @@ -0,0 +1,4 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract Foo {} diff --git a/packages/hardhat-core/test/fixture-projects/esm/cjs-config/hardhat.config.cjs b/packages/hardhat-core/test/fixture-projects/esm/cjs-config/hardhat.config.cjs new file mode 100644 index 0000000000..d8c7dfd907 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm/cjs-config/hardhat.config.cjs @@ -0,0 +1,10 @@ +module.exports = { + solidity: "0.8.17", + networks: { + localhost: { + accounts: [ + "0xa95f9e3e7ae4e4865c5968828fe7c03fffa8a9f3bb52d36d26243f4c868ee166", + ], + }, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/esm/cjs-config/package.json b/packages/hardhat-core/test/fixture-projects/esm/cjs-config/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm/cjs-config/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/esm/js-config/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/esm/js-config/hardhat.config.js new file mode 100644 index 0000000000..f053ebf797 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm/js-config/hardhat.config.js @@ -0,0 +1 @@ +module.exports = {}; diff --git a/packages/hardhat-core/test/fixture-projects/esm/js-config/package.json b/packages/hardhat-core/test/fixture-projects/esm/js-config/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/esm/js-config/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false-overriden/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false-overriden/hardhat.config.js new file mode 100644 index 0000000000..a76ce88866 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false-overriden/hardhat.config.js @@ -0,0 +1,10 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + bail: false, + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false-overriden/package.json b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false-overriden/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false-overriden/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/test/test.js b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false-overriden/test/test.js similarity index 100% rename from packages/hardhat-core/test/fixture-projects/test-task/bail/test/test.js rename to packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false-overriden/test/test.js diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false/hardhat.config.js new file mode 100644 index 0000000000..a76ce88866 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false/hardhat.config.js @@ -0,0 +1,10 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + bail: false, + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false/package.json b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false/test/test.js b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false/test/test.js new file mode 100644 index 0000000000..eaa57843f3 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-false/test/test.js @@ -0,0 +1,11 @@ +const assert = require("assert"); + +describe("test suite 1", function () { + it("should fail", async function () { + assert(false); + }); + + it("should also fail", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-true/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-true/hardhat.config.js new file mode 100644 index 0000000000..1d29f9e35c --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-true/hardhat.config.js @@ -0,0 +1,10 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + bail: true, + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-true/package.json b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-true/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-true/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-true/test/test.js b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-true/test/test.js new file mode 100644 index 0000000000..eaa57843f3 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/bail/config-bail-true/test/test.js @@ -0,0 +1,11 @@ +const assert = require("assert"); + +describe("test suite 1", function () { + it("should fail", async function () { + assert(false); + }); + + it("should also fail", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/default-with-bail-flag/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/test-task/bail/default-with-bail-flag/hardhat.config.js new file mode 100644 index 0000000000..6b6b617b59 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/bail/default-with-bail-flag/hardhat.config.js @@ -0,0 +1,9 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/default-with-bail-flag/package.json b/packages/hardhat-core/test/fixture-projects/test-task/bail/default-with-bail-flag/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/bail/default-with-bail-flag/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/default-with-bail-flag/test/test.js b/packages/hardhat-core/test/fixture-projects/test-task/bail/default-with-bail-flag/test/test.js new file mode 100644 index 0000000000..eaa57843f3 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/bail/default-with-bail-flag/test/test.js @@ -0,0 +1,11 @@ +const assert = require("assert"); + +describe("test suite 1", function () { + it("should fail", async function () { + assert(false); + }); + + it("should also fail", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/default/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/test-task/bail/default/hardhat.config.js new file mode 100644 index 0000000000..6b6b617b59 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/bail/default/hardhat.config.js @@ -0,0 +1,9 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/default/package.json b/packages/hardhat-core/test/fixture-projects/test-task/bail/default/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/bail/default/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/bail/default/test/test.js b/packages/hardhat-core/test/fixture-projects/test-task/bail/default/test/test.js new file mode 100644 index 0000000000..eaa57843f3 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/bail/default/test/test.js @@ -0,0 +1,11 @@ +const assert = require("assert"); + +describe("test suite 1", function () { + it("should fail", async function () { + assert(false); + }); + + it("should also fail", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/failing-tests/package.json b/packages/hardhat-core/test/fixture-projects/test-task/failing-tests/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/failing-tests/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/minimal-config/package.json b/packages/hardhat-core/test/fixture-projects/test-task/minimal-config/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/minimal-config/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/hardhat.config.js new file mode 100644 index 0000000000..6b6b617b59 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/hardhat.config.js @@ -0,0 +1,9 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/package.json b/packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/test/test.cjs b/packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/test/test.cjs new file mode 100644 index 0000000000..a7ef47e270 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/test/test.cjs @@ -0,0 +1,7 @@ +const assert = require("assert"); + +describe("test suite", function () { + it("should fail", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/test/test.js b/packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/test/test.js new file mode 100644 index 0000000000..a7ef47e270 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/test/test.js @@ -0,0 +1,7 @@ +const assert = require("assert"); + +describe("test suite", function () { + it("should fail", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/test/test.mjs b/packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/test/test.mjs new file mode 100644 index 0000000000..3bdaacb121 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/mixed-test-files/test/test.mjs @@ -0,0 +1,7 @@ +import assert from "assert"; + +describe("test suite", function () { + it("should fail", async function () { + assert(false); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false-overriden/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false-overriden/hardhat.config.js new file mode 100644 index 0000000000..20bb0a7c18 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false-overriden/hardhat.config.js @@ -0,0 +1,10 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + parallel: false, + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false-overriden/package.json b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false-overriden/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false-overriden/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/test/check-parallel.js b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false-overriden/test/check-parallel.js similarity index 100% rename from packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/test/check-parallel.js rename to packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false-overriden/test/check-parallel.js diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false/hardhat.config.js new file mode 100644 index 0000000000..20bb0a7c18 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false/hardhat.config.js @@ -0,0 +1,10 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + parallel: false, + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false/package.json b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false/test/check-parallel.js b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false/test/check-parallel.js new file mode 100644 index 0000000000..bd07fe7176 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-false/test/check-parallel.js @@ -0,0 +1,7 @@ +const assert = require("assert"); + +describe("parallel tests", function () { + it("pass if run in parallel mode", async function () { + assert(process.env.MOCHA_WORKER_ID !== undefined); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-true/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-true/hardhat.config.js new file mode 100644 index 0000000000..106ddad54d --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-true/hardhat.config.js @@ -0,0 +1,10 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + parallel: true, + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-true/package.json b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-true/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-true/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-true/test/check-parallel.js b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-true/test/check-parallel.js new file mode 100644 index 0000000000..bd07fe7176 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel-config-true/test/check-parallel.js @@ -0,0 +1,7 @@ +const assert = require("assert"); + +describe("parallel tests", function () { + it("pass if run in parallel mode", async function () { + assert(process.env.MOCHA_WORKER_ID !== undefined); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel/hardhat.config.js new file mode 100644 index 0000000000..6b6b617b59 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel/hardhat.config.js @@ -0,0 +1,9 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel/package.json b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel/test/check-parallel.js b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel/test/check-parallel.js new file mode 100644 index 0000000000..bd07fe7176 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/parallel/test/check-parallel.js @@ -0,0 +1,7 @@ +const assert = require("assert"); + +describe("parallel tests", function () { + it("pass if run in parallel mode", async function () { + assert(process.env.MOCHA_WORKER_ID !== undefined); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/serial/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/serial/hardhat.config.js new file mode 100644 index 0000000000..6b6b617b59 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/serial/hardhat.config.js @@ -0,0 +1,9 @@ +module.exports = { + solidity: "0.8.3", + mocha: { + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/serial/package.json b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/serial/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/serial/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/serial/test/check-parallel.js b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/serial/test/check-parallel.js new file mode 100644 index 0000000000..bd07fe7176 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/parallel-tests/serial/test/check-parallel.js @@ -0,0 +1,7 @@ +const assert = require("assert"); + +describe("parallel tests", function () { + it("pass if run in parallel mode", async function () { + assert(process.env.MOCHA_WORKER_ID !== undefined); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/hardhat.config.js new file mode 100644 index 0000000000..5c621b1ab2 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/hardhat.config.js @@ -0,0 +1,16 @@ +task("twice", async (_, hre) => { + await hre.run("test", { noCompile: true }); + await hre.run("test", { noCompile: true }); + + return true; +}); + +module.exports = { + solidity: "0.8.3", + mocha: { + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/package.json b/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/test/test.js b/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/test/test.js new file mode 100644 index 0000000000..126428887d --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/test/test.js @@ -0,0 +1,18 @@ +const assert = require("assert"); + +describe("test suite 2", function () { + it("should start with block number 0", async function () { + const blockNumber = await network.provider.send("eth_blockNumber"); + + assert(blockNumber === "0x0"); + + // send a tx to increase the block number + const [a] = await network.provider.send("eth_accounts"); + await network.provider.send("eth_sendTransaction", [ + { + from: a, + to: a, + }, + ]); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/test/test.mjs b/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/test/test.mjs new file mode 100644 index 0000000000..26b3453344 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice-mjs/test/test.mjs @@ -0,0 +1,18 @@ +import assert from "assert"; + +describe("test suite 2", function () { + it("should start with block number 0", async function () { + const blockNumber = await network.provider.send("eth_blockNumber"); + + assert(blockNumber === "0x0"); + + // send a tx to increase the block number + const [a] = await network.provider.send("eth_accounts"); + await network.provider.send("eth_sendTransaction", [ + { + from: a, + to: a, + }, + ]); + }); +}); diff --git a/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice/hardhat.config.js new file mode 100644 index 0000000000..5c621b1ab2 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice/hardhat.config.js @@ -0,0 +1,16 @@ +task("twice", async (_, hre) => { + await hre.run("test", { noCompile: true }); + await hre.run("test", { noCompile: true }); + + return true; +}); + +module.exports = { + solidity: "0.8.3", + mocha: { + // disable test output of the fixture so that + // the output of the fixture isn't mixed with + // the output of the hardhat tests + reporter: function () {}, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice/package.json b/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice/test/test.js b/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice/test/test.js new file mode 100644 index 0000000000..126428887d --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/test-task/run-tests-twice/test/test.js @@ -0,0 +1,18 @@ +const assert = require("assert"); + +describe("test suite 2", function () { + it("should start with block number 0", async function () { + const blockNumber = await network.provider.send("eth_blockNumber"); + + assert(blockNumber === "0x0"); + + // send a tx to increase the block number + const [a] = await network.provider.send("eth_accounts"); + await network.provider.send("eth_sendTransaction", [ + { + from: a, + to: a, + }, + ]); + }); +}); diff --git a/packages/hardhat-core/test/internal/core/config/config-loading.ts b/packages/hardhat-core/test/internal/core/config/config-loading.ts index 3e9a11a4b4..da1ac02507 100644 --- a/packages/hardhat-core/test/internal/core/config/config-loading.ts +++ b/packages/hardhat-core/test/internal/core/config/config-loading.ts @@ -36,6 +36,18 @@ describe("config loading", function () { }); }); + describe("can load CJS config path inside an esm project", function () { + useFixtureProject("esm/cjs-config"); + useEnvironment(); + + it("should load the default config if none is given", function () { + assert.isDefined(this.env.config.networks.localhost); + assert.deepEqual(this.env.config.networks.localhost.accounts, [ + "0xa95f9e3e7ae4e4865c5968828fe7c03fffa8a9f3bb52d36d26243f4c868ee166", + ]); + }); + }); + describe("Config validation", function () { describe("When the config is invalid", function () { useFixtureProject("invalid-config"); @@ -508,4 +520,41 @@ Hardhat plugin instead.` ); }); }); + + describe("ESM project", function () { + describe(".js config file", function () { + useFixtureProject("esm/js-config"); + + beforeEach(function () { + HardhatContext.createHardhatContext(); + }); + + afterEach(function () { + resetHardhatContext(); + }); + + it("Should throw the right error", function () { + expectHardhatError( + () => loadConfigAndTasks(), + ERRORS.GENERAL.ESM_PROJECT_WITHOUT_CJS_CONFIG + ); + }); + }); + + describe(".cjs config file", function () { + useFixtureProject("esm/cjs-config"); + + beforeEach(function () { + HardhatContext.createHardhatContext(); + }); + + afterEach(function () { + resetHardhatContext(); + }); + + it("Should not throw", function () { + loadConfigAndTasks(); + }); + }); + }); }); diff --git a/packages/hardhat-core/test/internal/core/project-structure.ts b/packages/hardhat-core/test/internal/core/project-structure.ts index e8fd1f0bc0..8dddb53eea 100644 --- a/packages/hardhat-core/test/internal/core/project-structure.ts +++ b/packages/hardhat-core/test/internal/core/project-structure.ts @@ -71,6 +71,26 @@ describe("project structure", () => { }); }); }); + + describe("Inside an ESM project", () => { + useFixtureProject("esm/cjs-config"); + let configPath: string; + + before("get root path", async () => { + configPath = await getRealPath( + path.join(process.cwd(), "hardhat.config.cjs") + ); + }); + + it("should work from the project root", () => { + assert.equal(getUserConfigPath(), configPath); + }); + + it("should work from deeper inside the project", () => { + process.chdir("contracts"); + assert.equal(getUserConfigPath(), configPath); + }); + }); }); describe("getRecommendedGitIgnore", () => { diff --git a/packages/hardhat-core/test/internal/util/scripts-runner.ts b/packages/hardhat-core/test/internal/util/scripts-runner.ts index 2c3ea1aa56..238a96ea0c 100644 --- a/packages/hardhat-core/test/internal/util/scripts-runner.ts +++ b/packages/hardhat-core/test/internal/util/scripts-runner.ts @@ -7,7 +7,7 @@ import { import { useEnvironment } from "../../helpers/environment"; import { useFixtureProject } from "../../helpers/project"; -describe("Scripts runner", function () { +describe("Scripts runner (CJS)", function () { useFixtureProject("project-with-scripts"); it("Should pass params to the script", async function () { @@ -91,3 +91,88 @@ describe("Scripts runner", function () { }); }); }); + +describe("Scripts runner (ESM)", function () { + useFixtureProject("esm-project-with-scripts"); + + it("Should pass params to the script", async function () { + const [statusCodeWithScriptParams, statusCodeWithNoParams] = + await Promise.all([ + runScript("./params-script.js", ["a", "b", "c"]), + runScript("./params-script.js"), + ]); + + assert.equal(statusCodeWithScriptParams, 0); + + // We check here that the script is correctly testing this: + assert.notEqual(statusCodeWithNoParams, 0); + }); + + it("Should run the script to completion", async function () { + const before = new Date(); + const status = await runScript("./async-script.js"); + assert.equal(status, 123); + const after = new Date(); + + assert.isAtLeast(after.getTime() - before.getTime(), 100); + }); + + it("Should resolve to the status code of the script run", async function () { + assert.deepEqual(await runScript("./failing-script.js"), 123); + }); + + it("Should pass env variables to the script", async function () { + const [statusCodeWithEnvVars, statusCodeWithNoEnvArgs] = await Promise.all([ + runScript("./env-var-script.js", [], [], { + TEST_ENV_VAR: "test", + }), + runScript("./env-var-script.js"), + ]); + + assert.equal( + statusCodeWithEnvVars, + 0, + "Status code with env vars should be 0" + ); + + assert.notEqual( + statusCodeWithNoEnvArgs, + 0, + "Status code with no env vars should not be 0" + ); + }); + + describe("runWithHardhat", function () { + useEnvironment(); + + it("Should load hardhat/register successfully", async function () { + const [statusCodeWithHardhat, statusCodeWithoutHardhat] = + await Promise.all([ + runScriptWithHardhat( + this.env.hardhatArguments, + "./successful-script.js" + ), + runScript("./successful-script.js"), + ]); + + assert.equal(statusCodeWithHardhat, 0); + + // We check here that the script is correctly testing this: + assert.notEqual(statusCodeWithoutHardhat, 0); + }); + + it("Should forward all the hardhat arguments", async function () { + // This is only for testing purposes, as we can't set a hardhat argument + // as the CLA does, and env variables always get forwarded to child + // processes + this.env.hardhatArguments.network = "custom"; + + const statusCode = await runScriptWithHardhat( + this.env.hardhatArguments, + "./assert-hardhat-arguments.js" + ); + + assert.equal(statusCode, 0); + }); + }); +}); From 38ed85d86ac043f99559f2150e87e7685bc3bdaa Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Fri, 6 Jan 2023 11:15:22 +0100 Subject: [PATCH 04/17] Improve project creation and add esm sample project --- .../sample-projects/javascript-esm/LICENSE.md | 11 ++ .../sample-projects/javascript-esm/README.md | 13 ++ .../javascript-esm/contracts/Lock.sol | 34 +++++ .../javascript-esm/hardhat.config.cjs | 6 + .../javascript-esm/scripts/deploy.js | 31 ++++ .../javascript-esm/test/Lock.js | 123 ++++++++++++++++ .../src/internal/cli/project-creation.ts | 133 ++++++++++++++---- .../src/internal/core/errors-list.ts | 7 + 8 files changed, 332 insertions(+), 26 deletions(-) create mode 100644 packages/hardhat-core/sample-projects/javascript-esm/LICENSE.md create mode 100644 packages/hardhat-core/sample-projects/javascript-esm/README.md create mode 100644 packages/hardhat-core/sample-projects/javascript-esm/contracts/Lock.sol create mode 100644 packages/hardhat-core/sample-projects/javascript-esm/hardhat.config.cjs create mode 100644 packages/hardhat-core/sample-projects/javascript-esm/scripts/deploy.js create mode 100644 packages/hardhat-core/sample-projects/javascript-esm/test/Lock.js diff --git a/packages/hardhat-core/sample-projects/javascript-esm/LICENSE.md b/packages/hardhat-core/sample-projects/javascript-esm/LICENSE.md new file mode 100644 index 0000000000..c539a505b4 --- /dev/null +++ b/packages/hardhat-core/sample-projects/javascript-esm/LICENSE.md @@ -0,0 +1,11 @@ +# License + +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. + +In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to [https://unlicense.org](https://unlicense.org) diff --git a/packages/hardhat-core/sample-projects/javascript-esm/README.md b/packages/hardhat-core/sample-projects/javascript-esm/README.md new file mode 100644 index 0000000000..e9dd5f3485 --- /dev/null +++ b/packages/hardhat-core/sample-projects/javascript-esm/README.md @@ -0,0 +1,13 @@ +# Sample Hardhat Project + +This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract. + +Try running some of the following tasks: + +```shell +npx hardhat help +npx hardhat test +REPORT_GAS=true npx hardhat test +npx hardhat node +npx hardhat run scripts/deploy.js +``` diff --git a/packages/hardhat-core/sample-projects/javascript-esm/contracts/Lock.sol b/packages/hardhat-core/sample-projects/javascript-esm/contracts/Lock.sol new file mode 100644 index 0000000000..50935f61fd --- /dev/null +++ b/packages/hardhat-core/sample-projects/javascript-esm/contracts/Lock.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.9; + +// Uncomment this line to use console.log +// import "hardhat/console.sol"; + +contract Lock { + uint public unlockTime; + address payable public owner; + + event Withdrawal(uint amount, uint when); + + constructor(uint _unlockTime) payable { + require( + block.timestamp < _unlockTime, + "Unlock time should be in the future" + ); + + unlockTime = _unlockTime; + owner = payable(msg.sender); + } + + function withdraw() public { + // Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal + // console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp); + + require(block.timestamp >= unlockTime, "You can't withdraw yet"); + require(msg.sender == owner, "You aren't the owner"); + + emit Withdrawal(address(this).balance, block.timestamp); + + owner.transfer(address(this).balance); + } +} diff --git a/packages/hardhat-core/sample-projects/javascript-esm/hardhat.config.cjs b/packages/hardhat-core/sample-projects/javascript-esm/hardhat.config.cjs new file mode 100644 index 0000000000..86913e7054 --- /dev/null +++ b/packages/hardhat-core/sample-projects/javascript-esm/hardhat.config.cjs @@ -0,0 +1,6 @@ +require("@nomicfoundation/hardhat-toolbox"); + +/** @type import('hardhat/config').HardhatUserConfig */ +module.exports = { + solidity: "0.8.17", +}; diff --git a/packages/hardhat-core/sample-projects/javascript-esm/scripts/deploy.js b/packages/hardhat-core/sample-projects/javascript-esm/scripts/deploy.js new file mode 100644 index 0000000000..36f6f4f22b --- /dev/null +++ b/packages/hardhat-core/sample-projects/javascript-esm/scripts/deploy.js @@ -0,0 +1,31 @@ +// We require the Hardhat Runtime Environment explicitly here. This is optional +// but useful for running the script in a standalone fashion through `node