<commit_before>/*
Thali unit test implementation of tape.
Highly inspired by wrapping-tape, and usage is very similar to the wrapping tape:

 var tape = require('thali-tape');

 var test = tape({
  setup: function(t) {
    // will be called after each test has started to setup the test
    // after the next line, the actual test code will be executed
  t.end();
 },
  teardown: function(t) {
    // will be called after each device has ended the test
    // do any final tear down for the test in here
  t.end();
 }
 });
*/

'use strict';

var tape = require('tape');
var CoordinatorConnector = require('CoordinatorConnector');
var parsedJSON = require('serveraddress.json');

function Thali_Tape(options) {

  var myName = "UT" + Math.round((Math.random() * (1000000)));
  if(options.deviceName){
    myName = options.deviceName;
  }

  var Coordinator = new CoordinatorConnector();
  Coordinator.init(parsedJSON[0].address, 3000);
  console.log('attempting to connect to test coordinator to ' + parsedJSON[0].address + ' type: ' + parsedJSON[0].name);

  Coordinator.on('error', function (data) {
    var errData = JSON.parse(data);
    console.log('Error:' + data + ' : ' + errData.type +  ' : ' + errData.data);
  });

// Add a disconnect listener
  Coordinator.on('disconnect', function () {
    console.log('The client has disconnected!');
    //we need to stop & close any tests we are runnign here
    if(setUp_t != null){
      setUp_t.fail("Coordinator server got disconnected");
      setUp_t = null;
    }

    if(teardDown_t != null){
      teardDown_t.fail("Coordinator server got disconnected");
      teardDown_t = null;
    }
  });

  var isConnected = false;
  Coordinator.on('connect', function () {
    if(!isConnected) {
      isConnected = true;
      Coordinator.initUnitTest(myName);
    }
  });

  var setUp_t = null;
  var teardDown_t = null;

  //test([name], [opts], cb)
  return function(name, opts, cb) {
    // if there is only two input values, then the second is the function, not opts
    if (!cb) {
      cb = opts;
      opts = null;
    }

    var setUpCallback = function(t) {
      if(setUp_t == null) {
        setUp_t = t;
        Coordinator.setUp(myName, name);
      }
    }

    if (options.setup) {
      tape('setup',setUpCallback);
    }

    Coordinator.on('setup_ready', function (data) {
      if (options.setup && (setUp_t != null)) {
        options.setup.call(setUp_t, setUp_t);
        setUp_t = null;
      }
    });

  //test([name], [opts], cb)
    tape(name, function(t) {
      if (opts != null) {
        t.plan(opts);
      }
      cb.call(t, t);
    });


    if (options.teardown) {
      tape('teardown', function(t) {
        teardDown_t = t;
        Coordinator.tearDown(myName,name);
      });
    }

    Coordinator.on('tear_down_ready', function (data) {
      if (options.teardown && (teardDown_t != null)) {
        options.teardown.call(teardDown_t, teardDown_t);
        teardDown_t = null;
      }
    });
  };<commit_msg>Fix up paths and squash emitter leak warning (it's not a leak)<commit_after>/*
Thali unit test implementation of tape.
Highly inspired by wrapping-tape, and usage is very similar to the wrapping tape:

 var tape = require('thali-tape');

 var test = tape({
  setup: function(t) {
    // will be called after each test has started to setup the test
    // after the next line, the actual test code will be executed
  t.end();
 },
  teardown: function(t) {
    // will be called after each device has ended the test
    // do any final tear down for the test in here
  t.end();
 }
 });
*/

'use strict';

var tape = require('tape');
var CoordinatorConnector = require('./CoordinatorConnector');
var parsedJSON = require('serveraddress.json');

function Thali_Tape(options) {

  var myName = "UT" + Math.round((Math.random() * (1000000)));
  if(options.deviceName){
    myName = options.deviceName;
  }

  var Coordinator = new CoordinatorConnector();
  Coordinator.init(parsedJSON[0].address, 3000);
  console.log('attempting to connect to test coordinator to ' + parsedJSON[0].address + ' type: ' + parsedJSON[0].name);

  // We're about to add a lot of event handlers so squash the emitter leak warning
  Coordinator.setMaxListeners(0);

  Coordinator.on('error', function (data) {
    var errData = JSON.parse(data);
    console.log('Error:' + data + ' : ' + errData.type +  ' : ' + errData.data);
  });

  // Add a disconnect listener
  Coordinator.on('disconnect', function () {
    console.log('The client has disconnected!');
    //we need to stop & close any tests we are runnign here
    if(setUp_t != null){
      setUp_t.fail("Coordinator server got disconnected");
      setUp_t = null;
    }

    if(teardDown_t != null){
      teardDown_t.fail("Coordinator server got disconnected");
      teardDown_t = null;
    }
  });

  var isConnected = false;
  Coordinator.on('connect', function () {
    if(!isConnected) {
      isConnected = true;
      Coordinator.initUnitTest(myName);
    }
  });

  var setUp_t = null;
  var teardDown_t = null;

  //test([name], [opts], cb)
  return function(name, opts, cb) {
    // if there is only two input values, then the second is the function, not opts
    if (!cb) {
      cb = opts;
      opts = null;
    }

    var setUpCallback = function(t) {
      if(setUp_t == null) {
        setUp_t = t;
        Coordinator.setUp(myName, name);
      }
    }

    if (options.setup) {
      tape('setup',setUpCallback);
    }

    Coordinator.on('setup_ready', function (data) {
      if (options.setup && (setUp_t != null)) {
        options.setup.call(setUp_t, setUp_t);
        setUp_t = null;
      }
    });

    //test([name], [opts], cb)
    tape(name, function(t) {
      if (opts != null) {
        t.plan(opts);
      }
      cb.call(t, t);
    });


    if (options.teardown) {
      tape('teardown', function(t) {
        teardDown_t = t;
        Coordinator.tearDown(myName,name);
      });
    }

    Coordinator.on('tear_down_ready', function (data) {
      if (options.teardown && (teardDown_t != null)) {
        options.teardown.call(teardDown_t, teardDown_t);
        teardDown_t = null;
      }
    });
  };
{'fraction_non_alphanumeric': 0.13806514341273698, 'fraction_numerical': 0.004699400421325555, 'mean_word_length': 2.761121267519805, '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': '2994824', 'n_tokens_mistral': 2068, 'n_tokens_neox': 2006, 'n_words': 535}