(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", "../lib/executors/Browser", "../lib/browser/util", "../lib/common/util", "../lib/Channel", "@dojo/shim/global"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Browser_1 = require("../lib/executors/Browser");
    var util_1 = require("../lib/browser/util");
    var util_2 = require("../lib/common/util");
    var Channel_1 = require("../lib/Channel");
    var global_1 = require("@dojo/shim/global");
    // A Benchmark global needs to be defined for benchmark.js to work properly when loaded as part of the Intern browser
    // bundle since neither Node's require nor an AMD define will be present.
    global_1.default.Benchmark = {};
    var config = util_2.parseArgs(util_1.parseQuery());
    var channel = new Channel_1.default({
        url: config.serverUrl,
        sessionId: config.sessionId,
        port: config.socketPort
    });
    function displayMessage(message) {
        var pre = document.createElement('pre');
        pre.textContent = message;
        document.body.appendChild(pre);
        window.scrollTo(0, pre.offsetTop);
    }
    try {
        var intern_1 = global_1.default.intern = new Browser_1.default(config);
        // Forward all executor events back to the Intern host
        intern_1.on('*', function (_a) {
            var name = _a.name, data = _a.data;
            var promise = channel.sendMessage(name, data).catch(function (error) {
                displayMessage("Error sending " + name + ": " + error.message);
                console.error(error);
            });
            // If config.runInSync is true, return the message promise so that Intern will wait for acknowledgement before
            // continuing testing
            if (config.runInSync) {
                return promise;
            }
        });
        channel.sendMessage('remoteStatus', 'initialized');
        // Intern will be further configured and started via an execute command from RemoteSuite
    }
    catch (error) {
        displayMessage(error.message);
        channel.sendMessage('error', error);
    }
});
//# sourceMappingURL=remote.src.js.map