Karma基础路径默认为C:\。

3

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

我在gulp任务中运行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命令时,karma的日志输出如下:
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.

我是karma的新手,不太明白问题出在哪里。我尝试过 '''./''/' 这些 basePath


请在问题中添加标签“javascript”,这将增加语法高亮显示。 - SteveLacy
1个回答

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路径,即在终端中运行node的路径。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接