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

istanbul code coverage generation plugin #9248

Open
rschoenbichler opened this issue Sep 14, 2023 · 4 comments
Open

istanbul code coverage generation plugin #9248

rschoenbichler opened this issue Sep 14, 2023 · 4 comments

Comments

@rschoenbichler
Copy link

🙋 feature request

A transformer plugin that instruments the build to record code coverage in an istanbul.js compatible format

🤔 Expected Behavior

include via .parcelrc transformer section

😯 Current Behavior

not present

💁 Possible Solution

After some local trials, the istanbul-lib-instrumentation transformer always fails with a don't know how to turn this value into a node error. I've not found any other library so far for code coverage augmentation.

🔦 Context

I'm trying to augment a react/typescript/esnext application to retrieve code coverage information during runtime.

💻 Examples

import { createInstrumenter } from "istanbul-lib-instrument";
import { Transformer } from "@parcel/plugin";

const parcelInstrumenter = new Transformer({
    async transform(p) {
	    const instrumenter = createInstrumenter({ produceSourceMap: true, esModules: true });
	    const codeIn = await p.asset.getCode();
	    const mapIn = await p.asset.getMap();

	    const instrumented = instrumenter.instrumentSync(codeIn, p.asset.filePath, mapIn);
	    p.asset.setCode(instrumented);
	    p.asset.setMap(instrumenter.sourceMap);
	    
	    return [p.asset];
    },
});

export default parcelInstrumenter;
@mischnic
Copy link
Member

That sounds like a good third-party plugin.
What problem did you have with the plugin code you posted?

@rschoenbichler
Copy link
Author

That sounds like a good third-party plugin.

Absolutely, I just think that the parcel eco-system as a whole would benefit from this feature. So the awareness on the parcel side makes sense to me.

What problem did you have with the plugin code you posted?

I was trying to instrument a react / typescript / es-next module application. I've added the transformer as last step to the tsx transformer pipeline. The instrumentation failed in some deep recursive stack in the istanbul code traversal with a meaningless "can't turn this into a node" failure.

I know this is not parcels responsibility.
Looking at the plugin I've posted, I think the code and the transformer API make sense.
I just don't know where to go from here.
Maybe istanbul isn't even a viable option because it is nested too deep in the babel ages.
Which is why I thought reaching out to you makes sense, and maybe this is something that parcel want's to push as well and take it on your own agenda too?

@mischnic
Copy link
Member

mischnic commented Sep 19, 2023

That transformer plugin should work.

I've added the transformer as last step to the tsx transformer pipeline.

Try putting it at the start of the pipeline instead.

Which is why I thought reaching out to you makes sense, and maybe this is something that parcel want's to push as well and take it on your own agenda too?

No, we already have quite few people working on Parcel itself.

@rschoenbichler
Copy link
Author

Putting it to the start causes Istanbul to fail at the first typescript specific code segment (in my case a generic type)

@github-actions github-actions bot added the Stale Inactive issues label May 6, 2024
@parcel-bundler parcel-bundler deleted a comment from github-actions bot May 6, 2024
@mischnic mischnic added 🙋‍♀️ Feature and removed Stale Inactive issues labels May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants