Concepts
laika
is a combination of technologies including phantomjs
, mocha
, meteor
itself and some tricks. In this section you’ll be learning how laika works internally. It will help you to write better tests and understand why laika is bit slower than other testing frameworks.
Testing with the actual app
laika
is not anything about mocking or stubbing. Your tests will be tested against your actuall meteor app and using real browsers (phantomjs
in this case)
Each test will run on it’s own app and a separate database
Best thing about laika is, each test will run against separate process or your app and with a clean db. This is really good since your tests are isolated
from another. It’s kind a slower, but we’ve reduced the slowness with following techniques.
- fast mongod process with these options -
mongod --smallfiles --noprealloc --nojournal
- pooling apps so you don’t need to wait app to get loaded
- Running
mongod
on a ramdisk - see this guide
There are some other ways to increase the speed, but not yet tested
- Use parallel testing (
mocha
does not support this, and writing a test suite from the ground is not cool)
Server and your test communicate via a TCP connection
- At the beginning of the test,
laika
will inject piece of code block(runs on server) into your meteor app - When your app starts it will start a TCP connection and your test now can communicate with the server
- Test sends codes over the TCP connection and injected code will
eval()
it - Result of the
eval()
will be send via the TCP connection too (usingemit()
which you’ve seen on the getting started guide)
Client code is too evaluated on a real browser
- We use
phantomjs
for this, it is a headless webkit browser - Code will be evaluated on the client with
evaluate()
of phantomjs and injecting 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
- Of course you can check it with
git diff
:)
Using mocha
- What
laika
focus on how you can write tests on both client and the server at once. - We don’t need to build another test suite
- So we use
mocha
internally