Skip to content

get/set InstrumentationData not contains all needed info #801

Open
@wighawag

Description

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/

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions