gulp-print.test.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import 'mocha';
  2. import * as colors from 'ansi-colors';
  3. import * as chai from 'chai';
  4. import * as path from 'path';
  5. import * as sinon from 'sinon';
  6. import * as Vinyl from 'vinyl';
  7. import { Writable } from 'stream';
  8. import print, { setLogFunction } from '../src/gulp-print';
  9. chai.use(require('sinon-chai'));
  10. describe('gulp-print', () => {
  11. let logStub: sinon.SinonStub;
  12. beforeEach(() => {
  13. logStub = sinon.stub();
  14. setLogFunction(logStub);
  15. });
  16. describe('passing formatting function', () => {
  17. it('logs file path using default formatter', done => {
  18. const stream = print() as Writable;
  19. const filepath = path.join(process.cwd(), 'foo/bar.js');
  20. stream.on('end', () => {
  21. chai.expect(logStub).to.have.been.calledWith(colors.magenta(path.relative(process.cwd(), filepath)));
  22. done();
  23. });
  24. stream.write(new Vinyl({ path: filepath }));
  25. stream.end();
  26. });
  27. it('logs file paths using custom formatter', done => {
  28. const stream = print(filepath => `Hello ${filepath}`) as Writable;
  29. const filepath = path.join(process.cwd(), 'foo/bar.js');
  30. stream.on('end', () => {
  31. chai.expect(logStub).to.have.been.calledWith(`Hello ${colors.magenta(path.relative(process.cwd(), filepath))}`);
  32. done();
  33. });
  34. stream.write(new Vinyl({ path: filepath }));
  35. stream.end();
  36. });
  37. });
  38. });