err.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. var test = require('tape'),
  3. Vinyl = require('vinyl'),
  4. gulpUglify = require('../');
  5. var testContentsInput = 'function errorFunction(error)\n{';
  6. var testOkContentsInput = '"use strict"; (function(console, first, second) { console.log(first + second) }(5, 10))';
  7. var testFile1 = new Vinyl({
  8. cwd: "/home/terin/broken-promises/",
  9. base: "/home/terin/broken-promises/test",
  10. path: "/home/terin/broken-promises/test/test1.js",
  11. contents: new Buffer(testContentsInput)
  12. });
  13. var testFile2 = new Vinyl({
  14. cwd: "/home/terin/broken-promises/",
  15. base: "/home/terin/broken-promises/test",
  16. path: "/home/terin/broken-promises/test/test2.js",
  17. contents: new Buffer(testOkContentsInput)
  18. });
  19. test('should report files in error', function(t) {
  20. t.plan(6);
  21. var stream = gulpUglify();
  22. stream.on('data', function() {
  23. t.fail('we shouldn\'t have gotten here');
  24. });
  25. stream.on('error', function(e) {
  26. t.ok(e instanceof Error, 'argument should be of type error');
  27. t.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify');
  28. t.equal(e.fileName, testFile1.path, 'error reports correct file name');
  29. t.equal(e.lineNumber, 2, 'error reports correct line number');
  30. t.ok(e.stack, 'error has a stack');
  31. t.false(e.showStack, 'error is configured to not print the stack');
  32. });
  33. stream.write(testFile1);
  34. stream.end();
  35. });
  36. test('shouldn\'t blow up when given output options', function(t) {
  37. t.plan(5);
  38. var stream = gulpUglify({
  39. output: {
  40. exportAll: true
  41. }
  42. });
  43. stream.on('data', function() {
  44. t.fail('We shouldn\'t have gotten here');
  45. });
  46. stream.on('error', function(e) {
  47. t.ok(e instanceof Error, 'argument should be of type error');
  48. t.equals(e.message, testFile2.path + ': `exportAll` is not a supported option');
  49. t.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify');
  50. t.equal(e.fileName, testFile2.path, 'error reports correct file name');
  51. t.false(e.showStack, 'error is configured to not print the stack');
  52. });
  53. stream.write(testFile2);
  54. stream.end();
  55. });