Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ability to run coverage against a external test runner #798

Open
wighawag opened this issue Jun 7, 2023 · 2 comments
Open

ability to run coverage against a external test runner #798

wighawag opened this issue Jun 7, 2023 · 2 comments

Comments

@wighawag
Copy link

wighawag commented Jun 7, 2023

I am currently using vitest for my test

it use hardhat environment by simply importing hardhat,

Now if I install soldiity-coverage as plugin, it seems I need to make use of hardhat test task which does not let me use my vitest tests.

Is there a way to let the coverage be executed against my external test ?

Ideally I would like that to happen in memory but if that require launching a hardhat node, that would be fine enough

Note: I tried to execute vitest inside hardhat via overriding the TEST task but could not get it working, probably due to cjs / esm

@cgewecke
Copy link
Member

cgewecke commented Jun 8, 2023

@wighawag Is it impossible to launch vitest from a task? e.g it's not a problem specifically with overriding "test"?

solidity-coverage attaches to the in-memory provider to watch the test execution trace. It won't work with an independent node. I don't know enough about vitest to understand what should be done but if you have an example I could look at am happy to check it out.

In principle it should be possible to use the internal API solidity-coverage's own task uses to get something working around any test framework as long as it provides hooks for starting and finishing the test suite. (The API docs are a little inaccurate - they predate the existence of the hardhat client)

If you can launch vitest from a hardhat task, I'd suggest stealing all the code in the coverage task and adapting it to launch vitest somehow...

@wighawag
Copy link
Author

wighawag commented Jul 3, 2023

I managed to get something working: https://github.com/wighawag/vitest-solidity-coverage/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants