gulp-print.spec.coffee 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. require 'coffee-errors'
  2. path = require 'path'
  3. chai = require 'chai'
  4. sinon = require 'sinon'
  5. gutil = require 'gulp-util'
  6. # using compiled JavaScript file here to be sure module works
  7. print = require '../lib/gulp-print.js'
  8. expect = chai.expect
  9. chai.use require 'sinon-chai'
  10. describe 'gulp-print', ->
  11. beforeEach ->
  12. sinon.stub print, 'log'
  13. afterEach ->
  14. print.log.restore()
  15. describe 'passing formatting function', ->
  16. it 'logs file path using default formatter', (done) ->
  17. stream = print()
  18. filepath = path.join process.cwd(), 'foo/bar.js'
  19. stream.on 'end', ->
  20. expect(print.log).to.have.been.calledWith gutil.colors.magenta path.relative process.cwd(), filepath
  21. done()
  22. stream.write new gutil.File path: filepath
  23. stream.end()
  24. it 'logs file paths using custom formatter', (done) ->
  25. stream = print (filepath) -> "Hello #{filepath}"
  26. filepath = path.join process.cwd(), 'foo/bar.js'
  27. stream.on 'end', ->
  28. expect(print.log).to.have.been.calledWith "Hello #{gutil.colors.magenta path.relative process.cwd(), filepath}"
  29. done()
  30. stream.write new gutil.File path: filepath
  31. stream.end()