import { TYPED_TEST } from '../types';
import { createTest } from './createTest';
import { getModifier } from './getModifier';
import { updateModifier } from './updateModifier';
export function describe(what, tests) {
    const hasOnly = tests.some(x => x[TYPED_TEST].modifier === 'only');
    const allSkip = tests.every(x => x[TYPED_TEST].modifier === 'skip');
    const modifier = hasOnly ? 'only' : allSkip ? 'skip' : void 0;
    const testsToRun = modifier === 'only'
        ? tests.map(x => (getModifier(x) === 'only' ? x : updateModifier('skip', x)))
        : tests;
    const test = createTest(`${what}`, spec => {
        return Promise.all(testsToRun.map(t => {
            return t
                .runTest(Object.assign({}, spec, { skip: getModifier(t) === 'skip' || spec.skip }))
                .then(r => (Object.assign({}, r, { name: t[TYPED_TEST].name })));
        })).then(results => ({ type: 'group', results, name: test[TYPED_TEST].name }));
    });
    return modifier ? updateModifier(modifier, test) : test;
}
(function (describe) {
    function only(what, tests) {
        const test = describe(what, tests);
        return Object.assign({}, test, { [TYPED_TEST]: Object.assign({}, test[TYPED_TEST], { modifier: 'only' }) });
    }
    describe.only = only;
    function skip(what, tests) {
        return describe(what, tests.map(x => updateModifier('skip', x)));
    }
    describe.skip = skip;
})(describe || (describe = {}));
//# sourceMappingURL=describe.js.map