Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. const expect = require('chai').expect;
  2. const loglevel = require('loglevel');
  3. const other = require('loglevel-plugin-mock');
  4. const sinon = require('sinon');
  5. const prefix = require('../lib/loglevel-plugin-prefix');
  6. const spy = sinon.spy();
  7. loglevel.enableAll();
  8. describe('API', () => {
  9. it('Methods', () => {
  10. expect(prefix).to.have.property('apply').with.be.a('function');
  11. expect(prefix).to.have.property('reg').with.be.a('function');
  12. expect(prefix).not.to.have.property('noConflict');
  13. });
  14. it('Reg: empty arguments', () => {
  15. expect(prefix.reg).to.throw(TypeError, 'Argument is not a root logger');
  16. });
  17. it('Reg: incorrect argument', () => {
  18. expect(() => prefix.reg('logger')).to.throw(TypeError, 'Argument is not a root logger');
  19. });
  20. it('Apply: empty arguments', () => {
  21. expect(prefix.apply).to.throw(TypeError, 'Argument is not a logger');
  22. });
  23. it('Apply: incorrect argument', () => {
  24. expect(() => prefix.apply('logger')).to.throw(TypeError, 'Argument is not a logger');
  25. });
  26. });
  27. describe('Prefix', () => {
  28. other.apply(loglevel, { method: spy });
  29. beforeEach(() => {
  30. spy.reset();
  31. });
  32. it('Root applying', () => {
  33. expect(() => prefix.apply(loglevel)).to.not.throw();
  34. });
  35. it('Root reapplyng', () => {
  36. prefix.apply(loglevel, { template: '%l (%n):' });
  37. loglevel.info('test');
  38. expect(spy.calledWith('INFO (root): test')).to.be.true;
  39. });
  40. it('Format', () => {
  41. prefix.apply(loglevel, {
  42. format: (level, logger) => `${level} (${logger}):`
  43. });
  44. loglevel.info('test');
  45. expect(spy.calledWith('INFO (root): test')).to.be.true;
  46. });
  47. it('Unformat', () => {
  48. prefix.apply(loglevel, { template: '%l:' });
  49. loglevel.info('test');
  50. expect(spy.calledWith('INFO: test')).to.be.true;
  51. });
  52. it('The prefix must be combined with the first argument, if it is a string', () => {
  53. prefix.apply(loglevel, { template: '%l:' });
  54. loglevel.info('foo %s', 'bar');
  55. expect(spy.calledWith('INFO: foo %s', 'bar')).to.be.true;
  56. });
  57. it('All methods of the previous plugin should be called', () => {
  58. prefix.apply(loglevel);
  59. // for warn in apply
  60. spy.reset();
  61. loglevel.trace();
  62. loglevel.debug();
  63. loglevel.info();
  64. loglevel.warn();
  65. loglevel.error();
  66. expect(spy.callCount).to.equal(5);
  67. });
  68. it('Child applying', () => {
  69. const child = loglevel.getLogger('child');
  70. prefix.apply(child, { template: '%l (%n):' });
  71. child.info('test');
  72. expect(spy.calledWith('INFO (child): test')).to.be.true;
  73. });
  74. it('Child reapplyng', () => {
  75. const child = loglevel.getLogger('child');
  76. prefix.apply(child, {
  77. levelFormatter(level) {
  78. return level;
  79. }
  80. });
  81. child.info('test');
  82. expect(spy.calledWith('info (child): test')).to.be.true;
  83. });
  84. });