将茉莉花测试结果输出到控制台

时间:2022-03-02 13:56:08


I am using Jasmine (BDD Testing Framework for JavaScript) in my firefox add-on to test the functionality of my code.

我在我的firefox附加组件中使用Jasmine(用于JavaScript的BDD测试框架)来测试我的代码的功能。

The problem is that jasmine is outputing the test results to an HTML file,what I need is to Firebug Console or other solution to output the results.

问题是茉莉正在将测试结果输出到HTML文件,我需要的是Firebug控制台或其他输出结果的解决方案。

4 个解决方案

#1


29  

Have you tried the ConsoleRepoter

你试过ConsoleRepoter吗?

jasmine.getEnv().addReporter(new jasmine.ConsoleReporter(console.log));

According to the code Jasmine has the ConsoleReporter class that executes a print function (in this case console.log) that should do what you need.

根据代码Jasmine有ConsoleReporter类执行打印功能(在本例中为console.log),它应该做你需要的。

If all else fails you could just use this as a starting point to implement your own console.log reporter.

如果所有其他方法都失败了,您可以将此作为实现自己的console.log记者的起点。

#2


15  

In newest version of Jasmine (2.0) if you want to get test output to console you need to add following lines.

在最新版本的Jasmine(2.0)中,如果要将测试输出提供给控制台,则需要添加以下行。

var ConsoleReporter = jasmineRequire.ConsoleReporter();
var options = {
   timer: new jasmine.Timer, 
   print: function () {
      console.log.apply(console,arguments)
}};
consoleReporter = new ConsoleReporter(options); // initialize ConsoleReporter
jasmine.getEnv().addReporter(consoleReporter); //add reporter to execution environment

Output to html is included by default however so if you don't want html output at all you have to edit your boot.js file and remove relevant lines from there. If you want to customize how output is displayed in console edit file console.js. Source

默认情况下包含输出到html,但是如果您根本不需要html输出,则必须编辑boot.js文件并从那里删除相关行。如果要自定义输出在控制台编辑文件console.js中的显示方式。资源

#3


5  

jasmineRequire.ConsoleReporter did not exist in 2.3.0 so I used the following code:

josmineRequire.ConsoleReporter在2.3.0中不存在,所以我使用了以下代码:

//create a console.log reporter
var MyReporter = function(){jasmineRequire.JsApiReporter.apply(this,arguments);};
MyReporter.prototype = jasmineRequire.JsApiReporter.prototype;
MyReporter.prototype.constructor = MyReporter;
MyReporter.prototype.specDone=function(o){
    o=o||{};
    if(o.status!=="passed"){
      console.warn("Failed:" + o.fullName + o.failedExpectations[0].message);
    }
};
var env = jasmine.getEnv();
env.addReporter(new MyReporter());

#4


2  

For the sake of completeness here's the full configuration:

为了完整起见,这里是完整的配置:

First of all run the npm install command:

首先运行npm install命令:

npm install jasmine-console-reporter --save-dev

Then check your Jasmine configuration to make sure you got the helpers setting there:

然后检查您的Jasmine配置以确保您在那里设置了帮助程序:

spec/support/jasmine.json

规格/支持/ jasmine.json

{
    "spec_dir": "spec",
    "spec_files": [
        "**/*[sS]pec.js"
    ],
    "helpers": [
        "helpers/**/*.js"
    ],
    "stopSpecOnExpectationFailure": false,
    "random": false
}

Since helpers are executed before specs the only thing you have to do is to create a console reporter helper.

由于帮助程序在规范之前执行,因此您唯一需要做的就是创建一个控制台记者帮助程序。

spec/helpers/reporter/consoleReporter.js

规格/助理/记者/ consoleReporter.js

const JasmineConsoleReporter = require('jasmine-console-reporter');

let consoleReporter = new JasmineConsoleReporter({
    colors: 1,           // (0|false)|(1|true)|2
    cleanStack: 1,       // (0|false)|(1|true)|2|3
    verbosity: 4,        // (0|false)|1|2|(3|true)|4
    listStyle: 'indent', // "flat"|"indent"
    activity: false
});

jasmine.getEnv().addReporter(consoleReporter);

#1


29  

Have you tried the ConsoleRepoter

你试过ConsoleRepoter吗?

jasmine.getEnv().addReporter(new jasmine.ConsoleReporter(console.log));

According to the code Jasmine has the ConsoleReporter class that executes a print function (in this case console.log) that should do what you need.

根据代码Jasmine有ConsoleReporter类执行打印功能(在本例中为console.log),它应该做你需要的。

If all else fails you could just use this as a starting point to implement your own console.log reporter.

如果所有其他方法都失败了,您可以将此作为实现自己的console.log记者的起点。

#2


15  

In newest version of Jasmine (2.0) if you want to get test output to console you need to add following lines.

在最新版本的Jasmine(2.0)中,如果要将测试输出提供给控制台,则需要添加以下行。

var ConsoleReporter = jasmineRequire.ConsoleReporter();
var options = {
   timer: new jasmine.Timer, 
   print: function () {
      console.log.apply(console,arguments)
}};
consoleReporter = new ConsoleReporter(options); // initialize ConsoleReporter
jasmine.getEnv().addReporter(consoleReporter); //add reporter to execution environment

Output to html is included by default however so if you don't want html output at all you have to edit your boot.js file and remove relevant lines from there. If you want to customize how output is displayed in console edit file console.js. Source

默认情况下包含输出到html,但是如果您根本不需要html输出,则必须编辑boot.js文件并从那里删除相关行。如果要自定义输出在控制台编辑文件console.js中的显示方式。资源

#3


5  

jasmineRequire.ConsoleReporter did not exist in 2.3.0 so I used the following code:

josmineRequire.ConsoleReporter在2.3.0中不存在,所以我使用了以下代码:

//create a console.log reporter
var MyReporter = function(){jasmineRequire.JsApiReporter.apply(this,arguments);};
MyReporter.prototype = jasmineRequire.JsApiReporter.prototype;
MyReporter.prototype.constructor = MyReporter;
MyReporter.prototype.specDone=function(o){
    o=o||{};
    if(o.status!=="passed"){
      console.warn("Failed:" + o.fullName + o.failedExpectations[0].message);
    }
};
var env = jasmine.getEnv();
env.addReporter(new MyReporter());

#4


2  

For the sake of completeness here's the full configuration:

为了完整起见,这里是完整的配置:

First of all run the npm install command:

首先运行npm install命令:

npm install jasmine-console-reporter --save-dev

Then check your Jasmine configuration to make sure you got the helpers setting there:

然后检查您的Jasmine配置以确保您在那里设置了帮助程序:

spec/support/jasmine.json

规格/支持/ jasmine.json

{
    "spec_dir": "spec",
    "spec_files": [
        "**/*[sS]pec.js"
    ],
    "helpers": [
        "helpers/**/*.js"
    ],
    "stopSpecOnExpectationFailure": false,
    "random": false
}

Since helpers are executed before specs the only thing you have to do is to create a console reporter helper.

由于帮助程序在规范之前执行,因此您唯一需要做的就是创建一个控制台记者帮助程序。

spec/helpers/reporter/consoleReporter.js

规格/助理/记者/ consoleReporter.js

const JasmineConsoleReporter = require('jasmine-console-reporter');

let consoleReporter = new JasmineConsoleReporter({
    colors: 1,           // (0|false)|(1|true)|2
    cleanStack: 1,       // (0|false)|(1|true)|2|3
    verbosity: 4,        // (0|false)|1|2|(3|true)|4
    listStyle: 'indent', // "flat"|"indent"
    activity: false
});

jasmine.getEnv().addReporter(consoleReporter);