<commit_before>// Modules used to run tests
var assert = require('assert');
var Browser = require("zombie");

// Start up the server
var server = require(process.cwd() + '/server.js');

// Modules needed to set up test environment
var util = require('util');
var config = require(process.cwd() + '/lib/config').config;
var filteredConfig = require(process.cwd() + '/lib/config').filteredConfig;
var ExtensionApi = require(process.cwd() + '/lib/extension_api');

var BUNDLE_NAME = 'test-bundle';
var DASHBOARD_URL = util.format("http://%s:%d/", config.host, config.port);

describe("api", function() {
    var serverApi = {};
    before(function() {
        serverApi = new ExtensionApi(BUNDLE_NAME, server.io);
    });

    var clientApi = {};
    before(function(done) {
        var self = this;
        this.timeout(10000);
        this.browser = new Browser();
        this.browser
            .visit(DASHBOARD_URL)
            .then(function() {
                var evalStr = util.format('new NodeCG("%s", %s)', BUNDLE_NAME, JSON.stringify(filteredConfig));
                clientApi = self.browser.window.clientApi = self.browser.evaluate(evalStr);
            })
            .then(done, done);
    });

    it("should allow client -> server messaging with callbacks", function(done) {
        serverApi.listenFor('clientToServer', function (data, cb) {
            cb();
        });
        clientApi.sendMessage('clientToServer', function () {
            done();
        });
    });

    it("should allow server -> client messaging without callbacks", function(done) {
        clientApi.listenFor('serverToClient', function () {<commit_msg>Wait until the dashboard is loaded before extracting clientApi<commit_after>// Modules used to run tests
var assert = require('assert');
var Browser = require("zombie");

// Start up the server
var server = require(process.cwd() + '/server.js');

// Modules needed to set up test environment
var util = require('util');
var config = require(process.cwd() + '/lib/config').config;
var filteredConfig = require(process.cwd() + '/lib/config').filteredConfig;
var ExtensionApi = require(process.cwd() + '/lib/extension_api');

var BUNDLE_NAME = 'test-bundle';
var DASHBOARD_URL = util.format("http://%s:%d/", config.host, config.port);

describe("api", function() {
    var serverApi = {};
    before(function() {
        serverApi = new ExtensionApi(BUNDLE_NAME, server.io);
    });

    var clientApi = {};
    before(function(done) {
        var self = this;

        // Wait until page is loaded
        function pageLoaded(window) {
            return (typeof window.NodeCG !== "undefined");
        }

        this.timeout(10000);
        this.browser = new Browser();
        this.browser
            .visit(DASHBOARD_URL)
            .then(function() {
                self.browser.wait(pageLoaded, function () {
                    var evalStr = util.format('window.clientApi = new NodeCG("%s", %s)', BUNDLE_NAME, JSON.stringify(filteredConfig));
                    clientApi = self.browser.evaluate(evalStr);
                    done();
                });
            });
    });

    it("should allow client -> server messaging with callbacks", function(done) {
        serverApi.listenFor('clientToServer', function (data, cb) {
            cb();
        });
        clientApi.sendMessage('clientToServer', function () {
            done();
        });
    });

    it("should allow server -> client messaging without callbacks", function(done) {
        clientApi.listenFor('serverToClient', function () {
{'fraction_non_alphanumeric': 0.14590347923681257, 'fraction_numerical': 0.0028058361391694723, 'mean_word_length': 2.6828512396694215, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5577544', 'n_tokens_mistral': 1018, 'n_tokens_neox': 982, 'n_words': 240}