From b9e4677bc0ee23c6bcff4044e5ae726b782281d4 Mon Sep 17 00:00:00 2001 From: Alex Rea Date: Wed, 3 Jul 2024 14:42:31 +0100 Subject: [PATCH] Error if solcoverjs passed but nonexistent --- plugins/resources/plugin.utils.js | 5 ++++- test/integration/errors.js | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/plugins/resources/plugin.utils.js b/plugins/resources/plugin.utils.js index 9d333db..04c6632 100644 --- a/plugins/resources/plugin.utils.js +++ b/plugins/resources/plugin.utils.js @@ -222,7 +222,10 @@ function loadSolcoverJS(config={}){ throw new Error(error) } - // Config is optional + // Config is optional, but if passed and not found, error + } else if (config.solcoverjs) { + const message = ui.generate('solcoverjs-fail') + " --solcoverjs flag was set but no file was found"; + throw new Error(message); } else { coverageConfig = {}; } diff --git a/test/integration/errors.js b/test/integration/errors.js index b78b268..d5938f2 100644 --- a/test/integration/errors.js +++ b/test/integration/errors.js @@ -46,6 +46,26 @@ describe('Hardhat Plugin: error cases', function() { verify.coverageNotGenerated(hardhatConfig); }) + it('.solcover.js is not found', async function(){ + const taskArgs = { + solcoverjs: "./file-that-does-not-exist.js" + } + + mock.install('Simple', 'simple.js', solcoverConfig); + mock.hardhatSetupEnv(this); + + try { + await this.env.run("coverage", taskArgs); + assert.fail() + } catch (err) { + assert( + err.message.includes('--solcoverjs flag was set but no file was found'), + `Should error if --solcoverjs passed but not found: ${err.message}` + ); + } + }) + + it('.solcover.js has incorrectly formatted option', async function(){ solcoverConfig.port = "Antwerpen";