Skip to content

Commit

Permalink
wip! use tap.spawn() for each test
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed Dec 8, 2015
1 parent 08bb1c9 commit 079633a
Showing 1 changed file with 62 additions and 3 deletions.
65 changes: 62 additions & 3 deletions test/nyc-test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,74 @@
/* global describe, it */

var _ = require('lodash')
var fs = require('fs')
var NYC = require('../')
var path = require('path')
var rimraf = require('rimraf')
var sinon = require('sinon')
var spawn = require('child_process').spawn
var tap = require('tap')
var tapMocha = require('tap/lib/mocha')

require('chai').should()
require('tap').mochaGlobals()

var spawnNthTest = parseInt(process.env.NYC_TEST_SPAWN || '-1', 10)

var parents = []
var describe = function (name, fn) {
if (spawnNthTest === -1) {
var c = tap.current()
if (!fn) {
c.test(name)
} else {
c.test(name, function (tt) {
parents.unshift(tt)
fn()
parents.shift()
tt.end()
})
}
} else {
fn()
}
}

var cleanup = function () {
// TODO perform clean up. may need to wrap NYC() so we can set a temp
// directory different from what tap --coverage uses.
}

var testCounter = 0
var it = function (name, fn) {
if (spawnNthTest === testCounter) {
var wrapper
if (fn) {
if (fn.length) {
wrapper = function (done) {
try {
fn(function (err) {
cleanup()
done(err)
})
} catch (err) {
cleanup()
done(err)
}
}
} else {
wrapper = function () {
try {
fn()
} finally {
cleanup()
}
}
}
}
tapMocha.it(name, wrapper)
} else if (spawnNthTest === -1) {
parents[0].spawn(process.execPath, process.argv.slice(1), { env: { NYC_TEST_SPAWN: testCounter } }, '(in child process)')
}
testCounter++
}

describe('nyc', function () {
var fixtures = path.resolve(__dirname, './fixtures')
Expand Down

0 comments on commit 079633a

Please sign in to comment.