(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "@dojo/core/aspect", "../Suite", "../Test", "../../intern"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var aspect_1 = require("@dojo/core/aspect");
    var Suite_1 = require("../Suite");
    var Test_1 = require("../Test");
    var intern_1 = require("../../intern");
    function suite(name, factory) {
        return _suite(intern_1.default(), name, factory);
    }
    exports.suite = suite;
    function test(name, test) {
        if (!currentSuite) {
            throw new Error('A test must be declared within a suite');
        }
        currentSuite.add(new Test_1.default({ name: name, test: test }));
    }
    exports.test = test;
    function before(fn) {
        if (!currentSuite) {
            throw new Error("A suite lifecycle method must be declared within a suite");
        }
        aspect_1.on(currentSuite, 'before', fn);
    }
    exports.before = before;
    function after(fn) {
        if (!currentSuite) {
            throw new Error("A suite lifecycle method must be declared within a suite");
        }
        aspect_1.on(currentSuite, 'after', fn);
    }
    exports.after = after;
    function beforeEach(fn) {
        if (!currentSuite) {
            throw new Error("A suite lifecycle method must be declared within a suite");
        }
        aspect_1.on(currentSuite, 'beforeEach', fn);
    }
    exports.beforeEach = beforeEach;
    function afterEach(fn) {
        if (!currentSuite) {
            throw new Error("A suite lifecycle method must be declared within a suite");
        }
        aspect_1.on(currentSuite, 'afterEach', fn);
    }
    exports.afterEach = afterEach;
    function getInterface(executor) {
        return {
            suite: function (name, factory) {
                return _suite(executor, name, factory);
            },
            test: test,
            before: before,
            after: after,
            beforeEach: beforeEach,
            afterEach: afterEach
        };
    }
    exports.getInterface = getInterface;
    var currentSuite;
    function registerSuite(name, factory) {
        var parent = currentSuite;
        currentSuite = new Suite_1.default({ name: name, parent: parent });
        parent.add(currentSuite);
        factory(currentSuite);
        currentSuite = parent;
    }
    function _suite(executor, name, factory) {
        if (!currentSuite) {
            executor.addSuite(function (parent) {
                currentSuite = parent;
                registerSuite(name, factory);
                currentSuite = null;
            });
        }
        else {
            registerSuite(name, factory);
        }
    }
});
//# sourceMappingURL=tdd.js.map