<commit_before>import sinon from 'sinon';
import { expect } from 'chai';

import { Browserstack } from '../src/transports/browserstack';
import { Selenium } from '../src/transports/selenium';
import wdio from '../src';

describe('browserstack', function describe() {
  let wd;
  let selenium = new Selenium();

  before(function() {
    this.timeout(0);

    return selenium.start();
  });

  beforeEach(() => {
    wd = wdio({
      type: 'browserstack',
      wdio: {
        logLevel: 'verbose',
        waitforTimeout: 12345,
        framework: 'mocha',
        // Only for testing purposes
        cucumberOpts: {
          require: 'nothing',
        }
      }
    });

    // Unhandled "error" event could be interpreted as violation
    wd.on('error', () => {});
  });

  afterEach(() => {
    if (Browserstack.prototype.start.restore) {
      Browserstack.prototype.start.restore();
    }
  });

  after(() => {
    return selenium.stop();
  });

  it('should pass correct arguments', function(done) {
    this.timeout(0);

    sinon.stub(Browserstack.prototype, 'start', function() {
      expect(this.options).to.deep.equal({
        key: 'test',
        hosts: [{
          name: '0.0.0.0',
          port: 4444,
          sslFlag: 0
        }],
        onlyAutomate: true
      });

      done();
      return new Promise(() => {});
    });

    wd.write({
      path: `${__dirname}/without-errors.conf.js`
    });
  });

  it('should start "through" browserstack tunnel', function(done) {
    this.timeout(0);
    sinon.stub(Browserstack.prototype, 'start').returns(new Promise(resolve => resolve()));

    wd.on('finish', () => done());

    wd.write({
      path: `${__dirname}/without-errors.conf.js`
    });

    wd.end();
  });
});<commit_msg>Add catch clause to the unit test<commit_after>import sinon from 'sinon';
import { expect } from 'chai';

import { Browserstack } from '../src/transports/browserstack';
import { Selenium } from '../src/transports/selenium';
import wdio from '../src';

describe('browserstack', function describe() {
  let wd;
  let selenium = new Selenium();

  before(function() {
    this.timeout(0);

    return selenium.start();
  });

  beforeEach(() => {
    wd = wdio({
      type: 'browserstack',
      wdio: {
        logLevel: 'verbose',
        waitforTimeout: 12345,
        framework: 'mocha',
        // Only for testing purposes
        cucumberOpts: {
          require: 'nothing',
        }
      }
    });

    // Unhandled "error" event could be interpreted as violation
    wd.on('error', () => {});
  });

  afterEach(() => {
    if (Browserstack.prototype.start.restore) {
      Browserstack.prototype.start.restore();
    }
  });

  after(() => {
    return selenium.stop();
  });

  it('should pass correct arguments', function(done) {
    this.timeout(0);

    sinon.stub(Browserstack.prototype, 'start', function() {
      expect(this.options).to.deep.equal({
        key: 'test',
        hosts: [{
          name: '0.0.0.0',
          port: 4444,
          sslFlag: 0
        }],
        onlyAutomate: true
      });

      done();
      return new Promise(() => {});
    });

    wd.write({
      path: `${__dirname}/without-errors.conf.js`
    });
  });

  it('should start "through" browserstack tunnel', function(done) {
    this.timeout(0);

    const promise = new Promise(resolve => resolve()).catch(() => {})

    sinon.stub(Browserstack.prototype, 'start').returns(promise);

    wd.on('finish', () => done());

    wd.write({
      path: `${__dirname}/without-errors.conf.js`
    });

    wd.end();
  });
});
{'fraction_non_alphanumeric': 0.17715877437325905, 'fraction_numerical': 0.00947075208913649, 'mean_word_length': 2.4005681818181817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4119491', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1101, 'n_words': 235}