Karma basePath默认为C:\

时间:2014-06-04 20:56:19

标签: javascript karma-runner gulp karma-jasmine

我试图通过karma运行jasmine Specs但是当karma查找我包含的文件时,它使用C:\的基本路径,即使配置文件在C:\dev\project\中。

我在吞咽任务中运行Karma:

var karma = require('karma').server;
gulp.task('test', function (done) {
    karma.start({configFile: '../../../karma.conf.js', singleRun: true}, done);
});

与此问题相关的设置:

basePath: '',
files: [
 {patterns:'bower_components/**/*.js',included:true},
 {patterns:'src/*.js', included:true},
 {patterns:'tests/*Spec.js', included:true}
],
exclude: []

当我运行gulp test时,来自业力的日志吐出来:

WARN [watcher]: Pattern "C:/bower_components/**/*.js" does not match any file.
WARN [watcher]: Pattern "C:/src/*.js" does not match any file.
WARN [watcher]: Pattern "C:/tests/*Spec.js" does not match any file.

我是业力新手,我不确定这里的问题是什么。我尝试了basePath '''./''/'

1 个答案:

答案 0 :(得分:6)

使用以下命令将basePath设置为本地CWD目录路径:

basePath: process.cwd(), //  this gets the path which gulp is running in terminal
files: [
 {patterns:'bower_components/**/*.js',included:true},
 {patterns:'src/*.js', included:true},
 {patterns:'tests/*Spec.js', included:true}
],
exclude: []

process.cwd()获取CLI路径,即终端中运行节点的路径。