common.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. 'use strict';
  2. /**
  3. * Functions common to more than one interface.
  4. *
  5. * @param {Suite[]} suites
  6. * @param {Context} context
  7. * @return {Object} An object containing common functions.
  8. */
  9. module.exports = function(suites, context) {
  10. return {
  11. /**
  12. * This is only present if flag --delay is passed into Mocha. It triggers
  13. * root suite execution.
  14. *
  15. * @param {Suite} suite The root wuite.
  16. * @return {Function} A function which runs the root suite
  17. */
  18. runWithSuite: function runWithSuite(suite) {
  19. return function run() {
  20. suite.run();
  21. };
  22. },
  23. /**
  24. * Execute before running tests.
  25. *
  26. * @param {string} name
  27. * @param {Function} fn
  28. */
  29. before: function(name, fn) {
  30. suites[0].beforeAll(name, fn);
  31. },
  32. /**
  33. * Execute after running tests.
  34. *
  35. * @param {string} name
  36. * @param {Function} fn
  37. */
  38. after: function(name, fn) {
  39. suites[0].afterAll(name, fn);
  40. },
  41. /**
  42. * Execute before each test case.
  43. *
  44. * @param {string} name
  45. * @param {Function} fn
  46. */
  47. beforeEach: function(name, fn) {
  48. suites[0].beforeEach(name, fn);
  49. },
  50. /**
  51. * Execute after each test case.
  52. *
  53. * @param {string} name
  54. * @param {Function} fn
  55. */
  56. afterEach: function(name, fn) {
  57. suites[0].afterEach(name, fn);
  58. },
  59. test: {
  60. /**
  61. * Pending test case.
  62. *
  63. * @param {string} title
  64. */
  65. skip: function(title) {
  66. context.test(title);
  67. },
  68. /**
  69. * Number of retry attempts
  70. *
  71. * @param {number} n
  72. */
  73. retries: function(n) {
  74. context.retries(n);
  75. }
  76. }
  77. };
  78. };