Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(createError): separate createError into own module
- Loading branch information
1 parent
735e04d
commit e3709af
Showing
3 changed files
with
44 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
var PluginError = require('gulp-util/lib/PluginError'); | ||
var pluginName = 'gulp-uglify'; | ||
|
||
module.exports = function createError(file, err) { | ||
if (typeof err === 'string') { | ||
return new PluginError(pluginName, file.path + ': ' + err, { | ||
fileName: file.path, | ||
showStack: false | ||
}); | ||
} | ||
|
||
var msg = err.message || err.msg || 'unspecified error'; | ||
|
||
return new PluginError(pluginName, file.path + ': ' + msg, { | ||
fileName: file.path, | ||
lineNumber: err.line, | ||
stack: err.stack, | ||
showStack: false | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
var test = require('tape'); | ||
var Vinyl = require('vinyl'); | ||
var createError = require('../lib/createError'); | ||
|
||
var testOkContentsInput = '"use strict"; (function(console, first, second) { console.log(first + second) }(5, 10))'; | ||
var testFile = new Vinyl({ | ||
cwd: '/home/terin/broken-promises/', | ||
base: '/home/terin/broken-promises/test', | ||
path: '/home/terin/broken-promises/test/test2.js', | ||
contents: new Buffer(testOkContentsInput) | ||
}); | ||
|
||
test('should report "unspecified error" if err has no msg or message properties', function (t) { | ||
t.plan(3); | ||
var e = createError(testFile, {}); | ||
|
||
t.ok(e instanceof Error, 'argument should be of type error'); | ||
t.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify'); | ||
t.true(e.message.match(/unspecified error$/), 'error should not be specified'); | ||
}); |