"use strict";
/// <reference types="systemjs"/>
/**
 * A loader script for setting up the SystemJS loader.
 *
 * Note that loader scripts must be simple scripts, not modules.
 */
intern.registerLoader(function (options) {
    options.baseURL = options.baseURL || intern.config.basePath;
    var globalObj = typeof window !== 'undefined' ? window : global;
    if (intern.environment === 'browser') {
        return intern.loadScript('node_modules/systemjs/dist/system.src.js').then(function () {
            return configAndLoad(SystemJS);
        });
    }
    else {
        // Use globalObj to get to require to improve testability
        var SystemJS_1 = globalObj.require('systemjs');
        return configAndLoad(SystemJS_1);
    }
    function configAndLoad(loader) {
        intern.log('Using SystemJS loader');
        intern.log('Configuring SystemJS with:', options);
        loader.config(options);
        return function (modules) {
            intern.log('Loading modules with SystemJS:', modules);
            return modules.reduce(function (previous, suite) {
                if (previous) {
                    return previous.then(function () { return loader.import(suite); });
                }
                return loader.import(suite);
            }, null);
        };
    }
});
//# sourceMappingURL=systemjs.js.map