1 | (function (factory) {
|
2 | if (typeof module === "object" && typeof module.exports === "object") {
|
3 | var v = factory(require, exports);
|
4 | if (v !== undefined) module.exports = v;
|
5 | }
|
6 | else if (typeof define === "function" && define.amd) {
|
7 | define(["require", "exports", "tslib", "@theintern/common", "../Suite", "../Test"], factory);
|
8 | }
|
9 | })(function (require, exports) {
|
10 | "use strict";
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | exports.createSuite = exports.isSuiteDescriptorFactory = exports.getInterface = void 0;
|
13 | var tslib_1 = require("tslib");
|
14 | var common_1 = require("@theintern/common");
|
15 | var Suite_1 = tslib_1.__importDefault(require("../Suite"));
|
16 | var Test_1 = tslib_1.__importStar(require("../Test"));
|
17 | function registerSuite(name, descriptorOrFactory) {
|
18 | return _registerSuite(common_1.global.intern, name, descriptorOrFactory);
|
19 | }
|
20 | exports.default = registerSuite;
|
21 | function getInterface(executor) {
|
22 | return {
|
23 | registerSuite: function (name, descriptorOrFactory) {
|
24 | return _registerSuite(executor, name, descriptorOrFactory);
|
25 | }
|
26 | };
|
27 | }
|
28 | exports.getInterface = getInterface;
|
29 | function isSuiteDescriptorFactory(value) {
|
30 | return typeof value === 'function';
|
31 | }
|
32 | exports.isSuiteDescriptorFactory = isSuiteDescriptorFactory;
|
33 | function createSuite(name, parent, descriptor, SuiteClass, TestClass) {
|
34 | var options = { name: name, parent: parent };
|
35 | var tests;
|
36 | if (isObjectSuiteDescriptor(descriptor)) {
|
37 | var keys = Object.keys(descriptor).filter(function (key) { return key !== 'tests'; });
|
38 | for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
39 | var key = keys_1[_i];
|
40 | var optionsKey = key;
|
41 | if (key === 'setup') {
|
42 | parent.executor.emit('deprecated', {
|
43 | original: 'Suite#setup',
|
44 | replacement: 'Suite#before'
|
45 | });
|
46 | optionsKey = 'before';
|
47 | }
|
48 | else if (key === 'teardown') {
|
49 | parent.executor.emit('deprecated', {
|
50 | original: 'Suite#teardown',
|
51 | replacement: 'Suite#after'
|
52 | });
|
53 | optionsKey = 'after';
|
54 | }
|
55 | options[optionsKey] =
|
56 | descriptor[key];
|
57 | }
|
58 | tests = descriptor.tests;
|
59 | }
|
60 | else {
|
61 | tests = descriptor;
|
62 | }
|
63 | var suite = new SuiteClass(options);
|
64 | Object.keys(tests)
|
65 | .map(function (name) {
|
66 | if (name === 'before' ||
|
67 | name === 'after' ||
|
68 | name === 'setup' ||
|
69 | name === 'teardown' ||
|
70 | name === 'beforeEach' ||
|
71 | name === 'afterEach') {
|
72 | parent.executor.log("Warning: created test with lifecycle method name \"" + name + "\"");
|
73 | }
|
74 | var thing = tests[name];
|
75 | if (Test_1.isTestFunction(thing)) {
|
76 | return new TestClass({ name: name, test: thing, parent: suite });
|
77 | }
|
78 | return createSuite(name, suite, tslib_1.__assign({}, thing), SuiteClass, TestClass);
|
79 | })
|
80 | .forEach(function (suiteOrTest) {
|
81 | suite.add(suiteOrTest);
|
82 | });
|
83 | return suite;
|
84 | }
|
85 | exports.createSuite = createSuite;
|
86 | function isObjectSuiteDescriptor(value) {
|
87 | return typeof value === 'object' && typeof value.tests === 'object';
|
88 | }
|
89 | function _registerSuite(executor, name, descriptorOrFactory) {
|
90 | executor.addSuite(function (parent) {
|
91 | var descriptor;
|
92 | if (isSuiteDescriptorFactory(descriptorOrFactory)) {
|
93 | descriptor = descriptorOrFactory();
|
94 | }
|
95 | else {
|
96 | descriptor = descriptorOrFactory;
|
97 | }
|
98 | parent.add(createSuite(name, parent, descriptor, Suite_1.default, Test_1.default));
|
99 | });
|
100 | }
|
101 | });
|
102 |
|
\ | No newline at end of file |