title: JavaScript test (mocha) with 'import' js file
body: <p>I understand <code>module.export</code> and <code>require</code> mannner:</p>
  
  <p><a href="https://stackoverflow.com/questions/12258806/requiring-external-js-file-for-mocha-testing">Requiring external js file for mocha testing</a></p>
  
  <p>Although it's pretty usable as long as it's a module, I feel this manner is inconvenient since what I intends to do now is to test a code in a file.</p>
  
  <p>For instance, I have a code in a file:</p>
  
  <p><strong>app.js</strong></p>
  
  <pre><code>'use strict';
  console.log('app.js is running');
  var INFINITY = 'INFINITY';
  </code></pre>
  
  <p>and now, I want to test this code in a file:</p>
  
  <p><strong>test.js</strong></p>
  
  <pre><code>var expect = require('chai').expect;
  
  require('./app.js');
  
  
      describe('INFINITY', function()
      {
          it('INFINITY === "INFINITY"',
              function()
              {
                  expect(INFINITY)
                      .to.equal('INFINITY');
              });
      });
  </code></pre>
  
  <p>The test code executes <code>app.js</code>, so the output is;</p>
  
  <p><code>app.js is running</code></p>
  
  <p>then</p>
  
  <p><code>ReferenceError: INFINITY is not defined</code></p>
  
  <p>This is not what I expected.</p>
  
  <p>I do not want to use <code>module.export</code> and to write like</p>
  
  <p><code>var app = require('./app.js');</code></p>
  
  <p>and</p>
  
  <p><code>app.INFINITY</code> and <code>app.anyOtherValue</code> for every line in the test code.</p>
  
  <p>There must be a smart way. Could you tell me?</p>
  
  <p>Thanks.</p>