'use strict';

const path  = require ('path');
const util  = require ('util');
const Mocha = require ('mocha');

const script = path.resolve (process.argv[2]);

require ('babel-core/register') ({
  presets: ['es2015', 'stage-0']
});

[
  'error', 'info', 'log', 'warn'
].forEach ((log) => {
  const _log = console[log];

  console[log] = function () {
    const output = util.format.apply (this, arguments);
    _log (output);

    const {stack} = new Error ();
    const line = stack
      .split ('\n')
      .filter ((line) => new RegExp (`^[ ]+at .*\\(${script}:[0-9]+:[0-9]+\\)$`, 'i').test (line))
      .map ((line) => line.replace (/.*:([0-9]+):[0-9]+[)]$/, '$1'));

    if (!line.length) {
      return;
    }

    process.send ({
      message: 'console',
      type: /(error|warn)/.test (log) ? 'stderr' : 'stdout',
      line: parseInt (line[0]),
      output
    });
  };
});

const _mocha = new Mocha ({
  grep: new RegExp (process.argv[3]),
  reporter: 'min'
});

_mocha.addFile (script);
const runner = _mocha.run (() => process.exit (0));

runner.on ('fail', (test, err) => {
  process.send ({
    message: 'fail',
    test: {
      state:    test.state,
      title:    test.title,
      duration: test.duration,
      timedOut: test.timedOut
    },
    err
  });
});

runner.on ('pass', (test) => {
  process.send ({
    message: 'pass',
    test: {
      state:    test.state,
      title:    test.title,
      duration: test.duration,
      timedOut: test.timedOut
    }
  });
});

@@ -154,16 +154,98 @@
 v%5B2%5D);%0A%0A
+/* Disable because it adds too much unrelated exceptions; it needs to investigate%0A
 require 
@@ -307,16 +307,19 @@
 -0'%5D%0A%7D);
+%0A*/
 %0A%0A%5B%0A  'e

Disable buggy use of babel-core