test.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. var expect = require('chai').expect
  2. var through = require('through2')
  3. var Vinyl = require('vinyl')
  4. clone = require('./')
  5. describe('gulp-clone', function() {
  6. it('should clone files in the stream', function(done) {
  7. var sourceStream = clone(),
  8. cloneStream = clone(),
  9. count = 0;
  10. sourceStream.pipe(cloneStream);
  11. sourceStream.on('data', function(data) {
  12. expect(String(data.contents)).to.be.equal('source stream');
  13. expect(data.path).to.be.equal('file.js');
  14. count++;
  15. });
  16. cloneStream.pipe(through.obj(function(file, enc, cb) {
  17. file.contents = new Buffer('cloned stream');
  18. cb(null, file);
  19. }))
  20. cloneStream.on('data', function(data) {
  21. expect(String(data.contents)).to.be.equal('cloned stream');
  22. expect(data.path).to.be.equal('file.js');
  23. count++;
  24. });
  25. sourceStream.write(new Vinyl({
  26. path: 'file.js',
  27. contents: new Buffer('source stream')
  28. }));
  29. sourceStream.on('end', function(data) {
  30. expect(count).to.be.equal(2);
  31. done();
  32. });
  33. sourceStream.end();
  34. });
  35. it('should clone files in the stream, using the old behaviour', function(done) {
  36. var sink = clone.sink(),
  37. buffer = [];
  38. sink
  39. .pipe(sink.tap())
  40. .pipe(through.obj(function(f,e,cb) {
  41. buffer.push(f);
  42. cb(null, f);
  43. }))
  44. .on('finish', function() {
  45. expect(buffer).to.have.length(2);
  46. expect(buffer).to.have.nested.property('[0].path', 'afile.js');
  47. expect(buffer).to.have.nested.property('[1].path', 'afile.js');
  48. done();
  49. });
  50. sink.write(new Vinyl({
  51. path: 'afile.js',
  52. contents: new Buffer("")
  53. }));
  54. sink.end();
  55. });
  56. });