Skip to content

Commit

Permalink
Add support to don't schedule generator queue at composeWith.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Jul 5, 2021
1 parent 36c6feb commit 2e65ccb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -812,14 +812,23 @@ class Environment extends Base {
* @param {String} namespaceOrPath
* @param {Array} [args]
* @param {Object} [options]
* @param {Boolean} [schedule]
* @return {Generator} The instantiated generator or the singleton instance.
*/
composeWith(generator, args, options) {
composeWith(generator, args, options, schedule = true) {
if (typeof args === 'boolean') {
schedule = args;
args = undefined;
options = undefined;
} else if (typeof options === 'boolean') {
schedule = options;
options = undefined;
}
const generatorInstance = this.create(generator, args, options);
if (generatorInstance.then) {
return generatorInstance.then(generatorInstance => this.queueGenerator(generatorInstance, true));
return generatorInstance.then(generatorInstance => this.queueGenerator(generatorInstance, schedule));
}
return this.queueGenerator(generatorInstance, true);
return this.queueGenerator(generatorInstance, schedule);
}

/**
Expand Down
15 changes: 15 additions & 0 deletions test/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,21 @@ describe('Environment', () => {
assert.ok(this.env.composeWith('stub') instanceof this.Generator);
});

it('should schedule generator queue', function () {
this.env.runLoop.add = sinon.spy();
this.env.composeWith('stub');
assert(this.env.runLoop.add.calledOnce);
assert(this.env.runLoop.add.getCall(0).firstArg === 'environment:run');
});

describe('passing false schedule parameter', () => {
it('should queue generator tasks', function () {
this.env.runLoop.add = sinon.spy();
this.env.composeWith('stub', [], {}, false);
assert(this.env.runLoop.add.getCall(0).firstArg !== 'environment:run');
});
});

it('should emit a compose event', function (done) {
this.env.once('compose', (namespace, generator) => {
assert.ok(namespace === 'stub');
Expand Down

0 comments on commit 2e65ccb

Please sign in to comment.