UNPKG

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