From dfef6a68ee18dbd2e1f5a099061a3b8a0e404485 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Fri, 19 May 2023 23:49:23 +0200 Subject: [PATCH] Fix error when running hardhat test with parameters (#4265) --- hardhat/task-test-get-files.js | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/hardhat/task-test-get-files.js b/hardhat/task-test-get-files.js index 896bf1274af..108f40a42c0 100644 --- a/hardhat/task-test-get-files.js +++ b/hardhat/task-test-get-files.js @@ -3,33 +3,23 @@ const { TASK_TEST_GET_TEST_FILES } = require('hardhat/builtin-tasks/task-names') // Modifies `hardhat test` to skip the proxy tests after proxies are removed by the transpiler for upgradeability. -internalTask(TASK_TEST_GET_TEST_FILES).setAction(async ({ testFiles }, { config }) => { - if (testFiles.length !== 0) { - return testFiles; - } - - const globAsync = require('glob'); +internalTask(TASK_TEST_GET_TEST_FILES).setAction(async (args, hre, runSuper) => { const path = require('path'); const { promises: fs } = require('fs'); - const { promisify } = require('util'); - - const glob = promisify(globAsync); const hasProxies = await fs - .access(path.join(config.paths.sources, 'proxy/Proxy.sol')) + .access(path.join(hre.config.paths.sources, 'proxy/Proxy.sol')) .then(() => true) .catch(() => false); - return await glob(path.join(config.paths.tests, '**/*.js'), { - ignore: hasProxies - ? [] - : [ - 'proxy/beacon/BeaconProxy.test.js', - 'proxy/beacon/UpgradeableBeacon.test.js', - 'proxy/ERC1967/ERC1967Proxy.test.js', - 'proxy/transparent/ProxyAdmin.test.js', - 'proxy/transparent/TransparentUpgradeableProxy.test.js', - 'proxy/utils/UUPSUpgradeable.test.js', - ].map(p => path.join(config.paths.tests, p)), - }); + const ignoredIfProxy = [ + 'proxy/beacon/BeaconProxy.test.js', + 'proxy/beacon/UpgradeableBeacon.test.js', + 'proxy/ERC1967/ERC1967Proxy.test.js', + 'proxy/transparent/ProxyAdmin.test.js', + 'proxy/transparent/TransparentUpgradeableProxy.test.js', + 'proxy/utils/UUPSUpgradeable.test.js', + ].map(p => path.join(hre.config.paths.tests, p)); + + return (await runSuper(args)).filter(file => hasProxies || !ignoredIfProxy.includes(file)); });