exports.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * Module dependencies.
  3. */
  4. var Suite = require('../suite')
  5. , Test = require('../test');
  6. /**
  7. * TDD-style interface:
  8. *
  9. * exports.Array = {
  10. * '#indexOf()': {
  11. * 'should return -1 when the value is not present': function(){
  12. *
  13. * },
  14. *
  15. * 'should return the correct index when the value is present': function(){
  16. *
  17. * }
  18. * }
  19. * };
  20. *
  21. */
  22. module.exports = function(suite){
  23. var suites = [suite];
  24. suite.on('require', visit);
  25. function visit(obj) {
  26. var suite;
  27. for (var key in obj) {
  28. if ('function' == typeof obj[key]) {
  29. var fn = obj[key];
  30. switch (key) {
  31. case 'before':
  32. suites[0].beforeAll(fn);
  33. break;
  34. case 'after':
  35. suites[0].afterAll(fn);
  36. break;
  37. case 'beforeEach':
  38. suites[0].beforeEach(fn);
  39. break;
  40. case 'afterEach':
  41. suites[0].afterEach(fn);
  42. break;
  43. default:
  44. suites[0].addTest(new Test(key, fn));
  45. }
  46. } else {
  47. var suite = Suite.create(suites[0], key);
  48. suites.unshift(suite);
  49. visit(obj[key]);
  50. suites.shift();
  51. }
  52. }
  53. }
  54. };