// Karma configuration
// Generated on Sun Apr 10 2016 12:06:14 GMT+0200 (Central European Daylight Time)

module.exports = function (config) {
    if (process.env.TRAVIS && (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY)) {
        console.log('Make sure the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are set.');
        process.exit(1);
    }

    var customLaunchers = new CustomLaunchers();

    customLaunchers
        .addChrome('35', '36', '44', '45')('Windows 8')
        .addEdge('13.10586')('Windows 10')
        .addOpera('12.12')('Windows 7')
        .addSafari('7.0')('OS X 10.9')
        .addSafari('8.0')('OS X 10.10')
        .addSafari('9.0')('OS X 10.11')
        .addFirefox('6.0', '33', '34')('Windows 8')
        .addFirefox('6.0', '33', '34')();

    config.set({

        // base path that will be used to resolve all patterns (eg. files, exclude)
        basePath: '',

        // frameworks to use
        // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
        frameworks: ['systemjs', 'jasmine'],


        // list of files / patterns to load in the browser
        files: [
            'tests/*-spec.ts',
            'tests/*-specs.ts'
        ],


        // list of files to exclude
        exclude: [],


        // preprocess matching files before serving them to the browser
        // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
        preprocessors: {},

        // test results reporter to use
        // possible values: 'dots', 'progress'
        // available reporters: https://npmjs.org/browse/keyword/karma-reporter
        reporters: process.env.TRAVIS ? ['progress', 'saucelabs'] : ['progress'],


        // web server port
        port: 9876,


        // enable / disable colors in the output (reporters and logs)
        colors: true,


        // level of logging
        // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
        logLevel: config.LOG_INFO,


        // enable / disable watching file and executing tests whenever any file changes
        autoWatch: true,


        // start these browsers
        // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
        browsers: process.env.TRAVIS ? Object.keys(customLaunchers) :['Chrome'],


        // Continuous Integration mode
        // if true, Karma captures browsers, runs the tests and exits
        singleRun: process.env.TRAVIS ? true : false,

        // Concurrency level
        // how many browser should be started simultaneous
        concurrency: 4,


        systemjs: {
            configFile: 'config.js',
            config: {
                paths: {
                    "typescript": "node_modules/typescript/lib/typescript.js",
                    "systemjs": "node_modules/systemjs/dist/system.js",
                    'system-polyfills': 'node_modules/systemjs/dist/system-polyfills.js',
                    'es6-module-loader': 'node_modules/es6-module-loader/dist/es6-module-loader.js'
                },
                packages: {
                    'tests': {
                        defaultExtension: 'ts'
                    },
                    'src': {
                        defaultExtension: 'ts'
                    }
                },
                transpiler: 'typescript'
            },
            serveFiles: [
                'src/**/*.ts',
                'tests/**/*.ts',
                'jspm_packages/**/*'
            ]
        },

        customLaunchers: customLaunchers,
        
        sauceLabs: {
            testName: 'Web App Unit Tests'
        }
    })
};

function CustomLaunchers() {
    var self = this;

    this.addChrome = addBrowser('chrome');
    this.addEdge = addBrowser('MicrosoftEdge');
    this.addOpera = addBrowser('opera');
    this.addSafari = addBrowser('safari');
    this.addFirefox = addBrowser('firefox');

    function addBrowser(browser) {
        return function () {
            var versions = Array.from(arguments);
            return function (system) {
                versions.forEach(function (version) {
                    var browserName = browser + '_' + version + '_' + (system || 'linux').replace(' ', '_');

                    self[browserName] = {
                        base: 'SauceLabs',
                        browserName: browser,
                        version: version
                    };

                    if (system) {
                        self[browserName].platform = system;
                    }
                });

                return self;
            };
        };
    }
}

@@ -2327,16 +2327,28 @@
 v.TRAVIS
+%0A           
  ? Objec
@@ -2370,16 +2370,85 @@
 unchers)
+.filter(function(key) %7B return !key.startsWith('add'); %7D)%0A           
  :%5B'Chro
@@ -2450,25 +2450,24 @@
 'Chrome'%5D,%0A%0A
-%0A
         // C

exclude non-browsers