"use strict";
/**
 * A loader script for setting up the Dojo loader.
 *
 * Note that loader scripts must be simple scripts, not modules.
 */
intern.registerLoader(function (options) {
    var globalObj = typeof window !== 'undefined' ? window : global;
    options.baseUrl = options.baseUrl || intern.config.basePath;
    if (!('async' in options)) {
        options.async = true;
    }
    intern.log('Configuring Dojo loader with:', options);
    globalObj.dojoConfig = options;
    return intern.loadScript('node_modules/dojo/dojo.js').then(function () {
        var require = globalObj.require;
        intern.log('Using Dojo loader');
        return function (modules) {
            var handle;
            return new Promise(function (resolve, reject) {
                handle = require.on('error', function (error) {
                    intern.emit('error', error);
                    reject(new Error("Dojo loader error: " + error.message));
                });
                intern.log('Loading modules:', modules);
                require(modules, function () { resolve(); });
            }).then(function () { handle.remove(); }, function (error) {
                handle && handle.remove();
                throw error;
            });
        };
    });
});
//# sourceMappingURL=dojo.js.map