启动时打开Karma debug.html页面 [英] Open Karma debug.html page on startup

查看:1085
本文介绍了启动时打开Karma debug.html页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何启动Karma并让它在与浏览器相同的浏览器中自动打开debug.html文件噶开始页?



长版:



我不是一个使用控制台记者Karma的巨大粉丝,所以我一直在使用业力-jasmine-html-reporter-livereload ,它输出到Karma的localhost:9876 / debug.html文件。问题是,每次我开始一个调试会话时,都必须点击业务打开的网页中的调试按钮。



我想找到一种方法让业力通过一个吞噬任务自动打开debug.html页面。我在多个浏览器中运行测试,因此我希望打开debug.html页面作为Karma打开的每个浏览器中的第二个选项卡。我也想在关闭karma时关闭debug.html选项卡。我试过了一堆东西,没有成功。



这是我的大嘴巴任务。 'watch'任务监视我的源代码TypeScript文件并将它们编译为javascript ...没有任何花哨。

  gulp.task('watch-test',['watch'],function(done){
/ /开始一个livereload服务器,以便因果报应html
//记者知道每当脚本改变时重新加载$ ​​b $ b livereload.listen(35729);
gulp.watch('dist / src / ** /*.js').on('change',livereload.changed);

new KarmaServer({
configFile:__dirname +'/karma.conf.js',
singleRun:false
},done).start();
});


解决方案

不完美..你可以注入一个JavaScript的上下文:

 文件:[
test / init.js ,
...
]

并将这段代码放入文件:

 (function(window){
if(!window.parent.initDone&& window.location ('/ debug.html','_blank');
}
})(window)

这将确保窗口仅在第一次打开测试运行,只会在context.html中执行。



您可以在该块中添加您希望的任何init代码。


The short version:

How do I start up Karma and have it open the debug.html file automatically in the same browser as the Karma start page?

The long version:

I'm not a huge fan of using the console reporters for Karma, so I have been using karma-jasmine-html-reporter-livereload which outputs to Karma's localhost:9876/debug.html file. The problem is, every time I start a debugging session, I have to click the 'debug' button in the web page that karma opens.

I would like to find a way to have karma open the debug.html page automatically through a gulp task. I run the tests in multiple browsers, so I would like the debug.html page to open as a second tab in each of the browsers that Karma opens. I would also like to be able to close that debug.html tab when karma closes. I've tried a bunch of things, with no success.

Here's my gulp task. The 'watch' task watches my source TypeScript files and compiles them into javascript...nothing fancy.

gulp.task('watch-test', ['watch'], function (done) {
    //start a livereload server so that the karma html 
    //reporter knows to reload whenever the scripts change
    livereload.listen(35729);
    gulp.watch('dist/src/**/*.js').on('change', livereload.changed);

    new KarmaServer({
        configFile: __dirname + '/karma.conf.js',
        singleRun: false
    }, done).start();
});

解决方案

I found a way that makes it permanent although it is not perfect.. You can inject into the context a javascript:

files: [
    "test/init.js",
    ...
]

and put inside the file this code:

(function (window) {
    if (!window.parent.initDone && window.location.pathname === '/context.html') {
         window.parent.initDone = true;
         window.open('/debug.html', '_blank');
    }
})(window)

this will ensure that the window is open only the first time the tests are run and it will be executed only in context.html.

You can add any init code you wish inside that block.

这篇关于启动时打开Karma debug.html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆