"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.startupTest = void 0;
const adapter_1 = require("./adapter");
const karma_1 = require("./karma");
const platform_1 = require("./platform");
const updater_1 = require("./updater");
function startupTest() {
    const socket = new platform_1.IO();
    const updater = new updater_1.StatusUpdater(socket);
    const karmaClient = new karma_1.KarmaClient(updater, socket);
    if (KARMA_CLIENT_CONFIG.captureConsole) {
        // patch the console
        const localConsole = console || {
            log: function () { },
            info: function () { },
            warn: function () { },
            error: function () { },
            debug: function () { },
        };
        const logMethods = [
            'log',
            'info',
            'warn',
            'error',
            'debug',
        ];
        const patchConsoleMethod = function (method) {
            const orig = localConsole[method];
            if (!orig) {
                return;
            }
            localConsole[method] = function () {
                try {
                    return Function.prototype.apply.call(orig, localConsole, arguments);
                }
                catch (error) {
                    karmaClient.log('warn', [
                        'Console method ' + method + ' threw: ' + error,
                    ]);
                }
                karmaClient.log(method, Array.from(arguments));
            };
        };
        for (let i = 0; i < logMethods.length; i++) {
            patchConsoleMethod(logMethods[i]);
        }
    }
    (0, adapter_1.createStartFn)(karmaClient, jasmine.getEnv())();
}
exports.startupTest = startupTest;
//# sourceMappingURL=main.js.map