You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const fs = require('fs');
  2. const should = require('should');
  3. const Vinyl = require('vinyl');
  4. const injectJS = require('../');
  5. describe('gulp-inject-js', function () {
  6. it('should produce expected file', function (done) {
  7. const srcFile = new Vinyl({
  8. path: 'test/fixtures/index.html',
  9. base: 'test/fixtures/',
  10. contents: fs.readFileSync('test/fixtures/index.html')
  11. });
  12. const expectedFile = new Vinyl({
  13. path: 'test/expected/index.html',
  14. base: 'test/expected/',
  15. contents: fs.readFileSync('test/expected/index.html')
  16. });
  17. const stream = injectJS();
  18. stream.on('error', function (error) {
  19. should.exist(error);
  20. done(error);
  21. });
  22. stream.on('data', function (newFile) {
  23. should.exist(newFile);
  24. should.exist(newFile.contents);
  25. String(newFile.contents).should.equal(String(expectedFile.contents));
  26. done();
  27. });
  28. stream.write(srcFile);
  29. stream.end();
  30. });
  31. it('should error on stream', function (done) {
  32. const srcFile = new Vinyl({
  33. path: 'test/fixtures/index.html',
  34. cwd: 'test/',
  35. base: 'test/fixtures',
  36. contents: fs.createReadStream('test/fixtures/index.html')
  37. });
  38. const stream = injectJS();
  39. stream.on('error', function (error) {
  40. should.exist(error);
  41. done();
  42. });
  43. stream.on('data', function (newFile) {
  44. newFile.contents.pipe(es.wait(function (error) {
  45. done(error);
  46. }));
  47. });
  48. stream.write(srcFile);
  49. stream.end();
  50. });
  51. });