laika is a combination of technologies including
meteor itself, and some tricks. In this section you’ll be learning how laika works internally. It will help you write better tests and understand why laika is a bit slower than other testing frameworks.
Testing with the actual app
laika doesn’t do mocking or stubbing. Your tests will be tested against your actual Meteor app and using real browsers (
phantomjs in this case).
laika’s focus is on writing tests for both the client and server. We don’t need to build another test suite, so we use
Each test will run on its own app and a separate database
Best thing about laika is, each test will run against a separate process of your app and with a clean database. This is really good since your tests are isolated from each another. It’s a bit slower, but we’ve sped things up in a few ways:
- Fast mongod process with these options -
mongod --smallfiles --noprealloc --nojournal
- Pooling apps so you don’t need to wait for the app to get loaded
mongodon a ramdisk - see this guide
There are some other ways to increase the speed, but not yet tested:
- Use parallel testing (
mochadoes not support this, and writing a test suite from the ground up is not cool)
The server and your test communicate via a TCP connection
- At the beginning of the test,
laikawill inject a code block that runs on the server into your Meteor app
- When your app starts, it will start a TCP connection so your test can communicate with the server
- The test sends its code over TCP and the injected code will
- The result of the
eval()is sent back via TCP (using
emit(), which you’ve seen in the Getting Started guide)
Client code is evaluated in a real browser
- We use
phantomjsfor this. It’s a headless browser (meaning no graphical interface is required), based on WebKit.
- Your test code will be evaluated on the client with phantomjs’s
evaluate()method and by injecting a small piece of code into your meteor app.
All the injected code will be removed
- Injected code can be used to exploit your app in production
- But don’t worry - we’ll remove it after the test
- You can check that with