title: mocha unit test - how to clear cached javascript after each test
body: <p>I'm trying to test a javascript file (let's call it hello.js) using mocha and jsdom. I have several unit tests; each test basically sets up some window properties, calls hello.js, and checks window property values. Tests seem to be running somehow; however, it seems like mocha uses "cached" hello.js after the first test (logging only shows in the first test).</p>
  
  <p>Can someone tell me how I can ensure that I reload hello.js in each test?</p>
  
  <pre><code>const expect = require('chai').expect;
  const jsdom = require('jsdom');
  const { JSDOM } = jsdom;
  var dom = (new JSDOM(`&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;`));
  
  describe('hello', ()=&gt;{
      afterEach(()=&gt;{
          dom = (new JSDOM(`&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;`));
          global.window = {};
          document = {};
          location = {};
      });
      it('should test A', ()=&gt; {
          global.window = dom.window;
          global.window.document.cookie = "test=kiwi";
          document = global.window.document;
          const hello = require('../public/hello.js');
         expect(document.getElementsByTagName('IFRAME').length).to.equal(1);
      });
      it('should test B', ()=&gt; {
          global.window = dom.window;
          global.window.document.cookie = "test=apple";
          document = global.window.document;
          const hello = require('../public/hello.js');
         expect(document.getElementsByTagName('IFRAME').length).to.equal(0);
      });
  });
  </code></pre>