我尝试使用browserify和mocha扩展在Karmajs中使用gulp任务来测试我的客户端脚本,但是只运行了一个测试文件。这是我的gulp任务
let Server = require('karma').Server;
gulp.task('client-test', function (done) {
new Server({
configFile: `${__dirname}/karma.conf.js`,
singleRun: true
}, done).start();
});
这是我的配置文件:
module.exports = function (config) {
config.set({
basePath: '../',
frameworks: ['mocha', 'browserify'],
files: [{ pattern: 'client/test/spec/**/*.js', included: true }],
preprocessors: {
"client/test/spec/**/*.js": ['browserify']
},
client: {
mocha: {
reporter: 'html',
ui: 'bdd'
}
},
browserify: {
debug: true,
transform: ['babelify', 'debowerify', 'brfs']
},
reporters: ['spec'],
port: 8081,
colors: true,
logLevel: config.LOG_INFO,
autowatch: true,
browsers: ['PhantomJS'],
phantomjsLauncher: {
exitOnResourceError: true
}
});
};
正如您所看到的,我使用**选择器来获取所有子目录中的js文件,但是当我运行任务时,我得到以下输出:
> node_modules/gulp/bin/gulp.js "client-test"
[12:24:26] Using gulpfile ~/workspace/gulpfile.js
[12:24:26] Starting 'client-test'...
[BABEL] Note: The code generator has deoptimised the styling of "/home/ubuntu/workspace/bower_components/angular-mocks/angular-mocks.js" as it exceeds the max of "100KB".
[BABEL] Note: The code generator has deoptimised the styling of "/home/ubuntu/workspace/bower_components/angular/angular.js" as it exceeds the max of "100KB".
[BABEL] Note: The code generator has deoptimised the styling of "/home/ubuntu/workspace/bower_components/rxjs/dist/rx.all.js" as it exceeds the max of "100KB".
08 06 2016 12:24:51.273:INFO [framework.browserify]: bundle built
08 06 2016 12:24:51.334:INFO [karma]: Karma v0.13.22 server started at http://0.0.0.0:8081/
08 06 2016 12:24:51.362:INFO [launcher]: Starting browser PhantomJS
08 06 2016 12:25:04.754:ERROR [phantomjs.launcher]: Fontconfig warning: ignoring C.UTF-8: not a valid language tag
08 06 2016 12:25:09.105:INFO [PhantomJS 2.1.1 (Linux 0.0.0)]: Connected on socket /#SqfLEWAUFbgjRpw6AAAA with id 21013769
AuthService
✓ Logs in a existing user
✓ Registers a new user
✓ Checks to see if a user is already authenticated
PhantomJS 2.1.1 (Linux 0.0.0): Executed 3 of 3 SUCCESS (0.152 secs / 0.041 secs)
TOTAL: 3 SUCCESS
为什么只运行一个测试文件?我做错了什么?
答案 0 :(得分:0)
事实证明,当第二个文件中出现错误时,测试将不会对第二个文件运行。