// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/docs/referenceConf.js

/*global jasmine */
//var SpecReporter = require('jasmine-spec-reporter');

exports.config = {
  sauceUser: process.env.SAUCE_USERNAME,
  sauceKey: process.env.SAUCE_ACCESS_KEY,
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  multiCapabilities: [{
    browserName: 'firefox',
    version: '32',
    platform: 'OS X 10.10',
    name: "firefox-tests",
    shardTestFiles: true,
    maxInstances: 25
  }, {
    browserName: 'chrome',
    version: '41',
    platform: 'Windows 7',
    name: "chrome-tests",
    shardTestFiles: true,
    maxInstances: 25
  }],
  directConnect: false,
  seleniumAddress: 'http://' + process.env.SAUCE_USERNAME + ':' + process.env.SAUCE_ACCESS_KEY + '@ondemand.saucelabs.com:80/wd/hub',
  baseUrl: 'http://multipli-test.herokuapp.com/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    isVerbose: false,
    includeStackTrace: false,
    print: function() {},
  },
  useAllAngular2AppRoots: true,
  //beforeLaunch: function() {
  //  require('ts-node').register({
  //    project: 'e2e'
  //  });
  //},
  onPrepare: function() {
  //   jasmine.getEnv().addReporter(new SpecReporter());
    
    require('ts-node').register({
      project: 'e2e'
    });

    jasmine.getEnv().addReporter({
      specDone: function(result) {
        specDescription = result.description;
        specFullName = result.fullName;

        browser.getSession().then(function(session) {

          var formattedResult = result.failedExpectations[0].message.replace(/'/g, "\\\"");

            var exec = require('child_process').exec;
            var cmd = 'curl -X PUT -s -d \'{"name": "' + result.fullName + '", "passed": false, "custom-data": { "message": "' + formattedResult + '" } }\' -u ' + process.env.SAUCE_USERNAME + ':' + process.env.SAUCE_ACCESS_KEY + ' https://saucelabs.com/rest/v1/' + process.env.SAUCE_USERNAME + '/jobs/' + session.getId();
//            var cmd = 'curl -X PUT -s -d \'{"name": "' + result.fullName + '", "passed": ' + (result.status == 'passed' ? 'true' : 'false') + ', "custom-data": { "message": "' + result.failedExpectations[0].message + '"} }\' -u ' + process.env.SAUCE_USERNAME + ':' + process.env.SAUCE_ACCESS_KEY + ' https://saucelabs.com/rest/v1/' + process.env.SAUCE_USERNAME + '/jobs/' + session.getId();
console.log(JSON.stringify(result));
console.log(formattedResult);
//            var cmd = 'curl -X PUT -s -d \'{"name": "' + result.fullName + '", "passed": false, "custom-data": ' + JSON.stringify(result) + '}\' -u ' + process.env.SAUCE_USERNAME + ':' + process.env.SAUCE_ACCESS_KEY + ' https://saucelabs.com/rest/v1/' + process.env.SAUCE_USERNAME + '/jobs/' + session.getId();

            exec(cmd, function(error, stdout, stderr) {
              console.log('stdout: ' + stdout);
              console.log('stderr: ' + stderr);

              if(error !== null)
              {
                  console.log('exec error: ' + error);
              }
            });

        });

      }
    });

    var caps = browser.getCapabilities()
  },
  onComplete: function() {

  }
};

@@ -1709,62 +1709,673 @@
 );%0A%0A
-            var exec = require('child_process').exec;%0A
+var data = %7B%0A              name: result.fullName,%0A              passed: result.status == 'passed' ? true : false,%0A              _customData: result%0A           %7D;%0A%0Avar formattedData = JSON.stringify(data).replace(/_customData/, %22custom-data%22);%0Aconsole.log(formattedData);%0A%0A%0A            var exec = require('child_process').exec;%0A//            var cmd = %22curl -X PUT -s -d %5C'%7B%5C%22name%5C%22: %5C%22%22 + result.fullName + %22%5C%22, %5C%22passed%5C%22: false, %5C%22custom-data%5C%22: %7B %5C%22message%5C%22: %5C%22%22 + formattedResult + %22%5C%22 %7D %7D%5C' -u %22 + process.env.SAUCE_USERNAME + %22:%22 + process.env.SAUCE_ACCESS_KEY + %22 https://saucelabs.com/rest/v1/%22 + process.env.SAUCE_USERNAME + %22/jobs/%22 + session.getId();%0A//
     
@@ -3085,16 +3085,18 @@
 etId();%0A
+//
 console.
@@ -3124,16 +3124,18 @@
 sult));%0A
+//
 console.

create data object