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

Running nyc on child processes within child processes? #202

Closed
ben-eb opened this issue Mar 23, 2016 · 2 comments
Closed

Running nyc on child processes within child processes? #202

ben-eb opened this issue Mar 23, 2016 · 2 comments

Comments

@ben-eb
Copy link

ben-eb commented Mar 23, 2016

I'm trying to find a solution to avajs/ava#604 (comment), where I want to be able to run AVA on each test file serially and output a global code coverage. I've got the start of a simple runner here:

#!/usr/bin/env node

var glob = require('glob');
var spawn = require('child_process').spawn;
var files = require('minimist')(process.argv.slice(2))._[0];

function spawnAva (file) {
    return new Promise(function (resolve, reject) {
        var ps = spawn(process.execPath, ['node_modules/.bin/ava', file]);

        ps.stdout.pipe(process.stdout);
        ps.stderr.pipe(process.stderr);

        ps.on('close', function (code) {
            if (code === 0) {
                return resolve(code);
            }
            return reject(code);
        });
    });
}

glob(files, function (err, tests) {
    if (err) {
        throw err;
    }
    return tests.reduce(function (promise, file) {
        return promise.then(function () { return spawnAva(file); });
    }, Promise.resolve());
});

This works great for running AVA on each file separately but it means that code coverage for the tests themselves are swallowed as nyc instruments the batch-ava command instead.

$ nyc --all batch-ava test/**/*.js

   1 passed


   1 passed

------------|----------|----------|----------|----------|----------------|
File        |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
------------|----------|----------|----------|----------|----------------|
 batch-ava/ |    88.89 |       50 |      100 |    88.24 |                |
  index.js  |    88.89 |       50 |      100 |    88.24 |          18,25 |
------------|----------|----------|----------|----------|----------------|
All files   |    88.89 |       50 |      100 |    88.24 |                |
------------|----------|----------|----------|----------|----------------|

Does anyone know a workaround for this issue?

@novemberborn
Copy link
Contributor

@ben-eb I cloned https://github.com/postcss/postcss-selector-parser, saved your script as runall.js and changed the test script to nyc node runall.js 'src/__tests__/*.js'. I do get full coverage output:

----------------------------------------|----------|----------|----------|----------|----------------|
File                                    |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
----------------------------------------|----------|----------|----------|----------|----------------|
 postcss-selector-parser/               |    88.89 |       50 |      100 |    88.24 |                |
  runall.js                             |    88.89 |       50 |      100 |    88.24 |          16,23 |
 postcss-selector-parser/src/           |    97.26 |    95.94 |      100 |    97.26 |                |
  index.js                              |      100 |      100 |      100 |      100 |                |
  parser.js                             |    98.31 |    96.21 |      100 |    98.31 |232,241,276,459 |
  processor.js                          |      100 |      100 |      100 |      100 |                |
  sortAscending.js                      |      100 |      100 |      100 |      100 |                |
  tokenize.js                           |    93.86 |    95.24 |      100 |    93.86 |... 163,177,178 |
 postcss-selector-parser/src/selectors/ |    94.39 |    80.85 |    96.34 |    94.39 |                |
  attribute.js                          |    93.33 |     87.5 |      100 |    93.33 |             27 |
  className.js                          |      100 |      100 |      100 |      100 |                |
  combinator.js                         |      100 |      100 |      100 |      100 |                |
  comment.js                            |      100 |      100 |      100 |      100 |                |
  container.js                          |     93.1 |    77.08 |    97.56 |     93.1 |... 125,134,147 |
  id.js                                 |      100 |      100 |      100 |      100 |                |
  namespace.js                          |      100 |      100 |      100 |      100 |                |
  nesting.js                            |      100 |      100 |      100 |      100 |                |
  node.js                               |    91.67 |    78.57 |    77.78 |    91.67 |       17,20,60 |
  pseudo.js                             |      100 |      100 |      100 |      100 |                |
  root.js                               |      100 |      100 |      100 |      100 |                |
  selector.js                           |      100 |      100 |      100 |      100 |                |
  string.js                             |      100 |      100 |      100 |      100 |                |
  tag.js                                |      100 |      100 |      100 |      100 |                |
  universal.js                          |      100 |      100 |      100 |      100 |                |
----------------------------------------|----------|----------|----------|----------|----------------|
All files                               |    96.05 |    90.51 |    97.76 |    96.04 |                |
----------------------------------------|----------|----------|----------|----------|----------------|

Which repo were you trying with?

(I tried with --all but that crashed, probably due to #183)

@ben-eb
Copy link
Author

ben-eb commented Mar 24, 2016

Was trying this out in a separate repo. That's good enough for me, thanks for your help. 👍

@ben-eb ben-eb closed this as completed Mar 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants