<commit_before>/*
 * mochify.js
 *
 * Copyright (c) 2014 <NAME> <<EMAIL>>
 *
 * @license MIT
 */
'use strict';

var through   = require('through2');
var phantomic = require('phantomic');
var trace     = require('./trace');


module.exports = function (b, opts) {

  var done;
  function apply() {
    var input = through(function (chunk, enc, next) {
      /*jslint unparam: true*/
      this.push(chunk);
      next();
    });
    var output = phantomic(input, {
      debug     : opts.debug,
      port      : opts.port,
      brout     : true,
      phantomjs : opts.phantomjs
    }, function (code) {
      if (code) {
        b.emit('error', new Error('Exit ' + code));
      }
      done();
    });

    var out = output.pipe(trace());

    var wrap = b.pipeline.get('wrap');
    wrap.push(through(function (chunk, enc, next) {
      /*jslint unparam: true*/
      input.write(chunk);
      next();
    }, function (next) {
      done = next;
      input.end();
    }));

    wrap.push(out);
  }

  apply();
  b.on('reset', apply);

};
<commit_msg>Increase --watch performance by preloading phantomjs<commit_after>/*
 * mochify.js
 *
 * Copyright (c) 2014 <NAME> <<EMAIL>>
 *
 * @license MIT
 */
'use strict';

var through   = require('through2');
var phantomic = require('phantomic');
var trace     = require('./trace');

module.exports = function (b, opts) {

  var done;
  var input;
  var output;
  function launch() {
    input = through(function (chunk, enc, next) {
      /*jslint unparam: true*/
      this.push(chunk);
      next();
    });
    output = phantomic(input, {
      debug     : opts.debug,
      port      : opts.port,
      brout     : true,
      phantomjs : opts.phantomjs
    }, function (code) {
      if (code) {
        b.emit('error', new Error('Exit ' + code));
      }
      if (done) {
        done();
        done = null;
        output = null;
        if (opts.watch) {
          launch();
        }
      }
    });
  }

  launch();

  function apply() {
    var wrap = b.pipeline.get('wrap');

    wrap.push(through(function (chunk, enc, next) {
      /*jslint unparam: true*/
      input.write(chunk);
      next();
    }, function (next) {
      done = next;
      input.end();
    }));

    wrap.push(output.pipe(trace()));
  }

  apply();
  b.on('reset', apply);

};

{'fraction_non_alphanumeric': 0.17077388672719412, 'fraction_numerical': 0.00432338953739732, 'mean_word_length': 2.0977242302543506, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5581058', 'n_tokens_mistral': 785, 'n_tokens_neox': 759, 'n_words': 182}