wiring.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*global describe, before, it */
  2. var path = require('path');
  3. var fs = require('fs');
  4. var events = require('events');
  5. var assert = require('assert');
  6. var wiring = require('../lib/actions/wiring');
  7. describe('yeoman.generator.lib.actions.wiring', function () {
  8. before(function () {
  9. this.fixtures = path.join(__dirname, 'fixtures');
  10. });
  11. it('should generate a simple block', function () {
  12. var res = wiring.generateBlock('js', 'main.js', [
  13. 'path/file1.js',
  14. 'path/file2.js'
  15. ]);
  16. assert.equal(res.trim(), '<!-- build:js main.js -->\npath/file1.js,path/file2.js <!-- endbuild -->');
  17. });
  18. it('should generate a simple block with search path', function () {
  19. var res = wiring.generateBlock('js', 'main.js', [
  20. 'path/file1.js',
  21. 'path/file2.js'
  22. ], '.tmp/');
  23. assert.equal(res.trim(), '<!-- build:js(.tmp/) main.js -->\npath/file1.js,path/file2.js <!-- endbuild -->');
  24. });
  25. it('should generate block with multiple search paths', function () {
  26. var res = wiring.generateBlock('js', 'main.js', [
  27. 'path/file1.js',
  28. 'path/file2.js'
  29. ], ['.tmp/', 'dist/']);
  30. assert.equal(res.trim(), '<!-- build:js({.tmp/,dist/}) main.js -->\npath/file1.js,path/file2.js <!-- endbuild -->');
  31. });
  32. it('should append js files to an html string', function () {
  33. var html = '<html><body></body></html>';
  34. var res = wiring.appendFiles(html, 'js', 'out/file.js', ['in/file1.js', 'in/file2.js']);
  35. var fixture = fs.readFileSync(path.join(this.fixtures, 'js_block.html'),
  36. 'utf-8').trim();
  37. assert.equal(res, fixture);
  38. });
  39. it('appendFiles should work the same using the object syntax', function () {
  40. var html = '<html><body></body></html>';
  41. var res = wiring.appendFiles(html, 'js', 'out/file.js', ['in/file1.js', 'in/file2.js']);
  42. var res2 = wiring.appendFiles({
  43. html: html,
  44. fileType: 'js',
  45. optimizedPath: 'out/file.js',
  46. sourceFileList: ['in/file1.js', 'in/file2.js']
  47. });
  48. assert.equal(res, res2);
  49. });
  50. });