index.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. Object.defineProperty(exports, 'bind', {
  6. enumerable: true,
  7. get: function () {
  8. return _bind.default;
  9. }
  10. });
  11. exports.default = void 0;
  12. var _bind = _interopRequireDefault(require('./bind'));
  13. function _interopRequireDefault(obj) {
  14. return obj && obj.__esModule ? obj : {default: obj};
  15. }
  16. /**
  17. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  18. *
  19. * This source code is licensed under the MIT license found in the
  20. * LICENSE file in the root directory of this source tree.
  21. *
  22. */
  23. const install = (g, table, ...data) => {
  24. const bindingWithArray = data.length === 0;
  25. const bindingWithTemplate = Array.isArray(table) && !!table.raw;
  26. if (!bindingWithArray && !bindingWithTemplate) {
  27. throw new Error(
  28. '`.each` must only be called with an Array or Tagged Template Literal.'
  29. );
  30. }
  31. const test = (title, test, timeout) =>
  32. (0, _bind.default)(g.test)(table, ...data)(title, test, timeout);
  33. test.skip = (0, _bind.default)(g.test.skip)(table, ...data);
  34. test.only = (0, _bind.default)(g.test.only)(table, ...data);
  35. const testConcurrent = (title, test, timeout) =>
  36. (0, _bind.default)(g.test.concurrent)(table, ...data)(title, test, timeout);
  37. test.concurrent = testConcurrent;
  38. testConcurrent.only = (0, _bind.default)(g.test.concurrent.only)(
  39. table,
  40. ...data
  41. );
  42. testConcurrent.skip = (0, _bind.default)(g.test.concurrent.skip)(
  43. table,
  44. ...data
  45. );
  46. const it = (title, test, timeout) =>
  47. (0, _bind.default)(g.it)(table, ...data)(title, test, timeout);
  48. it.skip = (0, _bind.default)(g.it.skip)(table, ...data);
  49. it.only = (0, _bind.default)(g.it.only)(table, ...data);
  50. it.concurrent = testConcurrent;
  51. const xit = (0, _bind.default)(g.xit)(table, ...data);
  52. const fit = (0, _bind.default)(g.fit)(table, ...data);
  53. const xtest = (0, _bind.default)(g.xtest)(table, ...data);
  54. const describe = (title, suite, timeout) =>
  55. (0, _bind.default)(g.describe, false)(table, ...data)(
  56. title,
  57. suite,
  58. timeout
  59. );
  60. describe.skip = (0, _bind.default)(g.describe.skip, false)(table, ...data);
  61. describe.only = (0, _bind.default)(g.describe.only, false)(table, ...data);
  62. const fdescribe = (0, _bind.default)(g.fdescribe, false)(table, ...data);
  63. const xdescribe = (0, _bind.default)(g.xdescribe, false)(table, ...data);
  64. return {
  65. describe,
  66. fdescribe,
  67. fit,
  68. it,
  69. test,
  70. xdescribe,
  71. xit,
  72. xtest
  73. };
  74. };
  75. const each = (table, ...data) => install(global, table, ...data);
  76. each.withGlobal = g => (table, ...data) => install(g, table, ...data);
  77. var _default = each;
  78. exports.default = _default;