Skip to content

Commit

Permalink
Merge pull request #28 from backflip/feature/error-handling
Browse files Browse the repository at this point in the history
Issue #20: Templating step: Throw gulp-util's PluginError instead of …
  • Loading branch information
backflip committed Aug 2, 2015
2 parents 6395438 + 3c8e3ba commit 068c088
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,14 @@ function iconfontCSS(config) {

stream._flush = function(cb) {
var content;

if (glyphMap.length) {
consolidate[config.engine](config.path, {
glyphs: glyphMap,
fontName: config.fontName,
fontPath: config.fontPath
}, function(error, html) {
if (error) {
throw error;
}, function(err, html) {
if (err) {
throw new gutil.PluginError(PLUGIN_NAME, 'Error in template: ' + err.message);
}

content = Buffer(html);
Expand Down
16 changes: 9 additions & 7 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@ var gulp = require('gulp'),

describe('gulp-iconfont-css', function() {
function testType(type, name) {
var resultsDir = __dirname + '/results_'+type;
it('should generate '+name+' file', function(done) {
var resultsDir = __dirname + '/results_' + type;

it('should generate ' + name + ' file', function(done) {
gulp.src(__dirname + '/fixtures/icons/*.svg')
.pipe(iconfontCss({
fontName: 'Icons',
path: type,
targetPath: '../_icons.'+type
targetPath: '../_icons.' + type
}).on('error', function(err) {
console.log(err);
}))
.pipe(gulp.dest(resultsDir + '/icons/'))
.pipe(es.wait(function() {
assert.equal(
fs.readFileSync(resultsDir + '/_icons.'+type, 'utf8'),
fs.readFileSync(__dirname + '/expected/_icons.'+type, 'utf8')
fs.readFileSync(resultsDir + '/_icons.' + type, 'utf8'),
fs.readFileSync(__dirname + '/expected/_icons.' + type, 'utf8')
);

fs.unlinkSync(resultsDir + '/_icons.'+type);
fs.unlinkSync(resultsDir + '/_icons.' + type);
fs.unlinkSync(resultsDir + '/icons/uE001-github.svg');
fs.unlinkSync(resultsDir + '/icons/uE002-twitter.svg');
fs.rmdirSync(resultsDir + '/icons/');
Expand All @@ -35,5 +38,4 @@ describe('gulp-iconfont-css', function() {
testType('scss', 'SCSS');
testType('less', 'Less');
testType('css', 'CSS');

});

0 comments on commit 068c088

Please sign in to comment.