启动时打开 Karma debug.html 页面

2023-03-18前端开发问题
1

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

The End

相关推荐

ajax请求获取json数据并处理的实例代码
ajax请求获取json数据并处理的实例代码 $.ajax({ type: 'GET', url: 'https://localhost:44369/UserInfo/EditUserJson',//请求数据 data: json,//传递数据 //dataType:'json/text',//预计服务器返回的类型 timeout: 3000,//请求超时的时间 //回调函数传参 suc...
2024-11-22 前端开发问题
215

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

layui 实现实时刷新一个外部的div
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14 前端开发问题
156

layui laydate日期时间范围,时间默认设定为23:59:59
在Layui中,如果你想设置日期时间选择器(datetime)的默认结束时间为当天的23:59:59,你可以使用如下代码: laydate.render({ elem: '#test10' ,type: 'datetime' ,range: true ,max: '{:date("Y-m-d 23:59:59")}' ,ready: function(date){ $(".layui-laydat...
2024-10-24 前端开发问题
279

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

jQuery怎么动态向页面添加代码?
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18 前端开发问题
125