log-abspath-test.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. "use strict";
  2. var vows = require('vows')
  3. , assert = require('assert')
  4. , sandbox = require('sandboxed-module');
  5. vows.describe('log4js-abspath').addBatch({
  6. 'options': {
  7. topic: function() {
  8. var appenderOptions,
  9. log4js = sandbox.require(
  10. '../lib/log4js',
  11. { requires:
  12. { './appenders/fake':
  13. { name: "fake",
  14. appender: function() {},
  15. configure: function(configuration, options) {
  16. appenderOptions = options;
  17. return function() {};
  18. }
  19. }
  20. }
  21. }
  22. ),
  23. config = {
  24. "appenders": [
  25. {
  26. "type" : "fake",
  27. "filename" : "cheesy-wotsits.log"
  28. }
  29. ]
  30. };
  31. log4js.configure(config, {
  32. cwd: '/absolute/path/to'
  33. });
  34. return appenderOptions;
  35. },
  36. 'should be passed to appenders during configuration': function(options) {
  37. assert.equal(options.cwd, '/absolute/path/to');
  38. }
  39. },
  40. 'file appender': {
  41. topic: function() {
  42. var fileOpened,
  43. fileAppender = sandbox.require(
  44. '../lib/appenders/file',
  45. { requires:
  46. { '../streams':
  47. { RollingFileStream:
  48. function(file) {
  49. fileOpened = file;
  50. return {
  51. on: function() {},
  52. end: function() {}
  53. };
  54. }
  55. }
  56. }
  57. }
  58. );
  59. fileAppender.configure(
  60. {
  61. filename: "whatever.log",
  62. maxLogSize: 10
  63. },
  64. { cwd: '/absolute/path/to' }
  65. );
  66. return fileOpened;
  67. },
  68. 'should prepend options.cwd to config.filename': function(fileOpened) {
  69. assert.equal(fileOpened, "/absolute/path/to/whatever.log");
  70. }
  71. },
  72. }).export(module);