Karma public api缺少configFile选项 [英] Karma public api lacks configFile option

查看:141
本文介绍了Karma public api缺少configFile选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gulp-karma建议这样一个外部配置文件:

  module.exports = {
asePath:' ',
singleRun:true
};

我想要一个像这样的外部配置文件(grunt-karma style):

  module.exports = function(config){
config.set({
basePath:'',
singleRun :true
});
};

如何使用正确的配置文件 karma API。

详细信息:



我使用gulp-karma,并且如前所述
<
i必须自己实施。

>

Karma API 很简单:

  var server = require('karma')。server; 
server.start(config,done);

config 变量含糊不清。这是一个普通对象,带有配置

  var config = {
basePath:'',
singleRun:true
// ...
}

让我们来看看grunt-karma:



示例grunt-karma配置:

  karma:{
单位:{
configFile:'karma。 conf.js'
}
}

grunt-karma配置可以采用 configFile 选项,这是没有记录的任何地方



我可以看到,我可以从 configFile //github.com/karma-runner/karma/blob/master/lib/server.js#L282\">业力源代码

var config = cfg.parseConfig(cliOptions.configFile,cliOptions);



是否有文档f或提到 configFile 选项的Karma API,grunt-karma如何知道
使用它

这个问题出人意料地相关,这些评论的大部分都在本文最后提出的实际问题上变得轻而易举:grunt-karma如何知道使用配置对象的属性名为 configFile

我也一直在想,同样的事情,因为该属性没有列在karma配置文档中的任何地方。例如,如果我想通过我的gulp文件中的公共API来运行我的业力测试。它看起来像这样:
...

pre $ var karmaConfig = require('spec / karma.conf.js );
//其中我的配置文件导出一个对象,其属性如exclude:,路径:
karma.start(karmaConfig)},process.exit);

这可以正常工作,除非我想导出配置函数,所以我可以使用配置常量(这里):

  //允许我这样做

module.exports = function(config){
config.set({
logLevel: config.LOG_INFO
});
}

但是没有办法让这个工作起作用,除非你使用这样的东西:

  karma.start({configFile:'spec / karma.conf.js'},process.exit); 

在那里我简单地传入一个包含 configFile 指向实际的配置文件。



Karma docs 不要在任何地方提及(如此评论),但它是通过API完成我的测试的唯一方法同时使用配置功能导出方法。


gulp-karma suggests an external config file like this:

module.exports = {
    basePath: '',
    singleRun: true
};

I want an external config file like this (grunt-karma style):

module.exports = function(config) {
    config.set({
         basePath: '',
         singleRun: true
    });
};

How to use the proper config file with karma API.

Details:

I am using gulp-karma, and as mentioned there, i have to implement it on my own.

Karma API is very simple:

var server = require('karma').server;
server.start(config, done);

config variable is vague. It is a plain object with configuration:

var config = {
    basePath: '',
    singleRun: true
    // ...
}

Let's take a look at grunt-karma:

Sample grunt-karma config:

karma: {
  unit: {
      configFile: 'karma.conf.js'
  }
}

grunt-karma configuration can take a configFile option, which is not documented anywhere.

I can see, i can pass a configFile option from karma source code:

var config = cfg.parseConfig(cliOptions.configFile, cliOptions);

Is there a documentation for the Karma API that mentions configFile option, how does grunt-karma know to use it.

解决方案

This question is surprisingly relevant, and most of these comments breeze over the actual question posed at the end of this post: "How does grunt-karma know to use a config object with a property called configFile.

I, too, have been wondering the same thing as that property is not listed anywhere in the karma config docs. For instance, if I would like to run my karma tests via the public API in my gulpfile. It would look like this: ...

var karmaConfig = require('spec/karma.conf.js');
// where my config file exports an object with properties like exclude:, path:
karma.start(karmaConfig)}, process.exit);

This would work fine, except if I wanted to export the config function so I can use the config constants (outlined here):

// allows me to do this

module.exports = function(config) {
    config.set({
        logLevel: config.LOG_INFO
    });
}

But there's no way to get this to work unless you use something like this:

karma.start({configFile: 'spec/karma.conf.js'}, process.exit);

Where I simply pass in an object with a property configFile that points to the actual config file.

Karma docs don't mention this anywhere (as of this comment), but it's the only way to accomplish running my test via the API while using the config function export method.

这篇关于Karma public api缺少configFile选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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