|
1 | 1 | /* global describe, it */
|
2 | 2 |
|
| 3 | +var _ = require('lodash') |
3 | 4 | var path = require('path')
|
4 |
| -var fs = require('fs') |
5 |
| -var spawn = require('child_process').spawn |
6 |
| -var isWindows = require('is-windows')() |
| 5 | +var bin = path.resolve(__dirname, '../../bin/nyc') |
7 | 6 | var fixturesCLI = path.resolve(__dirname, '../fixtures/cli')
|
8 |
| -var fixturesHooks = path.resolve(__dirname, '../fixtures/hooks') |
9 | 7 | var fakebin = path.resolve(fixturesCLI, 'fakebin')
|
10 |
| -var bin = path.resolve(__dirname, '../../bin/nyc') |
| 8 | +var fixturesHooks = path.resolve(__dirname, '../fixtures/hooks') |
| 9 | +var fs = require('fs') |
| 10 | +var glob = require('glob') |
| 11 | +var isWindows = require('is-windows')() |
11 | 12 | var rimraf = require('rimraf')
|
| 13 | +var spawn = require('child_process').spawn |
12 | 14 |
|
13 | 15 | require('chai').should()
|
14 | 16 | require('tap').mochaGlobals()
|
@@ -332,41 +334,6 @@ describe('the nyc cli', function () {
|
332 | 334 | })
|
333 | 335 | })
|
334 | 336 |
|
335 |
| - it('setting instrument to "false" sets noop instrumenter', function (done) { |
336 |
| - var args = [ |
337 |
| - bin, |
338 |
| - '--silent', |
339 |
| - '--no-instrument', |
340 |
| - '--no-source-map', |
341 |
| - process.execPath, |
342 |
| - './env.js' |
343 |
| - ] |
344 |
| - var expected = { |
345 |
| - silent: true, |
346 |
| - instrument: false, |
347 |
| - sourceMap: false, |
348 |
| - instrumenter: './lib/instrumenters/noop' |
349 |
| - } |
350 |
| - |
351 |
| - var proc = spawn(process.execPath, args, { |
352 |
| - cwd: fixturesCLI, |
353 |
| - env: env |
354 |
| - }) |
355 |
| - |
356 |
| - var stdout = '' |
357 |
| - proc.stdout.on('data', function (chunk) { |
358 |
| - stdout += chunk |
359 |
| - }) |
360 |
| - |
361 |
| - proc.on('close', function (code) { |
362 |
| - code.should.equal(0) |
363 |
| - var env = JSON.parse(stdout) |
364 |
| - var config = JSON.parse(env.NYC_CONFIG, null, 2) |
365 |
| - config.should.include(expected) |
366 |
| - done() |
367 |
| - }) |
368 |
| - }) |
369 |
| - |
370 | 337 | describe('coverage', function () {
|
371 | 338 | if (parseInt(process.versions.node.split('.')[0]) < 4) return
|
372 | 339 | it('reports appropriate coverage information for es6 source files', function (done) {
|
@@ -619,4 +586,88 @@ describe('the nyc cli', function () {
|
619 | 586 | })
|
620 | 587 | })
|
621 | 588 | })
|
| 589 | + |
| 590 | + describe('noop instrumenter', function () { |
| 591 | + it('setting instrument to "false" configures noop instrumenter', function (done) { |
| 592 | + var args = [ |
| 593 | + bin, |
| 594 | + '--silent', |
| 595 | + '--no-instrument', |
| 596 | + '--no-source-map', |
| 597 | + process.execPath, |
| 598 | + './env.js' |
| 599 | + ] |
| 600 | + var expected = { |
| 601 | + silent: true, |
| 602 | + instrument: false, |
| 603 | + sourceMap: false, |
| 604 | + instrumenter: './lib/instrumenters/noop' |
| 605 | + } |
| 606 | + |
| 607 | + var proc = spawn(process.execPath, args, { |
| 608 | + cwd: fixturesCLI, |
| 609 | + env: env |
| 610 | + }) |
| 611 | + |
| 612 | + var stdout = '' |
| 613 | + proc.stdout.on('data', function (chunk) { |
| 614 | + stdout += chunk |
| 615 | + }) |
| 616 | + |
| 617 | + proc.on('close', function (code) { |
| 618 | + code.should.equal(0) |
| 619 | + var env = JSON.parse(stdout) |
| 620 | + var config = JSON.parse(env.NYC_CONFIG, null, 2) |
| 621 | + config.should.include(expected) |
| 622 | + done() |
| 623 | + }) |
| 624 | + }) |
| 625 | + |
| 626 | + describe('--all', function () { |
| 627 | + it('extracts coverage headers from unexecuted files', function (done) { |
| 628 | + var nycOutput = path.resolve(fixturesCLI, '.nyc_output') |
| 629 | + rimraf.sync(nycOutput) |
| 630 | + |
| 631 | + var args = [ |
| 632 | + bin, |
| 633 | + '--all', |
| 634 | + '--silent', |
| 635 | + '--no-instrument', |
| 636 | + '--no-source-map', |
| 637 | + process.execPath, |
| 638 | + // any file other than external-instrument.js, which we |
| 639 | + // want to ensure has its header loaded. |
| 640 | + './env.js' |
| 641 | + ] |
| 642 | + |
| 643 | + var proc = spawn(process.execPath, args, { |
| 644 | + cwd: fixturesCLI, |
| 645 | + env: env |
| 646 | + }) |
| 647 | + |
| 648 | + proc.on('close', function (code) { |
| 649 | + code.should.equal(0) |
| 650 | + glob(nycOutput + '/*.json', function (_err, files) { |
| 651 | + // we should have extracted the coverage header from external-instrumenter.js. |
| 652 | + var coverage = {} |
| 653 | + files.forEach(function (file) { |
| 654 | + _.assign(coverage, JSON.parse( |
| 655 | + fs.readFileSync(file, 'utf-8') |
| 656 | + )) |
| 657 | + }) |
| 658 | + Object.keys(coverage)[0].should.equal('./external-instrumenter.js') |
| 659 | + |
| 660 | + // we should not have executed file, so all counts sould be 0. |
| 661 | + var sum = 0 |
| 662 | + ;Object.keys(coverage['./external-instrumenter.js'].s).forEach(function (k) { |
| 663 | + sum += coverage['./external-instrumenter.js'].s[k] |
| 664 | + }) |
| 665 | + sum.should.equal(0) |
| 666 | + |
| 667 | + return done() |
| 668 | + }) |
| 669 | + }) |
| 670 | + }) |
| 671 | + }) |
| 672 | + }) |
622 | 673 | })
|
0 commit comments