Testing connect-assets compiled js with Mocha

I am trying to figure out how to test front-end javascript compiled with connect-assets in Mocha.

I see mocha has a browser runner, but that does not compile and use the same asset as your actual applications javascript.

How can you test connect-assets compiled JS with mocha.

If you're looking to do it all from the Command Line, I don't think that will be possible.

To test your client side code with mocha you'll probably need to setup a new client side test page.

You can start that process by doing a

mkdir public/test && mocha init public/test

which will create a new test directory in your public folder and put the default mocha client side testing files in there

  • mocha.css
  • mocha.js
  • tests.html

The challenge from there is going to be how you get your connect-assets compiled javascript on that tests.html page, which there isn't a good answer for.

I'd recommend creating a new testLayout.jade and translate the following html to it

<html>
  <head>
    <title>Mocha</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="/test/mocha.css" />
  </head>
  <body>
    <div id="mocha"></div>
    <script src="/test/mocha.js"></script>
    <script>mocha.setup('bdd')</script>

    <!-- Your connect-assets js("") script references here -->

    <script>
      mocha.run();
    </script>
  </body>
</html>

Then you're going to have to create another view that extends that layout. And, finally, hook up a route to display all that stuff.