Dave Kerr
Dave Kerr

Reputation: 5297

Node.js and Mocha Tests from the Browser

This is probably a really dumb question, but I'm not sure. If I have a node.js application and a much of tests built with Mocha, I can run them on my server no problems, using mocha. However, is there any way to invoke the unit tests through a browser and just pipe the results to the page? For development, I'd like to have a page on my website that shows the results of the tests.

Every time I search for how to do this, it's testing the actual browser code I'm finding (the dom, the UI etc), but it's actually just that I want to see the results of the tests run server-side but from the browser!

Thanks in advance!

Upvotes: 1

Views: 803

Answers (1)

Dan Kohn
Dan Kohn

Reputation: 34327

Sure, create a route in Express that executes mocha and returns the result to the browser. Take a look at child_process.fork to execute mocha: http://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options

And don't forget to turn it off before going into production!

Separately, I would highly recommend to you the concept of continuous deployment, and specifically the service CircleCI, which for $19 automatically runs all of your tests every time you push to Github.

Upvotes: 2

Related Questions