From Karma to Mocha, with a taste of jsdom
1–10 of 20 posts
Re: From Karma to Mocha, with a taste of jsdom
#2Re: From Karma to Mocha, with a taste of jsdom
#3Thanks for the good read, very enlightening. But, I thought the choice of React as an example was interesting since it already provides test utilities. Any specific reason you aren't using these or were they just omitted for simplifying a blog post? https://facebook.github.io/react/docs/test-utils.html
It's easy to say "But 0.13 was ages ago", but in reality it was only released back in March, which may seem like an eternity to Hacker News, but in the real world isn't long at all, and not necessarily long enough for businesses to change their working practices if they already have other methods working well for them.
Re: From Karma to Mocha, with a taste of jsdom
#4One of the things I like about Karma is the ability to run the test suite in a number of browsers. We run our suite in Firefox, Chrome and PhantomJS as part of the CI setup.
I wonder if it wouldn't have been possible to set up a complementary test runner which allowed your Jasmine tests to be run with jsdom? That would give you the speed increase, but without needing to port, and would have allowed you to still leverage Karma when needed.
However, a good read and the Karma bootup time is certainly a pain point I've felt!
Re: From Karma to Mocha, with a taste of jsdom
#5There's a great article [0] about tape, which I'd suggest giving a read!
If you want to run your tests on all the browsers, you can use zuul [1], which is also dead simple to use!
[0] https://medium.com/javascript-scene/why-i-use-tape-instead-o...
Re: From Karma to Mocha, with a taste of jsdom
#6Karma is a test runner. Use Karma to launch and run your tests in real browser instances. There is no better tool available for doing this.
Mocha is used to actually create your test suite. It's great at describing how your tests should run, with stuff like before/afterEach, it.only, describe.skip, etc. Use Mocha to describe which tests you want to run and how they should run.
You can easily load Mocha onto the page in your karma config using the karma-mocha plugin. Then, one line in your karma config and you're done. https://github.com/rackt/react-router/blob/53623216560e34fbe...
As for file watching (also part of the OP) your bundler should be doing that. Use karma-webpack (or whatever tool you're using to create your bundle).
Finally- probably the best thing about Karma is its wide support in the community. You can find a Karma plugin for just about any other tool you might want to use, including launchers for hosted browser environments like Sauce Labs and BrowserStack.
Re: From Karma to Mocha, with a taste of jsdom
#7Karma shines when you're running integration/e2e tests against _real_ browsers, especially IE.
Re: From Karma to Mocha, with a taste of jsdom
#8Karma and Mocha don't do the same thing, so this comparison is weird. Karma is a test runner. Use Karma to launch and run your tests in real browser instances. There is no better tool available for doing this. Mocha is used to actually create your test suite. It's great at describing how your tests should run, with stuff like before/afterEach, it.only, describe.skip, etc. Use Mocha to describe which tests you want to…
Also, from first glance, I'm unable to see a performance improvement by not using Karma. It may be because they're using more tests in Mocha, but the difference isn't huge considering they're losing a lot of functionality.
Re: From Karma to Mocha, with a taste of jsdom
#9Re: From Karma to Mocha, with a taste of jsdom
#10It seems that the majority of the benefit was replacing a browser instance (PhantomJS launched via Karma) with a virtual-DOM (jsdom). Karma shines when you're running integration/e2e tests against _real_ browsers, especially IE.
If you want to run automated tests on every browser, you pick up a SauceLabs account, configure the simple zuul.yml file, and you're done. If you wanna run it locally, you run the zuul cli tool and open the link with that browser.