<commit_before>/*global sinon, suite, beforeEach, test, expect, analytics */
(function () {

    suite('analytics.js');

    var providers = {
        'Google Analytics' : {
            trackingId : 'TEST'
        },
        'Mixpanel' : {
            token : '<PASSWORD>'
        }
    };

    var terseProviders = {
        'Google Analytics' : 'TERSE_TEST',
        'Mixpanel'         : 'TERSE_TEST'
    };


    // Initialize
    // ----------

    test('initialize copies providers into this.providers', function () {
        expect(analytics.providers).to.be.empty;
        analytics.initialize(providers);
        expect(analytics.providers.length).to.equal(2);
    });

    test('initialize sends settings to each providers', function () {
        analytics.initialize(providers);
        expect(analytics.providers[0].settings).to.equal(providers['Google Analytics']);
        expect(analytics.providers[1].settings).to.equal(providers['Mixpanel']);
    });

    test('initialize allows for apiKey strings as settings', function () {
        analytics.initialize(terseProviders);
        expect(analytics.providers[0].settings.trackingId).to.equal('TERSE_TEST');
        expect(analytics.providers[1].settings.token).to.equal('<PASSWORD>');
    });

    test('initialize sends settings to providers initialize method', function () {
        var spy = sinon.spy(analytics.providers[1], 'initialize');
        analytics.initialize(providers);
        expect(spy).to.have.been.calledWith(providers['Mixpanel']);

        spy.restore();
    });


    // Identify
    // --------

    test('identify sends userId along', function () {
        var spy = sinon.spy(analytics.providers[1], 'identify');
        analytics.identify('ID');
        expect(spy).to.have.been.calledWith('ID');

        spy.restore();
    });

    test('identify sends a clone of traits along', function  () {
        var spy = sinon.spy(analytics.providers[1], 'identify');
        var traits = {
            age  : 23,
            name : 'Achilles'
        };
        analytics.identify('ID', traits);
        expect(spy.args[0][1]).not.to.equal(traits);
        expect(spy.args[0][1]).to.deep.equal({
            $name : 'Achilles',
            age   : 23
        });

        spy.restore();
    });

    test('identify recognizes email userIds', function () {
        var spy = sinon.spy(window.mixpanel, 'register');
        analytics.identify('<EMAIL>');
        expect(spy.args[0][0]).to.deep.equal({ $email : '<EMAIL>' });

        spy.reset();
        analytics.identify('<EMAIL>');
        expect(spy.args[0][0]).to.deep.equal({ $email : '<EMAIL>' });

        spy.reset();
        analytics.identify('team@.org');
        expect(spy).not.to.have.been.called;

        spy.reset();
        analytics.identify('team+45.io');
        expect(spy).not.to.have.been.called;

        spy.reset();
        analytics.identify('@segmentio.com');
        expect(spy).not.to.have.been.called;

        spy.restore();
    });


    // Track
    // -----

    test('track sends event name along', function () {
        var spy = sinon.spy(analytics.providers[1], 'track');
        analytics.track('party');
        expect(spy).to.have.been.calledWith('party');

        spy.restore();
    });

    test('track sends a clone of event properties along', function  () {
        var spy = sinon.spy(analytics.providers[1], 'track');
        var properties = {
            level  : 'hard',
            volume : 11
        };
        analytics.track('party', properties);
        expect(spy.args[0][1]).not.to.equal(properties);

        spy.restore();
    });

})();



<commit_msg>Fixing analyticsjs test by clearing providers<commit_after>/*global sinon, suite, beforeEach, test, expect, analytics */
(function () {

    suite('analytics.js');

    var providers = {
        'Google Analytics' : {
            trackingId : 'TEST'
        },
        'Mixpanel' : {
            token : 'TEST'
        }
    };

    var terseProviders = {
        'Google Analytics' : 'TERSE_TEST',
        'Mixpanel'         : 'TERSE_TEST'
    };

    // Clear providers, some break on multiple inclusions.
    function clearProviders() {
        delete window._gaq;
        delete window.mixpanel;
    }


    // Initialize
    // ----------

    test('initialize copies providers into this.providers', function () {
        clearProviders();
        expect(analytics.providers).to.be.empty;
        analytics.initialize(providers);
        expect(analytics.providers.length).to.equal(2);
    });

    test('initialize sends settings to each providers', function () {
        clearProviders();
        analytics.initialize(providers);
        expect(analytics.providers[0].settings).to.equal(providers['Google Analytics']);
        expect(analytics.providers[1].settings).to.equal(providers['Mixpanel']);
    });

    test('initialize allows for apiKey strings as settings', function () {
        clearProviders();
        analytics.initialize(terseProviders);
        expect(analytics.providers[0].settings.trackingId).to.equal('TERSE_TEST');
        expect(analytics.providers[1].settings.token).to.equal('TER<PASSWORD>');
    });

    test('initialize sends settings to providers initialize method', function () {
        clearProviders();
        var spy = sinon.spy(analytics.providers[1], 'initialize');
        analytics.initialize(providers);
        expect(spy).to.have.been.calledWith(providers['Mixpanel']);

        spy.restore();
    });


    // Identify
    // --------

    test('identify sends userId along', function () {
        var spy = sinon.spy(analytics.providers[1], 'identify');
        analytics.identify('ID');
        expect(spy).to.have.been.calledWith('ID');

        spy.restore();
    });

    test('identify sends a clone of traits along', function  () {
        var spy = sinon.spy(analytics.providers[1], 'identify');
        var traits = {
            age  : 23,
            name : 'Achilles'
        };
        analytics.identify('ID', traits);
        expect(spy.args[0][1]).not.to.equal(traits);
        expect(spy.args[0][1]).to.deep.equal({
            $name : 'Achilles',
            age   : 23
        });

        spy.restore();
    });

    test('identify recognizes email userIds', function () {
        var spy = sinon.spy(window.mixpanel, 'register');
        analytics.identify('<EMAIL>');
        expect(spy.args[0][0]).to.deep.equal({ $email : '<EMAIL>' });

        spy.reset();
        analytics.identify('<EMAIL>');
        expect(spy.args[0][0]).to.deep.equal({ $email : '<EMAIL>' });

        spy.reset();
        analytics.identify('team@.org');
        expect(spy).not.to.have.been.called;

        spy.reset();
        analytics.identify('team+45.io');
        expect(spy).not.to.have.been.called;

        spy.reset();
        analytics.identify('@segmentio.com');
        expect(spy).not.to.have.been.called;

        spy.restore();
    });


    // Track
    // -----

    test('track sends event name along', function () {
        var spy = sinon.spy(analytics.providers[1], 'track');
        analytics.track('party');
        expect(spy).to.have.been.calledWith('party');

        spy.restore();
    });

    test('track sends a clone of event properties along', function  () {
        var spy = sinon.spy(analytics.providers[1], 'track');
        var properties = {
            level  : 'hard',
            volume : 11
        };
        analytics.track('party', properties);
        expect(spy.args[0][1]).not.to.equal(properties);

        spy.restore();
    });

})();




{'fraction_non_alphanumeric': 0.16589861751152074, 'fraction_numerical': 0.007373271889400922, 'mean_word_length': 2.257289879931389, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '1172692', 'n_tokens_mistral': 2306, 'n_tokens_neox': 2250, 'n_words': 376}