<commit_before>const assert = require('chai').assert;

const testUtils = require('./utils.js');

describe('piwikReactRouter', function () {
  beforeEach(() => {
    this.jsdom = require('jsdom-global')();
    // piwiks tracking client doesn't properly adds the script tag to jsdom.
    // As i won't modify the piwik loading script the easiest was to provide the script tag.
    // dirty – i know ;)
    document.body.innerHTML = '<script></script>';
  });

  afterEach(() => {
    this.jsdom();
  });

  it ('should correctly return the api if a global window object is present', () => {
    const siteId = 1;
    const url = 'foo.bar';

    const piwikReactRouter = testUtils.requireNoCache('../')({
      siteId,
      url
    });

    assert.sameMembers(Object.keys(piwikReactRouter), [
      '_isShim'
    ].concat(testUtils.API_METHOD_NAMES));

    assert.isFalse(piwikReactRouter._isShim);
  });

  it ('should correctly push the trackerUrl and siteId to the _paq array on instantiation', () => {
    const piwikReactRouter = testUtils.requireNoCache('../')({
      url: 'foo.bar',
      siteId: 1
    });

    assert.sameDeepMembers(window._paq, [
      [ 'setSiteId', 1 ],
      [ 'setTrackerUrl', 'http://foo.bar/piwik.php' ],
      [ 'enableLinkTracking' ]
    ]);
  });

  // todo: test warning
  it ('should correctly warn about invalid options and return the api shim', () => {
    assert.isTrue(testUtils.requireNoCache('../')()._isShim);
    assert.isTrue(testUtils.requireNoCache('../')({
      url: 'foo.bar'
    })._isShim);
    assert.isTrue(testUtils.requireNoCache('../')({
      siteId: 1
    })._isShim);
  });

  it ('should correctly track javascript errors', () => {
    const piwikReactRouter = testUtils.requireNoCache('../')({
      url: 'foo.bar',
      siteId: 1,
      trackErrors: true
    });

    piwikReactRouter.trackError(new Error('unknown error'));

    assert.includeDeepMembers(window._paq, [
      ['trackEvent',
      'JavaScript Error',
      'unknown error',
      'undefined:  undefined' ]
    ]);
  });

});<commit_msg>fine tuned existing tests<commit_after>const assert = require('chai').assert;

const testUtils = require('./utils.js');

describe('piwikReactRouter', function () {
  beforeEach(() => {
    this.jsdom = require('jsdom-global')();
    // piwiks tracking client doesn't properly adds the script tag to jsdom.
    // As i won't modify the piwik loading script the easiest was to provide the script tag.
    // dirty – i know ;)
    document.body.innerHTML = '<script></script>';
  });

  afterEach(() => {
    this.jsdom();
  });

  it ('should correctly return the api if a global window object is present', () => {
    const siteId = 1;
    const url = 'foo.bar';

    const piwikReactRouter = testUtils.requireNoCache('../')({
      siteId,
      url
    });

    assert.sameMembers(Object.keys(piwikReactRouter), [
      '_isShim'
    ].concat(testUtils.API_METHOD_NAMES));

    assert.isFalse(piwikReactRouter._isShim);

    testUtils.API_METHOD_NAMES.forEach(methodName => {
      assert.isFunction(piwikReactRouter[methodName]);
    });
  });

  it ('should correctly push the trackerUrl and siteId to the _paq array on instantiation', () => {
    const piwikReactRouter = testUtils.requireNoCache('../')({
      url: 'foo.bar',
      siteId: 1
    });

    assert.sameDeepMembers(window._paq, [
      [ 'setSiteId', 1 ],
      [ 'setTrackerUrl', 'http://foo.bar/piwik.php' ],
      [ 'enableLinkTracking' ]
    ]);
  });

  // todo: test warning
  it ('should correctly warn about invalid options and return the api shim', () => {
    assert.isTrue(testUtils.requireNoCache('../')()._isShim);
    assert.isTrue(testUtils.requireNoCache('../')({
      url: 'foo.bar'
    })._isShim);
    assert.isTrue(testUtils.requireNoCache('../')({
      siteId: 1
    })._isShim);
  });

  it ('should correctly track javascript errors', () => {
    const piwikReactRouter = testUtils.requireNoCache('../')({
      url: 'foo.bar',
      siteId: 1,
      trackErrors: true
    });

    let err = new Error('unknown error');
    err.filename = 'foo.js';
    err.lineno = 10;

    piwikReactRouter.trackError(err);

    assert.includeDeepMembers(window._paq, [
      [
        'trackEvent',
        'JavaScript Error',
        'unknown error',
        'foo.js: 10'
      ]
    ]);
  });

});
{'fraction_non_alphanumeric': 0.1612606395215091, 'fraction_numerical': 0.00322061191626409, 'mean_word_length': 2.868327402135231, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '2445395', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1365, 'n_words': 314}