Mocha JS – Run Tests on 800+ Browser/OS Platforms with 1 CLI Command
Mocha Made Awesome on the Sauce Labs Cloud - Quick Tutorial
Are you using Mocha JS - or considering using it? A typical use case for Mocha is running your JS unit tests in a real browser, so you can see how the tests perform in a real life environment. But if you do this, it’s important to run Mocha tests on as many real browsers as possible - to ensure you have broad coverage of platforms used by your users. And unfortunately - this can get quite complex.
Sure, it’s easy to install Firefox, Safari and Chrome (if you’re on Mac), point each of the browsers to the Mocha HTML test file and see if your tests passed or failed. But what about:
- Testing on all the different versions of each browser?
- Internet Explorer (if you’re on Windows) or Safari (if you’re on iOS)?
- Testing the same browsers on the other operating system? (your code could respond differently)
You’ll need to install at least a few dozen browsers on several virtual machines - and run Mocha’s HTML test file in each of them - to make sure you’re covering the platforms your application is viewed on. Doing this once or twice will be pretty hard. But in an agile development environment with a build every day or every few hours, it’s totally out of the question!
Sauce Labs to the rescue - Mocha JS testing made awesome
Here’s where we come in. Sauce can help you run your Mocha tests on as many as 700+ Browser/OS combinations automatically in our cloud testing platform:
- If you have an existing test runner, you can simply send us your tests through a convenient REST API, and continue working as usual, while leveraging the power of the Sauce cloud. See our REST API documentation.
- If you’re new to unit testing or use Grunt, our tutorial below will show you a quick setup, after which you’ll run your Mocha tests on all those platforms with one CLI command:
$ grunt test- we’ll then show you how to feed the results straight to your CI server.
Your first time here?
Sorry, we forgot to introduce ourselves. Sauce Labs is all about making automated testing awesome. Our cloud testing platform has run over 90 million browser tests for thousands of organizations including Salesforce.com, Yelp, Firefox, and the BBC. Our battle-tested platform now enables running JS unit tests in many real browsers quickly and easily. We are now using the same proven platform to help you run JS unit tests in real browsers on a large scale.
Keep in mind: Our cloud service isn’t free. We do have a 14-day free trial that gives you access to 90 hours of testing and up to 8 concurrent sessions. Beyond that, our paid plans start at $19 per month.
So, it’s a pleasure to make your acquaintance, shall we proceed? Read on for our quick tutorial.
About this Mocha JS tutorial
If you have an existing test runner, this tutorial is not for you! Visit these links to use Sauce with Yeti, Karma, Mocha Sauce, or Intern, or for any other test runner, head on to our REST API documentation.
If you are new to unit testing or already use Grunt, read on!
We’re going to use Grunt in conjunction with the grunt-saucelabs plugin (open source) and Node.js. At the end of it, you’ll have a CI system which can run large numbers of Mocha tests on the Sauce Cloud.
If these aren’t the exact languages or technologies you use, don’t worry - you can test on Sauce with Ruby, Python, Java, and many other programming languages. We strongly believe in letting our users stick with the languages and frameworks they are familiar with.
We hope you enjoyed our tutorial and are ready to run your Mocha JS tests on real browsers with Sauce Labs!
Want more? Just sign up for a free trial of Sauce and get testing!