From 079633a2666d3111f48686ab0dafe4bd9dac6aaa Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Tue, 8 Dec 2015 18:22:38 +0000 Subject: [PATCH] wip! use tap.spawn() for each test --- test/nyc-test.js | 65 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/test/nyc-test.js b/test/nyc-test.js index 0f72ee9d3..3a30f4cc4 100644 --- a/test/nyc-test.js +++ b/test/nyc-test.js @@ -1,5 +1,3 @@ -/* global describe, it */ - var _ = require('lodash') var fs = require('fs') var NYC = require('../') @@ -7,9 +5,70 @@ 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')