bind.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _jestUtil() {
  7. const data = require('jest-util');
  8. _jestUtil = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. var _array = _interopRequireDefault(require('./table/array'));
  14. var _template = _interopRequireDefault(require('./table/template'));
  15. var _validation = require('./validation');
  16. function _interopRequireDefault(obj) {
  17. return obj && obj.__esModule ? obj : {default: obj};
  18. }
  19. /**
  20. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  21. *
  22. * This source code is licensed under the MIT license found in the
  23. * LICENSE file in the root directory of this source tree.
  24. *
  25. */
  26. var _default = (cb, supportsDone = true) => (table, ...taggedTemplateData) =>
  27. function eachBind(title, test, timeout) {
  28. try {
  29. const tests = isArrayTable(taggedTemplateData)
  30. ? buildArrayTests(title, table)
  31. : buildTemplateTests(title, table, taggedTemplateData);
  32. return tests.forEach(row =>
  33. cb(
  34. row.title,
  35. applyArguments(supportsDone, row.arguments, test),
  36. timeout
  37. )
  38. );
  39. } catch (e) {
  40. const error = new (_jestUtil().ErrorWithStack)(e.message, eachBind);
  41. return cb(title, () => {
  42. throw error;
  43. });
  44. }
  45. };
  46. exports.default = _default;
  47. const isArrayTable = data => data.length === 0;
  48. const buildArrayTests = (title, table) => {
  49. (0, _validation.validateArrayTable)(table);
  50. return (0, _array.default)(title, table);
  51. };
  52. const buildTemplateTests = (title, table, taggedTemplateData) => {
  53. const headings = getHeadingKeys(table[0]);
  54. (0, _validation.validateTemplateTableHeadings)(headings, taggedTemplateData);
  55. return (0, _template.default)(title, headings, taggedTemplateData);
  56. };
  57. const getHeadingKeys = headings => headings.replace(/\s/g, '').split('|');
  58. const applyArguments = (supportsDone, params, test) =>
  59. supportsDone && params.length < test.length
  60. ? done => test(...params, done)
  61. : () => test(...params);