[mochaSetup] added notes to explain the purpose for the workarounds in place

This commit is contained in:
spalger 2016-01-13 16:50:55 -07:00
parent 680bf2102c
commit 7b15ee05d1
2 changed files with 12 additions and 0 deletions

View file

@ -1,6 +1,8 @@
var wrap = require('lodash').wrap;
var Mocha = require('mocha');
// work around simplemocha's lack of a "--require" option.
// see https://github.com/yaymukund/grunt-simple-mocha/issues/50 for feature request.
Mocha.prototype.run = wrap(Mocha.prototype.run, function (orig) {
require('../../test/mocha_setup');
orig.call(this);

View file

@ -3,6 +3,16 @@ var autoRelease = require('auto-release-sinon');
require('babel/register')(require('../src/optimize/babelOptions').node);
// hook into the global afterEach variable to allow autoReleaseSinon to register
// an afterEach handler before mocha has exposed itself to the test files.
//
// This works by telling autoReleaseSinon to use a fake "afterEach" function.
// Rather than actually record an afterEach handler the function tracks all of
// the calls it received and queues them up in queuedAfterEachArgs.
//
// The global "afterEach" variable is also tracked, and once it is assigned by mocha
// the variable global is reconfigured to point directly to the new value (from mocha)
// and all of the queued invocations are executed.
var queuedAfterEachArgs = [];
Object.defineProperty(global, 'afterEach', {
configurable: true,