Skip to content

Commit

Permalink
emit error when an error occurs inside consolidate
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed Feb 12, 2015
1 parent 03fb42b commit 749cc0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = function gulpWrap(opts, data, options) {
}
done(null, new Buffer(result));
});
}, done);
}, done).catch(done);
}

var run = new VinylBufferStream(compile);
Expand Down
22 changes: 13 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require('mocha');
describe('gulp-wrap', function() {
it('should pass an empty file as it is', function(done) {
wrap('')
.on('error', assert.ifError)
.on('error', done)
.on('data', function(file) {
assert(file.isNull());
done();
Expand All @@ -22,7 +22,7 @@ describe('gulp-wrap', function() {

it('should produce expected file via buffer', function(done) {
wrap('<%= contents %>bar')
.on('error', assert.ifError)
.on('error', done)
.on('data', function(file) {
assert(file.isBuffer());
assert.equal(String(file.contents), 'foobar');
Expand All @@ -33,7 +33,7 @@ describe('gulp-wrap', function() {

it('should produce expected file via stream', function(done) {
wrap('a<%= contents %>c')
.on('error', assert.ifError)
.on('error', done)
.on('data', function(file) {
assert(file.isStream());
file.contents.on('data', function(data) {
Expand All @@ -50,7 +50,7 @@ describe('gulp-wrap', function() {

it('should handle a template from a file', function(done) {
wrap({src: 'test/fixture.jst'})
.on('error', assert.ifError)
.on('error', done)
.on('data', function(file) {
assert(file.isBuffer());
assert.equal(String(file.contents), 'BEFORE Hello AFTER');
Expand All @@ -74,6 +74,7 @@ describe('gulp-wrap', function() {
{someVar: 'someVal'},
{variable: 'data'}
)
.on('error', done)
.on('data', function(file) {
assert(file.isBuffer());
assert.equal(String(file.contents), 'BEFORE Hello someVal AFTER');
Expand All @@ -87,7 +88,7 @@ describe('gulp-wrap', function() {
srcFile.someProp = 'someValue';

wrap('Contents: [<%= contents %>] - File prop: [<%= file.someProp %>]')
.on('error', assert.ifError)
.on('error', done)
.on('data', function(file) {
assert(file.isBuffer());
assert.equal(String(file.contents), 'Contents: [Hello] - File prop: [someValue]');
Expand All @@ -103,7 +104,7 @@ describe('gulp-wrap', function() {
wrap('<%= contents %> - <%= file.someProp %>', {
file: {someProp: 'foo'}
})
.on('error', assert.ifError)
.on('error', done)
.on('data', function(file) {
assert(file.isBuffer());
assert.equal(String(file.contents), 'Hello - foo');
Expand All @@ -122,7 +123,7 @@ describe('gulp-wrap', function() {
var expected = ['one 1', 'two 2'];

var stream = wrap('<%= file.one %> <%= file.two %> <%= contents %>')
.on('error', assert.ifError)
.on('error', done)
.on('data', function(file) {
assert(file.isBuffer());
assert(String(file.contents), expected.shift());
Expand All @@ -141,7 +142,7 @@ describe('gulp-wrap', function() {
srcFile.data = {prop: 'foo'};

wrap('<%= contents %> <%= prop %>')
.on('error', assert.ifError)
.on('error', done)
.on('data', function(file) {
assert(file.isBuffer());
assert.equal(String(file.contents), 'Hello foo');
Expand All @@ -152,6 +153,7 @@ describe('gulp-wrap', function() {

it('should allow for expressions', function(done) {
wrap('<%= path.dirname(file.path) %>', {file: {path: 'a/b'}}, {imports: {path: path}})
.on('error', done)
.on('data', function(file) {
assert(file.isBuffer());
assert.equal(String(file.contents), 'a');
Expand All @@ -165,7 +167,7 @@ describe('gulp-wrap', function() {

it('should parse JSON files by default', function(done) {
wrap('BEFORE <%= contents.name %> AFTER')
.on('error', assert.ifError)
.on('error', done)
.on('data', function(file) {
assert(file.isBuffer());
assert.equal(String(file.contents), 'BEFORE foo AFTER');
Expand All @@ -179,6 +181,7 @@ describe('gulp-wrap', function() {

it('should parse YAML files by default', function(done) {
wrap('BEFORE <%= contents.name %> AFTER')
.on('error', done)
.on('data', function(file) {
assert(file.isBuffer());
assert.equal(String(file.contents), 'BEFORE foo AFTER');
Expand All @@ -192,6 +195,7 @@ describe('gulp-wrap', function() {

it('option parse=false should disable file parsing', function(done) {
wrap('<%= contents %>', null, {parse: false})
.on('error', done)
.on('data', function(file) {
assert(file.isBuffer());
assert.equal(String(file.contents), 'name: foo');
Expand Down

0 comments on commit 749cc0b

Please sign in to comment.