Skip to content

Commit

Permalink
Merge pull request #402 from timrwood/single-end
Browse files Browse the repository at this point in the history
Adding failing tests for end event firing multiple times when copying a file more than once.
  • Loading branch information
SBoudrias committed Nov 13, 2013
2 parents 4957d04 + 6aada9b commit e003fba
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};

/**
Expand Down
32 changes: 32 additions & 0 deletions test/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit e003fba

Please sign in to comment.