- Laikaは、実際のアプリケーションと同じ方法でテストを実行します(PhantomJSを使用)
- 各テストは分離されています。 MeteorJSアプリケーションがクリーンなデータベースで再び起動します
- 開発には流星とmet石の両方を使用できますが、ライカはそれらの両方でうまく機能します
- 1つのテストでサーバーとクライアントでテストを実行できます。 これは、許可、サブスクリプション、メソッド呼び出しなどの瞬間をテストするのに役立ちます。
- MeteorJSはリアルタイムで動作するため、同時に複数のクライアントを操作する場合は、アプリケーションをテストする必要があります。 ライカできます。
- より正確なテストのためにイベントを使用する機能、つまり、実際にはユーザーの作業をエミュレートする
- テスト実行中に引数を使用してコードに値を渡す
- テンプレート生成の完了を待っています
設置
1. npmを使用してインストールします。
sudo npm install -g laika
2. PhantomJSをダウンロードしてインストールします 。
3.次のようにmongodbを実行します。
$ mongod --smallfiles --noprealloc --nojournal
テスト付きの最もシンプルなアプリケーション
新しいアプリケーションを作成します。
$ meteor create meteor-laika
collectionsディレクトリとその中にposts.jsファイルを作成します
// collections/posts.js Posts = new Meteor.Collection('posts');
testsディレクトリとposts.jsを作成します
//tests/posts.js var assert = require('assert'); suite('Posts', function() { test('in the server', function(done, server) { server.eval(function() { Posts.insert({title: 'hello title'}); var docs = Posts.find().fetch(); emit('docs', docs); }); server.once('docs', function(docs) { assert.equal(docs.length, 1); done(); }); }); });
ここでは、Postsというテストスイートを作成しました。これには、サーバーで1つのテストが呼び出されています。 したがって、このテストでは、コレクションにエントリが追加されているかどうかを確認します。 これを行うために、以下を作成しました。
server.eval(function() { Posts.insert({title: 'hello title'}); // var docs = Posts.find().fetch(); // emit('docs', docs); // });
emit関数を呼び出すと、適切な名前を持つonceメソッドが呼び出されます。 したがって、これらの操作の後、次のようになります。
server.once('docs', function(docs) { // assert.equal(docs.length, 1); // , done(); // });
テストの準備ができました。 アプリケーションをテストするには、
$ laika
以下が表示されます。

クライアントとサーバーでのテスト
テストスイート内に、このテストを挿入します。
test('using both client and the server', function(done, server, client) { server.eval(function() { Posts.find().observe({ added: addedNewPost // , , addedNewPost }); function addedNewPost(post) { emit('post', post); // "post" post ( ) } }).once('post', function(post) { // "post" assert.equal(post.title, 'hello title'); // , done(); // }); client.eval(function() { Posts.insert({title: 'hello title'}); // }); });
結果は次のようになります。

2つのクライアントでテストする
テストスイート内に次のコードを追加します。
test('using two client', function(done, server, c1, c2) { c1.eval(function() { Posts.find().observe({ added: addedNewPost // }); function addedNewPost(post) { emit('post', post); // , "post" } emit('done'); // "done" }).once('post', function(post) { assert.equal(post.title, 'from c2'); // , , done(); }).once('done', function() { c2.eval(insertPost); // insertPost }); function insertPost() { Posts.insert({title: 'from c2'}); // ( , ), } });
結果は次のようになります。

また、アプリケーションでiron-routerを使用する場合、テストの前に少なくとも1つのビューを作成します。ビューなしでは、すべてのテストが失敗します。
サイトにはかなりの数の例があります 。 ここでそれらを見ることができます 。 記録は小さいことが判明しましたが、この興味深いフレームワークを理解し始めた人には役立つことを願っています。 彼女はこのページの翻訳を無料で追加しています。 また、現時点でMeteorJSでアプリケーションをテストしている方法や、laikaが興味を持っているかどうかを聞くのも興味深いでしょう。