BaseRollingFileStream-test.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. "use strict";
  2. var vows = require('vows')
  3. , assert = require('assert')
  4. , fs = require('fs')
  5. , sandbox = require('sandboxed-module');
  6. vows.describe('../../lib/streams/BaseRollingFileStream').addBatch({
  7. 'when node version < 0.10.0': {
  8. topic: function() {
  9. var streamLib = sandbox.load(
  10. '../../lib/streams/BaseRollingFileStream',
  11. {
  12. globals: {
  13. process: {
  14. version: '0.8.11'
  15. }
  16. },
  17. requires: {
  18. 'readable-stream': {
  19. Writable: function() {}
  20. }
  21. }
  22. }
  23. );
  24. return streamLib.required;
  25. },
  26. 'it should use readable-stream to maintain compatibility': function(required) {
  27. assert.ok(required['readable-stream']);
  28. assert.ok(!required.stream);
  29. }
  30. },
  31. 'when node version > 0.10.0': {
  32. topic: function() {
  33. var streamLib = sandbox.load(
  34. '../../lib/streams/BaseRollingFileStream',
  35. {
  36. globals: {
  37. process: {
  38. version: '0.10.1'
  39. }
  40. },
  41. requires: {
  42. 'stream': {
  43. Writable: function() {}
  44. }
  45. }
  46. }
  47. );
  48. return streamLib.required;
  49. },
  50. 'it should use the core stream module': function(required) {
  51. assert.ok(required.stream);
  52. assert.ok(!required['readable-stream']);
  53. }
  54. },
  55. 'when no filename is passed': {
  56. topic: require('../../lib/streams/BaseRollingFileStream'),
  57. 'it should throw an error': function(BaseRollingFileStream) {
  58. try {
  59. new BaseRollingFileStream();
  60. assert.fail('should not get here');
  61. } catch (e) {
  62. assert.ok(e);
  63. }
  64. }
  65. },
  66. 'default behaviour': {
  67. topic: function() {
  68. var BaseRollingFileStream = require('../../lib/streams/BaseRollingFileStream')
  69. , stream = new BaseRollingFileStream('basetest.log');
  70. return stream;
  71. },
  72. teardown: function() {
  73. try {
  74. fs.unlink('basetest.log');
  75. } catch (e) {
  76. console.error("could not remove basetest.log", e);
  77. }
  78. },
  79. 'it should not want to roll': function(stream) {
  80. assert.isFalse(stream.shouldRoll());
  81. },
  82. 'it should not roll': function(stream) {
  83. var cbCalled = false;
  84. //just calls the callback straight away, no async calls
  85. stream.roll('basetest.log', function() { cbCalled = true; });
  86. assert.isTrue(cbCalled);
  87. }
  88. }
  89. }).exportTo(module);