test.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. var Runnable = require('./runnable');
  3. var utils = require('./utils');
  4. var isString = utils.isString;
  5. module.exports = Test;
  6. /**
  7. * Initialize a new `Test` with the given `title` and callback `fn`.
  8. *
  9. * @class
  10. * @extends Runnable
  11. * @param {String} title
  12. * @param {Function} fn
  13. */
  14. function Test(title, fn) {
  15. if (!isString(title)) {
  16. throw new Error(
  17. 'Test `title` should be a "string" but "' +
  18. typeof title +
  19. '" was given instead.'
  20. );
  21. }
  22. Runnable.call(this, title, fn);
  23. this.pending = !fn;
  24. this.type = 'test';
  25. }
  26. /**
  27. * Inherit from `Runnable.prototype`.
  28. */
  29. utils.inherits(Test, Runnable);
  30. Test.prototype.clone = function() {
  31. var test = new Test(this.title, this.fn);
  32. test.timeout(this.timeout());
  33. test.slow(this.slow());
  34. test.enableTimeouts(this.enableTimeouts());
  35. test.retries(this.retries());
  36. test.currentRetry(this.currentRetry());
  37. test.globals(this.globals());
  38. test.parent = this.parent;
  39. test.file = this.file;
  40. test.ctx = this.ctx;
  41. return test;
  42. };