Tuesday, March 24, 2015

3/24/15 - Karma Setup

We worked more on setting up Karma and Mocha.

First I ran karma init, which asks a series of questions about what you want Karma to do, and generates a karma.conf.js file based on your responses.  I also had to add some additional stuff myself.  Here's what Finn and I ended up with at the end of the period today.

 Next, I added mocha and chai to the frameworks array in the config. Several dependencies also need to be downloaded through npm. We got karma-firefox-launcher (npm install karma-firefox-launcher) so that karma could start a firefox instance, and karma-mocha so that karma can talk to mocha (npm install karma-mocha).

We also got chai, which is a library that allows you to do #expect(), #should(), and other test-related methods in mocha tests with npm install chai --save-dev. We then got the karma-chai adapter (npm install karma-chai --save-dev)

Note: I'm not sure what the --save-dev flag does, but it apparently logs it as a dependency in some sort of json file (I assume this is more geared towards node projects though). There's also the -g flag, which installs globally.

In order to make our lives easier, we also got karma-cli, which allows you to run karma directly from the command line.

With that done, you should be able to run karma start to start a web server with karma, and then in a new terminal, karma run. Make sure you run from the librifox directory so that karma will be able to find the karma.conf.js file.

Finn also expanded the testing of #stripHTMLTags (since that's the most easily testable method right now!)

One problem I see with this is if anyone else wants to run tests in our repo, they have to install all these dependencies, which is annoying for them.

1 comment:

  1. One of the reasons I'm so delighted you and Finn agreed to do the "Introduction to Firefox OS Programming" workshop on June 6th is that it will present you the opportunity (force you, actually) to stream line and summarize everything you're learning here into a repeatable process others can follow. That will mean I can pass on what you learn to other students next year and beyond.

    In Python, we have doctest (http://en.wikipedia.org/wiki/Doctest), which is the lightest, easiest to explain and use testing mechanism I've ever seen (and one of the many reasons I love Python so much). Every other testing setup I've seen involves large amounts of configuration and customization before you can even begin. That makes a system for experts, not beginners, even though I'm convinced that an early exposure to testing is of great benefit to beginners.

    Anyway, I'm hoping with the help of our friends at Mozilla we will be able to arrive at the least difficult testing process for Firefox OS.

    ReplyDelete