Getting mocha and webpack running to test JS

Hi all,

Looking for some guidance in JavaScript testing. For the java script calculator project I took a TDD (Test Driven Development) approach which I found awesome. It very much helped me reduce the creation of bugs as I expanded functionality. I’m sold on TDD.

I used the following tutorial to create my test framework. This tutorial basically invokes the testing through the browser by importing all the libraries in `

This was all well and good until I changed the project to use webpack which helped manage the dependencies. Now I have these require statements at the top of my app.js that the browser run version of mocha does not like. It seems if I used a framework such as webpack to build my dependencies I have to abandon my browser system of testing.

The solution it seems is to export all my JS functions with the following syntax
module.exports = { functionName : function(){//Do stuff}; otherfunction: function(){ //Do other stuff}: }

I have tried referencing in my testrunner html page but mocha can;t find any of my methods with the webpack created code (function(module, exports, webpack_require).

It feels wrong modifying my JavaScript syntax to get testing running in node. Does anybody know a different way to do this … or is this indeed the correct approach? I’m open to any other suggestions or approaches to running tests on JavaScript code. I’m aiming to get a nice build, deploy and test setup created so I’m ready to taken on more involved projects. I can elaborate with more code if needed.