test.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. describe('enabled', function () {
  2. 'use strict';
  3. var assume = require('assume')
  4. , enabled = require('./');
  5. beforeEach(function () {
  6. process.env.DEBUG = '';
  7. process.env.DIAGNOSTICS = '';
  8. });
  9. it('uses the `debug` env', function () {
  10. process.env.DEBUG = 'bigpipe';
  11. assume(enabled('bigpipe')).to.be.true();
  12. assume(enabled('false')).to.be.false();
  13. });
  14. it('uses the `diagnostics` env', function () {
  15. process.env.DIAGNOSTICS = 'bigpipe';
  16. assume(enabled('bigpipe')).to.be.true();
  17. assume(enabled('false')).to.be.false();
  18. });
  19. it('supports wildcards', function () {
  20. process.env.DEBUG = 'b*';
  21. assume(enabled('bigpipe')).to.be.true();
  22. assume(enabled('bro-fist')).to.be.true();
  23. assume(enabled('ro-fist')).to.be.false();
  24. });
  25. it('is disabled by default', function () {
  26. process.env.DEBUG = '';
  27. assume(enabled('bigpipe')).to.be.false();
  28. process.env.DEBUG = 'bigpipe';
  29. assume(enabled('bigpipe')).to.be.true();
  30. });
  31. it('can ignore loggers using a -', function () {
  32. process.env.DEBUG = 'bigpipe,-primus,sack,-other';
  33. assume(enabled('bigpipe')).to.be.true();
  34. assume(enabled('sack')).to.be.true();
  35. assume(enabled('primus')).to.be.false();
  36. assume(enabled('other')).to.be.false();
  37. assume(enabled('unknown')).to.be.false();
  38. });
  39. it('supports multiple ranges', function () {
  40. process.env.DEBUG = 'bigpipe*,primus*';
  41. assume(enabled('bigpipe:')).to.be.true();
  42. assume(enabled('bigpipes')).to.be.true();
  43. assume(enabled('primus:')).to.be.true();
  44. assume(enabled('primush')).to.be.true();
  45. assume(enabled('unknown')).to.be.false();
  46. });
  47. });