diff --git a/lib/actions/actions.js b/lib/actions/actions.js index 4b860351..46e915fe 100644 --- a/lib/actions/actions.js +++ b/lib/actions/actions.js @@ -290,7 +290,9 @@ actions.checkForCollision = function checkForCollision(filepath, content, cb) { content: content }); - this.conflicter.once('resolved:' + filepath, cb.bind(this, null)); + this.conflicter.once('resolved:' + filepath, function (config) { + process.nextTick(cb.bind(this, null, config)); + }.bind(this)); }; /** diff --git a/test/env.js b/test/env.js index 38fc4781..dff4822e 100644 --- a/test/env.js +++ b/test/env.js @@ -501,6 +501,38 @@ describe('Environment', function () { // actual run .run('angular:all myapp'); }); + + it('only call the end event once (bug #402)', function (done) { + function GeneratorOnce() { + generators.Base.apply(this, arguments); + this.sourceRoot(path.join(__dirname, 'fixtures')); + this.destinationRoot(path.join(__dirname, 'temp')); + } + + util.inherits(GeneratorOnce, generators.Base); + + GeneratorOnce.prototype.createDuplicate = function () { + this.copy('foo-copy.js'); + this.copy('foo-copy.js'); + }; + + var generatorOnce = new GeneratorOnce([], { + env: generators(), + resolved: __filename + }); + + var isFirstEndEvent = true; + + generatorOnce.on('end', function () { + assert.ok(isFirstEndEvent); + if (isFirstEndEvent) { + done(); + } + isFirstEndEvent = false; + }); + + generatorOnce.run(); + }); }); describe('Store', function() {