minify.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. 'use strict';
  2. var test = require('tape-catch');
  3. var assert = require('assert');
  4. var Vinyl = require('vinyl');
  5. var Buffer = require('safe-buffer').Buffer;
  6. var td = require('testdouble');
  7. var minify = require('../lib/minify');
  8. test('minify should work', function(t) {
  9. var testContentsInput =
  10. '"use strict"; (function(console, first, second) { console.log(first + second) }(5, 10))';
  11. var testFile = createTestFile(testContentsInput);
  12. var uglify = td.object(['minify']);
  13. var logger = td.object(['warn']);
  14. td.when(
  15. uglify.minify(
  16. {
  17. 'test1.js': testContentsInput
  18. },
  19. {
  20. output: {}
  21. }
  22. )
  23. ).thenReturn({
  24. code: 'foobar'
  25. });
  26. var subject = minify(uglify, logger)({});
  27. var file = subject(testFile);
  28. assert.ok(file instanceof Vinyl);
  29. assert.ok(Buffer.isBuffer(file.contents));
  30. assert.equal(String(file.contents), 'foobar');
  31. td.verify(logger.warn(), {
  32. times: 0,
  33. ignoreExtraArgs: true
  34. });
  35. td.reset();
  36. t.end();
  37. });
  38. test('minify should warn with string argument', function(t) {
  39. var testContentsInput =
  40. '"use strict"; (function(console, first, second) { console.log(first + second) }(5, 10))';
  41. var testFile = createTestFile(testContentsInput);
  42. var uglify = td.object(['minify']);
  43. var logger = td.object(['warn']);
  44. td.when(
  45. uglify.minify(
  46. {
  47. 'test1.js': testContentsInput
  48. },
  49. {
  50. output: {}
  51. }
  52. )
  53. ).thenReturn({
  54. code: 'foobar'
  55. });
  56. var subject = minify(uglify, logger)('build.min.js');
  57. var file = subject(testFile);
  58. td.verify(logger.warn('gulp-uglify expects an object, non-object provided'));
  59. assert.ok(file instanceof Vinyl);
  60. assert.ok(Buffer.isBuffer(file.contents));
  61. assert.equal(String(file.contents), 'foobar');
  62. td.reset();
  63. t.end();
  64. });
  65. function createTestFile(input) {
  66. return new Vinyl({
  67. cwd: '/home/terin/broken-promises/',
  68. base: '/home/terin/broken-promises/test',
  69. path: '/home/terin/broken-promises/test/test1.js',
  70. contents: Buffer.from(input)
  71. });
  72. }