// 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.TB_KEY || !process.env.TB_SECRET)) {
        console.log('Make sure the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are set.');
        process.exit(1);
    }

    var customLaunchers = new CustomLaunchers();

    customLaunchers
        .addChrome('36', '42', '43', '44', '45')('Windows 8')
        .addEdge('13.10586')('Windows 10')
        .addIE('9.0', '10.0', '11.0')('Windows 7')
        .addIE('10.0')('Windows 8')
        .addIE('11.0')('Windows 8.1')
        .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', '38', '39')('Windows 8')
        .addFirefox('6.0', '33', '34', '38', '39')()
        .addLatest('chrome', 'OS X 10.11')
        .addLatest('chrome', 'Windows 8')
        .addLatest('chrome', 'linux')
        .addLatest('firefox', 'linux')
        .addLatest('firefox', 'Windows 10')
        .addLatest('firefox', 'OS X 10.11')
        .addLatest('MicrosoftEdge', 'Windows 10');

    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 ? ['dots'] : ['progress'],

        plugins: ['karma-systemjs', 'karma-jasmine', 'karma-browserstack-launcher'],

        // 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).filter(function(key) { return !key.startsWith('add'); })
       //     :['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: 1,


        systemjs: {
            configFile: 'config.js',
            serveFiles: [
                'src/**/*.ts',
                'tests/**/*.ts',
                'jspm_packages/**/*',
                'node_modules/**/*'
            ]
        },

        customLaunchers: {
            chrome: {
                base: 'BrowserStack',
                browser: 'chrome',
                browser_version: '45',
                os: 'windows',
                os_version: '8'
            }
        },

        browsers: ['chrome'],
        
        sauceLabs: {
            testName: 'Web App Unit Tests'
        },

        testingbot: {
            testName: 'Web App Unit Tests',
            connectOptions: { verbose: true }
        },

        browserNoActivityTimeout: 60000
    })
};

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');
    this.addIE = addBrowser('internet explorer');
    
    this.addLatest = function(browser, system) {
        self[browser + '_latest_' + system] = {
            base: 'BrowserStack',
            browser: browser,
            platform: system
        };

        return self;
    };

    function addBrowser(browser) {        
        return function () {
            var versions = Array.from(arguments);
            return function (system) {
                
                versions.forEach(function (version) {
                    var seleniumKey = browser + '_' + version + '_' + system;

                    self[seleniumKey] = {
                        base: 'BrowserStack',
                        browser: browser,
                        browser_version: version
                    };

                    if (system) {
                        self[seleniumKey].os = system;
                    }
                });

                return self;
            };
        };
    }
}

@@ -3492,22 +3492,30 @@
         
-chrome
+bs_firefox_mac
 : %7B%0A    
@@ -3574,22 +3574,23 @@
 owser: '
-chrome
+firefox
 ',%0A     
@@ -3618,18 +3618,20 @@
 rsion: '
-45
+21.0
 ',%0A     
@@ -3650,15 +3650,12 @@
 s: '
-windows
+OS X
 ',%0A 
@@ -3682,17 +3682,29 @@
 rsion: '
-8
+Mountain Lion
 '%0A      
@@ -3702,32 +3702,33 @@
 n'%0A            %7D
+,
 %0A        %7D,%0A%0A   
@@ -3724,41 +3724,25 @@
     
-%7D,%0A%0A        browsers: %5B'chrome'%5D,
+    bs_iphone5: %7B
 %0A   
@@ -3746,25 +3746,24 @@
         
-%0A
         
 sauceLab
@@ -3758,63 +3758,65 @@
     
-sauceLabs: %7B%0A            testName: 'Web App Unit Tests'
+base: 'BrowserStack',%0A                device: 'iPhone 5',
 %0A   
@@ -3820,28 +3820,24 @@
         
-%7D,%0A%0A
         
 testingb
@@ -3832,163 +3832,129 @@
     
-testingbot: %7B%0A            testName: 'Web App Unit Tests',%0A            connectOptions: %7B verbose: true %7D%0A        %7D,%0A%0A        browserNoActivityTimeout: 60000
+os: 'ios',%0A                os_version: '6.0'%0A            %7D%0A        %7D,%0A%0A        browsers: %5B'bs_firefox_mac', 'bs_iphone5'%5D
 %0A   

change browsers