<commit_before>
const assert = require('assert'),
          os = require('os'),
        mock = require('mock-os'),
           _ = require('underscore');

const monitor     = require('../os-monitor'),
      { version } = require('../package.json');
      
let tester;

beforeEach(() => {
  mock({
    cpus: [{}, {}],
    loadavg: [2, 2, 2],
    freemem: 1000000,
    totalmem: 100000000,
    uptime: 1000000,
  });
  tester = new monitor.Monitor();
});
afterEach(() => {
  tester.destroy();
  mock.restore();
});

describe('Monitor class', function() {
  it('should have default instance', async () => {
    assert.ok(monitor instanceof monitor.Monitor);
  });
  it('should create new instances', async () => {
    assert.ok(tester instanceof monitor.Monitor);
  });
});
describe('API signature', function() {
  it('should have valid API signature', async () => {
    // API signature
    assert.ok(tester._read, "internal ._read() method expected");
    assert.ok(tester.version, "version property expected");
    assert.ok(tester.sendEvent, ".sendEvent() method expected");
    assert.ok(tester.start, ".start() method expected");
    assert.ok(tester.stop, ".stop() method expected");
    assert.ok(tester.reset, ".reset() method expected");
    assert.ok(tester.destroy, ".destroy() method expected");
    assert.ok(tester.config, ".config() method expected");
    assert.ok(tester.isRunning, ".isRunning() method expected");
    assert.ok(tester.throttle, ".throttle() method expected");
    assert.ok(tester.unthrottle, ".unthrottle() method expected");
    assert.ok(tester.when, ".when() method expected");
    assert.ok(tester.seconds, ".seconds() method expected");
    assert.ok(tester.minutes, ".minutes() method expected");
    assert.ok(tester.hours, ".hours() method expected");
    assert.ok(tester.days, ".days() method expected");
    assert.ok(tester.Monitor, "Monitor class expected");
    assert.ok(tester.Thenable, "Thenable class expected");
    assert.ok(tester.os, "os object reference expected");
    assert.ok(tester._, "_ object reference expected");
    assert.ok(tester.constants, "constants object expected");
    //assert.ok(monitor.whetever, "whatever expected");
  });
  it('should have readonly version', async () => {
    let version = tester.version;
    tester.version = '0.0.0';
    assert.strictEqual(tester.version, version);
  });
  it('should have version from package.json', async () => {
    assert.strictEqual(tester.version, version);
  });
});
describe('event emitter', function() {
  it('should emit start event', (done) => {
    tester.on('start', event => {
      assert.strictEqual(event.type, tester.constants.events.START);
      assert.strictEqual(tester.isRunning(), true);
      done();
    });
    tester.start();
  });
  it('should emit stop event', (done) => {
    tester.start({
      immediate: true,
    });
    tester.on('stop', event => {
      assert.strictEqual(event.type, tester.constants.events.STOP);
      assert.strictEqual(tester.isRunning(), false);
      done();
    });
    tester.stop();
  });
  it('should emit config event', (done) => {
    tester.on('config', event => {<commit_msg>improved test for .start()<commit_after>
const assert = require('assert'),
          os = require('os'),
        mock = require('mock-os'),
           _ = require('underscore');

const monitor     = require('../os-monitor'),
      { version } = require('../package.json');
      
let tester;

beforeEach(() => {
  mock({
    cpus: [{}, {}],
    loadavg: [2, 2, 2],
    freemem: 1000000,
    totalmem: 100000000,
    uptime: 1000000,
  });
  tester = new monitor.Monitor();
});
afterEach(() => {
  tester.destroy();
  mock.restore();
});

describe('Monitor class', function() {
  it('should have default instance', async () => {
    assert.ok(monitor instanceof monitor.Monitor);
  });
  it('should create new instances', async () => {
    assert.ok(tester instanceof monitor.Monitor);
  });
});
describe('API signature', function() {
  it('should have valid API signature', async () => {
    // API signature
    assert.ok(tester._read, "internal ._read() method expected");
    assert.ok(tester.version, "version property expected");
    assert.ok(tester.sendEvent, ".sendEvent() method expected");
    assert.ok(tester.start, ".start() method expected");
    assert.ok(tester.stop, ".stop() method expected");
    assert.ok(tester.reset, ".reset() method expected");
    assert.ok(tester.destroy, ".destroy() method expected");
    assert.ok(tester.config, ".config() method expected");
    assert.ok(tester.isRunning, ".isRunning() method expected");
    assert.ok(tester.throttle, ".throttle() method expected");
    assert.ok(tester.unthrottle, ".unthrottle() method expected");
    assert.ok(tester.when, ".when() method expected");
    assert.ok(tester.seconds, ".seconds() method expected");
    assert.ok(tester.minutes, ".minutes() method expected");
    assert.ok(tester.hours, ".hours() method expected");
    assert.ok(tester.days, ".days() method expected");
    assert.ok(tester.Monitor, "Monitor class expected");
    assert.ok(tester.Thenable, "Thenable class expected");
    assert.ok(tester.os, "os object reference expected");
    assert.ok(tester._, "_ object reference expected");
    assert.ok(tester.constants, "constants object expected");
    //assert.ok(monitor.whetever, "whatever expected");
  });
  it('should have readonly version', async () => {
    let version = tester.version;
    tester.version = '0.0.0';
    assert.strictEqual(tester.version, version);
  });
  it('should have version from package.json', async () => {
    assert.strictEqual(tester.version, version);
  });
});
describe('event emitter', function() {
  it('should emit start event', (done) => {
    let config = Object.assign({}, tester.constants.defaults, {uptime: 1234567, immediate: true});
    tester.on('start', event => {
      assert.strictEqual(event.type, tester.constants.events.START);
      assert.strictEqual(tester.isRunning(), true);
      assert.deepStrictEqual(tester.config(), config);
      done();
    });
    tester.start(config);
  });
  it('should emit stop event', (done) => {
    tester.start({
      immediate: true,
    });
    tester.on('stop', event => {
      assert.strictEqual(event.type, tester.constants.events.STOP);
      assert.strictEqual(tester.isRunning(), false);
      done();
    });
    tester.stop();
  });
  it('should emit config event', (done) => {
    tester.on('config', event => {
{'fraction_non_alphanumeric': 0.18023703247652761, 'fraction_numerical': 0.010004617515776512, 'mean_word_length': 3.6183368869936032, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '2806381', 'n_tokens_mistral': 2030, 'n_tokens_neox': 1955, 'n_words': 439}