task-test-get-files.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. const { internalTask } = require('hardhat/config');
  2. const { TASK_TEST_GET_TEST_FILES } = require('hardhat/builtin-tasks/task-names');
  3. // Modifies `hardhat test` to skip the proxy tests after proxies are removed by the transpiler for upgradeability.
  4. internalTask(TASK_TEST_GET_TEST_FILES).setAction(async ({ testFiles }, { config }) => {
  5. if (testFiles.length !== 0) {
  6. return testFiles;
  7. }
  8. const globAsync = require('glob');
  9. const path = require('path');
  10. const { promises: fs } = require('fs');
  11. const { promisify } = require('util');
  12. const glob = promisify(globAsync);
  13. const hasProxies = await fs
  14. .access(path.join(config.paths.sources, 'proxy/Proxy.sol'))
  15. .then(() => true)
  16. .catch(() => false);
  17. return await glob(path.join(config.paths.tests, '**/*.js'), {
  18. ignore: hasProxies
  19. ? []
  20. : [
  21. 'proxy/beacon/BeaconProxy.test.js',
  22. 'proxy/beacon/UpgradeableBeacon.test.js',
  23. 'proxy/ERC1967/ERC1967Proxy.test.js',
  24. 'proxy/transparent/ProxyAdmin.test.js',
  25. 'proxy/transparent/TransparentUpgradeableProxy.test.js',
  26. 'proxy/utils/UUPSUpgradeable.test.js',
  27. ].map(p => path.join(config.paths.tests, p)),
  28. });
  29. });