test.js 1.1 KB

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