gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 786 forks source link

instrumenting code on the fly #855

Closed ORESoftware closed 6 years ago

ORESoftware commented 6 years ago

say we have an Express server:

app.use(function(req,res,next){
    const k = cp.spawn('istanbul instrument');
    fs.createReadStream('foo.js').pipe(k.stdin).pipe(res);
});

is there a way to instrument a file like this on the fly, and serve it to the browser?

ORESoftware commented 6 years ago

I asked a question on SO about this too: https://stackoverflow.com/questions/47880168/instrumenting-files-on-the-fly-with-istanbul

ORESoftware commented 6 years ago

I realize this is possible just by doing this:

app.use(function(req,res,next){
    const k = cp.spawn('istanbul instrument foo.js');
    k.stdout.pipe(res);
});