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

istanbul cover: more than one command ? #646

Closed rundef closed 8 years ago

rundef commented 8 years ago

Hi, I have a projects who has two test frameworks :

We're trying to use istanbul to calculate code coverage, but we aren't able to calculate both the unit tests coverage and bdd tests coverage at the same time.

istanbul cover ./node_modules/.bin/mocha works istanbul cover ./node_modules/.bin/cucumberjs works istanbul cover ./node_modules/.bin/mocha ./node_modules/.bin/cucumberjs doesn't work

From what I understand, the ./node_modules/.bin/cucumberjs part is sent as command line argument to mocha.

Is there any way to make this work ?

Thanks

davglass commented 8 years ago

What I normally do is run the unit coverage and drop it into a ./unit directory and then run the bdd tests and drop them into ./bdd. Then use a script like this to generate the results for both:

var istanbul = require('istanbul'),
    path = require('path'),
    collector = new istanbul.Collector();

    ['unit', 'bdd'].forEach(function(item) {
        var file = path.join(__dirname, item, 'coverage.json');
        collector.add(JSON.parse(fs.readFileSync(file, 'utf8')));
    });

    ['lcov', 'json'].forEach(function(type) {
        var report = istanbul.Report.create(type, {
            dir: path.join(__dirname, 'full')
        });
        report.writeReport(collector, true);
    });
rundef commented 8 years ago

Works perfectly, thank you @davglass