"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
            t[p] = s[p];
    }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var Suite_1 = require("../Suite");
var Test_1 = require("../Test");
function getInterface(executor) {
    return {
        registerSuite: function (descriptor) {
            if (isSuiteDescriptorFactory(descriptor)) {
                descriptor = descriptor();
            }
            registerSuite(executor, descriptor, Suite_1.default, Test_1.default);
        }
    };
}
exports.default = getInterface;
function isSuiteDescriptorFactory(value) {
    return typeof value === 'function';
}
exports.isSuiteDescriptorFactory = isSuiteDescriptorFactory;
function registerSuite(executor, descriptor, SuiteClass, TestClass) {
    executor.addTest(createSuite(descriptor, SuiteClass, TestClass));
}
exports.registerSuite = registerSuite;
function isNestedSuiteDescriptor(value) {
    return value && typeof value.tests === 'object';
}
function createSuite(descriptor, SuiteClass, TestClass) {
    var options = { name: null, tests: [] };
    Object.keys(descriptor).filter(function (key) {
        return key !== 'tests';
    }).forEach(function (key) {
        options[key] = descriptor[key];
    });
    var suite = new SuiteClass(options);
    var tests = descriptor.tests;
    Object.keys(tests).map(function (name) {
        var thing = tests[name];
        if (isNestedSuiteDescriptor(thing)) {
            return createSuite(__assign({ name: name }, thing), SuiteClass, TestClass);
        }
        return new TestClass({ name: name, test: thing });
    }).forEach(function (suiteOrTest) {
        suite.add(suiteOrTest);
    });
    return suite;
}
//# sourceMappingURL=object.js.map