Skip to content

Commit 4e1ba5a

Browse files
committed
tests: report coverage in child processes
1 parent 400f919 commit 4e1ba5a

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ function eehaslisteners (emitter, type) {
151151
*/
152152

153153
function isignored (namespace) {
154-
/* istanbul ignore next: tested in a child processs */
155154
if (process.noDeprecation) {
156155
// --no-deprecation support
157156
return true
@@ -168,7 +167,6 @@ function isignored (namespace) {
168167
*/
169168

170169
function istraced (namespace) {
171-
/* istanbul ignore next: tested in a child processs */
172170
if (process.traceDeprecation) {
173171
// --trace-deprecation support
174172
return true

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"eslint-plugin-standard": "4.0.0",
2323
"istanbul": "0.4.5",
2424
"mocha": "5.2.0",
25-
"safe-buffer": "5.1.2"
25+
"safe-buffer": "5.1.2",
26+
"uid-safe": "2.1.5"
2627
},
2728
"files": [
2829
"lib/",
@@ -38,7 +39,7 @@
3839
"bench": "node benchmark/index.js",
3940
"lint": "eslint --plugin markdown --ext js,md .",
4041
"test": "mocha --reporter spec --bail test/",
41-
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec test/",
42-
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot test/"
42+
"test-ci": "istanbul cover --print=none node_modules/mocha/bin/_mocha -- --reporter spec test/ && istanbul report lcovonly text-summary",
43+
"test-cov": "istanbul cover --print=none node_modules/mocha/bin/_mocha -- --reporter dot test/ && istanbul report lcov text-summary"
4344
}
4445
}

test/test.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var path = require('path')
99
var script = path.join(__dirname, 'fixtures', 'script.js')
1010
var spawn = require('child_process').spawn
1111
var strictlib = libs.strict
12+
var uid = require('uid-safe').sync
1213

1314
describe('depd(namespace)', function () {
1415
it('creates deprecated function', function () {
@@ -718,7 +719,7 @@ describe('process.env.TRACE_DEPRECATION', function () {
718719

719720
describe('node script.js', function () {
720721
it('should display deprecation message', function (done) {
721-
captureChildStderr([script], function (err, stderr) {
722+
captureChildStderr(script, [], function (err, stderr) {
722723
if (err) return done(err)
723724
var filename = path.relative(process.cwd(), script)
724725
assert.strictEqual(stderr, '__timestamp__ my-cool-module deprecated oldfunction at ' + filename + ':7:10\n')
@@ -736,7 +737,7 @@ describe('node script.js', function () {
736737

737738
describe('node --no-deprecation script.js', function () {
738739
it('should suppress deprecation message', function (done) {
739-
captureChildStderr(['--no-deprecation', script], function (err, stderr) {
740+
captureChildStderr(script, ['--no-deprecation'], function (err, stderr) {
740741
if (err) return done(err)
741742
assert.strictEqual(stderr, '')
742743
done()
@@ -746,7 +747,7 @@ describe('node script.js', function () {
746747

747748
describe('node --trace-deprecation script.js', function () {
748749
it('should suppress deprecation message', function (done) {
749-
captureChildStderr(['--trace-deprecation', script], function (err, stderr) {
750+
captureChildStderr(script, ['--trace-deprecation'], function (err, stderr) {
750751
if (err) return done(err)
751752
assert.ok(stderr.indexOf('__timestamp__ my-cool-module deprecated oldfunction\n at run (' + script + ':7:10)\n at') === 0)
752753
done()
@@ -755,10 +756,16 @@ describe('node script.js', function () {
755756
})
756757
}())
757758

758-
function captureChildStderr (args, callback) {
759+
function captureChildStderr (script, opts, callback) {
759760
var chunks = []
760761
var env = { PATH: process.env.PATH }
761762
var exec = process.execPath
763+
764+
var args = process.env.running_under_istanbul
765+
? opts.concat(path.join(__dirname, '..', 'node_modules', 'istanbul', 'lib', 'cli.js'),
766+
'cover', '--dir=./coverage/child-' + uid(8), '--print=none', script)
767+
: opts.concat(script)
768+
762769
var proc = spawn(exec, args, {
763770
env: env
764771
})

0 commit comments

Comments
 (0)