gotwarlost / istanbul-middleware

Connect middleware for server side code coverage using istanbul
Other
179 stars 96 forks source link

Async version of instrumentSync() #46

Open ORESoftware opened 7 years ago

ORESoftware commented 7 years ago

Hey, this is looking good

I am wondering if there is an async version of this block:

app.use(function (req, res, next) {
    if (isJSRequiringCoverage(req)) {
        var file = getFilePath(req), //translate request to file name to be delivered
            code = readTheCodeFromFile(file), //use async for a real implementation
            instrumenter = im.getInstrumenter();
        res.send(instrumenter.instrumentSync(code, file));
            //exception handling omitted for brevity
    } else {
        next();
    }
});

something like this:

let  instrumenter = im.getInstrumenter();

app.use(function (req, res, next) {
     let file = getFilePath(req);
     fs.createReadStream(file).pipe(instrumenter.instrument(file)).pipe(res);
});

does something like this exist?

ORESoftware commented 7 years ago

if this is possible, something like this def belongs in the readme...however it would totally make sense if it were pretty much impossible to instrument code asynchronously/line-by-line.