启动时打开 Karma debug.html 页面

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

问题描述

简短版:

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

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

长版:

我不太喜欢使用控制台记者来记录 Karma,所以我一直在使用 karma-jasmine-html-reporter-livereload 输出到 Karma 的 localhost:9876/debug.html 文件.问题是,每次我开始调试会话时,我都必须单击 karma 打开的网页中的调试"按钮.

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.

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

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.

这是我的 gulp 任务.监视"任务监视我的源 TypeScript 文件并将它们编译成 javascript……没什么特别的.

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();
});

推荐答案

我找到了一种让它永久化的方法,虽然它并不完美.你可以在上下文中注入一个 javascript:

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)

这将确保该窗口仅在第一次运行测试时打开,并且仅在 context.html 中执行.

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 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I can get a text of all the cells of the table using testcafe(如何使用 testcafe 获取表格中所有单元格的文本)
node_modules is not recognized as an internal or external command(node_modules 未被识别为内部或外部命令)
How can I create conditional test cases using Protractor?(如何使用 Protractor 创建条件测试用例?)
PhantomJS and clicking a form button(PhantomJS 并单击表单按钮)
Clicking #39;OK#39; on alert or confirm dialog through jquery/javascript?(在警报上单击“确定或通过 jquery/javascript 确认对话框?)
QunitJS-Tests don#39;t start: PhantomJS timed out, possibly due to a missing QUnit start() call(QunitJS-Tests 不启动:PhantomJS 超时,可能是由于缺少 QUnit start() 调用)