Skip to content

Commit

Permalink
Implement withEnvironment method. (#63)
Browse files Browse the repository at this point in the history
* Implement withEnvironment method.

* Add withEnvironment test

* Remove unnecessary default callback from withEnvironment
  • Loading branch information
mshima authored and SBoudrias committed Jan 10, 2020
1 parent 50221b7 commit 3ba8f31
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/run-context.js
Expand Up @@ -80,7 +80,10 @@ RunContext.prototype._run = function() {

this.ran = true;
var namespace;
this.env = yeoman.createEnv([], {}, new TestAdapter());
this.env = (this.envCB || (env => env)).call(
this,
yeoman.createEnv([], {}, new TestAdapter())
);

helpers.registerDependencies(this.env, this.dependencies);

Expand Down Expand Up @@ -217,6 +220,20 @@ RunContext.prototype.inTmpDir = function(cb) {
return this.inDir(tmpdir, cb);
};

/**
* Create an environment
*
* This method is called automatically when creating a RunContext. Only use it if you need
* to use the callback.
*
* @param {Function} [cb] - callback who'll receive the folder path as argument
* @return {this} run context instance
*/
RunContext.prototype.withEnvironment = function(cb) {
this.envCB = cb;
return this;
};

/**
* Clean the directory used for tests inside inDir/inTmpDir
*/
Expand Down
17 changes: 17 additions & 0 deletions test/run-context.js
Expand Up @@ -628,6 +628,23 @@ describe('RunContext', function() {
});
});

describe('#withEnvironment()', function() {
it('register paths', function(done) {
this.ctx
.withEnvironment(env => {
env.register(require.resolve('./fixtures/generator-simple/app'));
return env;
})
.on(
'ready',
function() {
assert(this.ctx.env.get('simple:app'));
done();
}.bind(this)
);
});
});

describe('#withLocalConfig()', function() {
it('provides config to the generator', function(done) {
this.ctx
Expand Down

0 comments on commit 3ba8f31

Please sign in to comment.