The Mystery of the Mocha Logs

So I started a project today with a colleague. A simple one, nothing complex, just an exercise in test-driven development in the console using Node and Mocha. About two-thirds through our project we needed to do some significant debugging and tried to log some data to the console, but none of it was showing up. No matter where we put the log it didn’t appear when it was called in the Mocha tests. Somehow Mocha was gobbling up our printed lines. After trying a few different solutions, I found a post on StackOverflow suggesting to create a mocha.opts file in the tests directory with two configuration lines. This worked and we finished the project. For future reference, I went back and tried to figure out which line fixed our problem. After alternately deleting each line individually, and failing that removing the whole file, I couldn’t un-fix the problem. Mocha was now printing console logs 100% of the time. Rolling back to our first git commit, deleting the repo and re-cloning, nothing worked. This remains an utter mystery. Such is the world of Javascript.

Like what you read? Give Michael Sodaro a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.