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

get/set InstrumentationData not contains all needed info #801

Open
wighawag opened this issue Jul 2, 2023 · 0 comments
Open

get/set InstrumentationData not contains all needed info #801

wighawag opened this issue Jul 2, 2023 · 0 comments

Comments

@wighawag
Copy link

wighawag commented Jul 2, 2023

I was trying to use solidity-coverage outside of a pure hardhat project (see #798) and my setup require the instrumented compilation to run in its own process before I execute the tests

I was thinking setInstrumentationData would allow me to have all the info I need once compilation is done

The idea was to perform the instrucmentation and compile the resulting contracts in one process
This process would do

...
let {targets, skipped} = utils.assembleFiles(config, skipFiles);
targets = api.instrument(targets);
...
const data = api.getInstrumentationData();
fs.writeFileSync('coverage-data.json', JSON.stringify(data, null, 2));

and then when I execute the test, I load the data back

...
const data = JSON.parse(fs.readFileSync('coverage-data.json', 'utf-8'));
api.setInstrumentationData(data);

Unfortunately it does not save the data set here :

this.coverage.addContract(instrumented, target.canonicalPath);

I thus need to call instrument again and hope I am using the exact same data as the one used in the compilation step

Maybe I am doing something wrong ? or should getInstrumentationData gives also what coverage.js set ?

Edit:

I would probably need another process to be executed at the end of the test so I would need the following

const data = JSON.parse(fs.readFileSync('coverage-data.json', 'utf-8'));
api.setInstrumentationData(data);

to also work after the test have computed the hits, etc.. and get that info there

More edit:
This is currently how I handle it : 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

1 participant