title: How can I test a normal plain javascript file?
body: <p>If I have a plain javascript file</p>
  
  <pre><code>// hello.js
  function hello(string) {
    return 'hello ' + string;
  }
  </code></pre>
  
  <p>How can I use unit test over the functions in this file?</p>
  
  <h2>EDIT</h2>
  
  <p>Currently I have two ideas (both using nodejs):</p>
  
  <h3>eval + mochajs/nodejs</h3>
  
  <p>Test with mochajs test framework, for this I need use <code>eval</code></p>
  
  <pre><code>// test file
  var assert = require('assert');
  var fs = require('fs');
  eval.apply(this, [fs.readFileSync('./hello.js').toString()]);
  
  describe('hello function', function() {
    it('test output', function () {
      assert.equal('hello world', hello('world'));
    });
  });
  </code></pre>
  
  <h3>automatically pre-convert the javascript file in a nodejs module</h3>
  
  <p>Before to run the test create automatically a copy of <code>hello.js</code> with the structure of a nodejs module and run the test over the copy</p>
  
  <pre><code>// _hello.js to testing
  exports.hello = function(string) {
    return 'hello ' + string;
  }
  
  // test file
  var assert = require('assert');
  var hello = require('./_hello.js');
  
  describe('hello function', function() {
    it('test output', function () {
      assert.equal('hello world', hello.hello('world'));
    });
  });
  </code></pre>
  
  <p>In the second option, I need to make a script to convert the javascript file into a nodejs module, but I get some things like, in a nodejs module I can get the coverage measure.</p>