stream.test.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. const path = require('path');
  3. const writeable = require('../helpers').writeable;
  4. const { MESSAGE } = require('triple-beam');
  5. const os = require('os');
  6. const winston = require('../../');
  7. const split = require('split2');
  8. const assume = require('assume');
  9. describe('Stream({ stream })', function () {
  10. it('should support objectMode streams', function (done) {
  11. const expected = {
  12. level: 'info',
  13. message: 'lolwut testing!'
  14. };
  15. const stream = writeable(function (info) {
  16. assume(info).equals(expected);
  17. done();
  18. });
  19. const transport = new winston.transports.Stream({ stream });
  20. transport.log(expected);
  21. });
  22. it('should support UTF8 encoding streams', function (done) {
  23. const expected = {
  24. level: 'info',
  25. message: 'lolwut testing!',
  26. [MESSAGE]: 'info: lolwut testing!'
  27. };
  28. const stream = writeable(function (raw) {
  29. assume(raw.toString()).equals(`${expected[MESSAGE]}${os.EOL}`);
  30. done();
  31. }, false);
  32. const transport = new winston.transports.Stream({ stream });
  33. transport.log(expected);
  34. });
  35. it('should throw when not passed a stream', function () {
  36. assume(function () {
  37. const stream = new winston.transports.Stream()
  38. }).throws('options.stream is required.');''
  39. });
  40. });