<commit_before>'use strict';

// Modules used to run tests
var chai = require('chai');
var should = chai.should();
var expect = chai.expect;
var request = require('request');

var e = require('./setup/test-environment');
var C = require('./setup/test-constants');

describe('extension api', function() {
    before(function(done) {
        // Drop all replicants
        e.server._resetReplicants();

        // Wait a bit for all clients to react
        setTimeout(done, 1750);
    });

    it('can receive messages and fire acknowledgements', function(done) {
        e.apis.extension.listenFor('clientToServer', function (data, cb) {
            cb();
        });
        e.apis.dashboard.sendMessage('clientToServer', done);
    });

    it('can send messages', function(done) {
        e.apis.dashboard.listenFor('serverToClient', done);
        e.apis.extension.sendMessage('serverToClient');
    });

    it('can mount express middleware', function(done) {
        request(C.DASHBOARD_URL + 'test-bundle/test-route', function (error, response, body) {
            expect(error).to.be.null();
            expect(response.statusCode).to.equal(200);
            done();
        });
    });

    describe('nodecg config', function() {
        it('exists and has length', function() {
            expect(e.apis.extension.config).to.not.be.empty();
        });

        it('doesn\'t reveal sensitive information', function() {
            expect(e.apis.extension.config.login).to.not.have.property('sessionSecret');
        });

        it('isn\'t writable', function() {
            expect(function() {
                e.apis.extension.config.host = 'the_test_failed';
            }).to.throw(TypeError);
        });
    });

    describe('bundle config', function() {
        it('exists and has length', function() {
            expect(e.apis.extension.bundleConfig).to.not.be.empty();
        });
    });

    describe('replicants', function() {
        it('only apply defaultValue when first declared', function(done) {
            e.apis.dashboard.Replicant('test', { defaultValue: 'foo' });

            // Give Zombie a chance to process socket.io events
            e.browsers.dashboard.wait({duration: 100}, function() {
                var rep = e.apis.extension.Replicant('test', { defaultValue: 'bar' });
                expect(rep.value).to.equal('foo');
                done();
            });
        });

        it('can be read once without subscription, via readReplicant', function(done) {
            e.apis.extension.readReplicant('test', function(replicant) {
                expect(replicant.value).to.equal('foo');
                done();
            });
        });
<commit_msg>[replicants] fix extension `readReplicant` test (forgot it was sync)<commit_after>'use strict';

// Modules used to run tests
var chai = require('chai');
var should = chai.should();
var expect = chai.expect;
var request = require('request');

var e = require('./setup/test-environment');
var C = require('./setup/test-constants');

describe('extension api', function() {
    before(function(done) {
        // Drop all replicants
        e.server._resetReplicants();

        // Wait a bit for all clients to react
        setTimeout(done, 1750);
    });

    it('can receive messages and fire acknowledgements', function(done) {
        e.apis.extension.listenFor('clientToServer', function (data, cb) {
            cb();
        });
        e.apis.dashboard.sendMessage('clientToServer', done);
    });

    it('can send messages', function(done) {
        e.apis.dashboard.listenFor('serverToClient', done);
        e.apis.extension.sendMessage('serverToClient');
    });

    it('can mount express middleware', function(done) {
        request(C.DASHBOARD_URL + 'test-bundle/test-route', function (error, response, body) {
            expect(error).to.be.null();
            expect(response.statusCode).to.equal(200);
            done();
        });
    });

    describe('nodecg config', function() {
        it('exists and has length', function() {
            expect(e.apis.extension.config).to.not.be.empty();
        });

        it('doesn\'t reveal sensitive information', function() {
            expect(e.apis.extension.config.login).to.not.have.property('sessionSecret');
        });

        it('isn\'t writable', function() {
            expect(function() {
                e.apis.extension.config.host = 'the_test_failed';
            }).to.throw(TypeError);
        });
    });

    describe('bundle config', function() {
        it('exists and has length', function() {
            expect(e.apis.extension.bundleConfig).to.not.be.empty();
        });
    });

    describe('replicants', function() {
        it('only apply defaultValue when first declared', function(done) {
            e.apis.dashboard.Replicant('test', { defaultValue: 'foo' });

            // Give Zombie a chance to process socket.io events
            e.browsers.dashboard.wait({duration: 100}, function() {
                var rep = e.apis.extension.Replicant('test', { defaultValue: 'bar' });
                expect(rep.value).to.equal('foo');
                done();
            });
        });

        it('can be read once without subscription, via readReplicant', function() {
             expect(e.apis.extension.readReplicant('test').value).to.equal('foo');
        });

{'fraction_non_alphanumeric': 0.15537774469668775, 'fraction_numerical': 0.003721622627465575, 'mean_word_length': 2.3530879600748595, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6774578', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1478, 'n_words': 309}