前置き
jasmineはとっても便利!
とってもテストしやすいし、なによりテストが楽しくなる!!
といいことづくしですが、ページロードする度に勝手にテストを実行されてはせっかくの楽しいテストが時間かかりすぎて捗りません。なので、自動で実行しないようにしてみました。
どこをいじったの?
えっと、まずnpmでjasmineを入れたのですが、なんか階層が深い・・・・。
とりあえずこれをいじりました。
/node_modules/jasmine/node_modules/jasmine-core/lib/jasmine-core/boot.js
これを、こうです
変更前
/**
* ## Execution
*
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
*/
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
htmlReporter.initialize();
env.execute();
};
変更後
/**
* ## Execution
*
* Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
*/
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
htmlReporter.initialize();
if (window.location.search === '') {
location.href = '/?spec=0';
} else {
env.execute();
}
};
どうなるの?
こうしておくと、ページロードと同時にテストが始まらず、とりあえずテストリストのみが表示されるようになります。後は、実行したいテストのspecをクリックすればいいですね!
種明かし
パラメータにspec=でどのspecを実行するか?というパラメータを渡すことが出来ます。で、specは普通タイトル(でいいのかな?)を指定するようになってますが、数字を指定すると指定した数字番目のspecが実行されるようになります。specは1番目から順番に並んでるのでspec=0を指定してやることで0番目のspecを実行する(何も実行しない)を実現しています。