Skip to content

Commit 7d1e930

Browse files
committed
fixes nikhilmodak#24: stream should emit error event
1 parent d3a1a51 commit 7d1e930

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ function processDoc(opts) {
213213
function flushFunction (cb) {
214214
if (merged) {
215215
docsStreamEndCb = cb;
216-
// IMPORTANT: Allow gulp.watch to continue running.
216+
// IMPORTANT: If you do not want an error here to destroy a gulp watch,
217+
// see: http://stackoverflow.com/questions/23971388/prevent-errors-from-breaking-crashing-gulp-watch
217218
try{
218219
ngdoc.merge(reader.docs);
219220
reader.docs.forEach(function(doc){
@@ -234,6 +235,7 @@ function processDoc(opts) {
234235
setup.pages = _.union(setup.pages, ngdoc.metadata(reader.docs));
235236
} catch (flushError) {
236237
console.log(flushError);
238+
cb(flushError);
237239
}
238240
writeSetup(this);
239241

spec/fixtures/error/foo.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
/**
4+
* @ngdoc servicesdfasdf
5+
* @name foo
6+
* @description Malformed docblock
7+
**/
8+
angular.module('foo', [])
9+
.factory('foo', function() {
10+
return {};
11+
});
File renamed without changes.
File renamed without changes.

spec/ngdocSpec.js

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ var merge = require('merge-stream');
66
var fs = require('fs');
77
var del = require('del');
88

9+
// Location for temporary test files
10+
var tmpTestFiles = './tmp-test-files';
11+
912
describe('ngdoc', function() {
1013
var Doc = ngdoc.Doc;
1114
var dom;
@@ -18,6 +21,16 @@ describe('ngdoc', function() {
1821
return this.actual.indexOf(text) > -1;
1922
}
2023
});
24+
25+
try {
26+
del.sync([tmpTestFiles])
27+
} catch(e) {
28+
29+
}
30+
});
31+
32+
afterEach(function() {
33+
del.sync([tmpTestFiles])
2134
});
2235

2336
describe('Doc', function() {
@@ -660,33 +673,24 @@ describe('ngdoc', function() {
660673
});
661674

662675
describe('watch', function() {
663-
664-
beforeEach(function() {
665-
try {
666-
del.sync(['./tmp-test-files'])
667-
} catch(e) {
668-
669-
}
670-
});
671-
672-
afterEach(function() {
673-
del.sync(['./tmp-test-files'])
674-
});
675676

676677
it('should not duplicate pages if it is run in succession', function(done) {
677678

679+
var targetFiles = __dirname + '/fixtures/watch/*.js';
680+
var destFiles = tmpTestFiles;
681+
678682
// First go
679-
gulp.src(__dirname + '/fixtures/*.js')
683+
gulp.src(targetFiles)
680684
.pipe(index.process({}))
681-
.pipe(gulp.dest('./tmp-test-files'))
685+
.pipe(gulp.dest(destFiles))
682686
.on('end', function() {
683687
// Second go
684-
gulp.src(__dirname + '/fixtures/*.js')
688+
gulp.src(targetFiles)
685689
.pipe(index.process({}))
686-
.pipe(gulp.dest('./tmp-test-files'))
690+
.pipe(gulp.dest(destFiles))
687691
.on('end', function() {
688692

689-
var setupContent = fs.readFileSync('./tmp-test-files/js/docs-setup.js', 'utf-8');
693+
var setupContent = fs.readFileSync(destFiles + '/js/docs-setup.js', 'utf-8');
690694
var setup = eval(setupContent);
691695
expect(setup.pages.length).toEqual(2);
692696
done();
@@ -698,4 +702,16 @@ describe('ngdoc', function() {
698702

699703
});
700704

705+
describe('error handling', function() {
706+
707+
708+
it('should trigger an error event on the stream', function(done) {
709+
return gulp.src( __dirname + '/fixtures/error/*.js' )
710+
.pipe( index.process({}) )
711+
.pipe( gulp.dest( tmpTestFiles ) )
712+
.on('error', done);
713+
});
714+
715+
});
716+
701717
});

0 commit comments

Comments
 (0)