Skip to content

Commit

Permalink
RunContext now take a tmpdir setting to skip auto run in tmpdir
Browse files Browse the repository at this point in the history
Fix #718
  • Loading branch information
SBoudrias committed Dec 21, 2014
1 parent 3249643 commit 014413d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/test/run-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ var TestAdapter = require('./adapter').TestAdapter;
* This class provide a run context object to façade the complexity involved in setting
* up a generator for testing
* @constructor
* @param {String|Function} Generator - Namespace or generator constructor. If the later
* @param {String|Function} Generator - Namespace or generator constructor. If the later
* is provided, then namespace is assumed to be
* 'gen:test' in all cases
* @param {Object} [settings]
* @param {Boolean} [settings.tmpdir=true] - Automatically run this generator in a tmp dir
* @return {this}
*/

var RunContext = module.exports = function RunContext(Generator) {
var RunContext = module.exports = function RunContext(Generator, settings) {
this._asyncHolds = 0;
this.runned = false;
this.inDirSet = false;
Expand All @@ -29,6 +31,7 @@ var RunContext = module.exports = function RunContext(Generator) {
this.answers = {};
this.dependencies = [];
this.Generator = Generator;
this.settings = _.extend({ tmpdir: true }, settings);

setTimeout(this._run.bind(this), 10);
};
Expand All @@ -54,9 +57,10 @@ RunContext.prototype.async = function () {
*/

RunContext.prototype._run = function () {
if (!this.inDirSet) {
if (!this.inDirSet && this.settings.tmpdir) {
this.inTmpDir();
}

if (this._asyncHolds !== 0 || this.runned) return;
this.runned = true;

Expand Down
15 changes: 15 additions & 0 deletions test/run-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ describe('RunContext', function () {
}.bind(this));
});

it('allows an option to not automatically run in tmpdir', function (done) {
var cwd = process.cwd();
this.ctx.settings.tmpdir = false;
this.ctx.on('end', function (err) {
assert.equal(cwd, process.cwd());
done();
});
});

it('accepts settings', function () {
var Dummy = helpers.createDummyGenerator();
var ctx = new RunContext(Dummy, { tmpdir: false });
assert.equal(ctx.settings.tmpdir, false);
});

it('only run a generator once', function (done) {
this.ctx.on('end', function () {
sinon.assert.calledOnce(this.execSpy);
Expand Down

0 comments on commit 014413d

Please sign in to comment.