【问题标题】:Gulp run karma tests - can't find variable: angularGulp 运行业力测试 - 找不到变量:角度
【发布时间】:2015-04-05 22:49:11
【问题描述】:

运行 gulp 时,测试运行良好。在文件更改时,错误会被抛出,但随后会运行并通过测试。如果我在运行测试的情况下启动浏览器,它只会出错。我注意到文件没有按照我指定的方式提供。我当前的目录看起来像这样 应用程序 bower_components 节点模块 上市 javascripts 测试 karma.conf.js

gulpfile.js

var gulp = require('gulp');
var karma = require('gulp-karma');
var shell = require('gulp-shell');

var testFiles = [

];

var serverDir = [
    './views/*.js',
    './test/**/*.js',
    './test/*.js',
    './routes/**/*.js',
    './routes/*.js',
    './models/**/*.js',
    './models/*.js',
    'app.js'
];

gulp.task('test', function() {
    // Be sure to return the stream
    return gulp.src(testFiles)
        .pipe(karma({
            configFile: 'public/javascripts/karma.conf.js',
            action: 'watch'
        }))
        .on('error', function(err) {
            // Make sure failed tests cause gulp to exit non-zero
            //throw err;
        });
});

gulp.task('default', ['test', 'testServer', 'watchServerFiles']);

gulp.task('watchServerFiles', function() {
    gulp.watch(serverDir, ['testServer']);
});
gulp.task('testServer', shell.task('jasmine-node-karma test/api.spec.js'));

karma.conf.js

    module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine'],
    files: [
        '../../bower_components/angular/angular.js',
        '../../bower_components/angular-mocks/angular-mocks.js',
        '../../bower_components/angular-resource/angular-resource.js',
        '../../bower_components/angular-route/angular-route.js',
        '../../bower_components/lodash/lodash.js',
        './app.js',
        './controllers/*.js',
        './directives/*.js',
        './services/*.js',
        './*.js',
        './test/*.js',
        './test/**/*.js'
    ],
    reporters: ['progress'],
    browsers: ['PhantomJS'],
    plugins: [
      'karma-jasmine',
      'karma-phantomjs-launcher'
    ],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    singleRun: false
  });
};

【问题讨论】:

    标签: gulp karma-runner gulp-karma


    【解决方案1】:

    查看thread

    两个投票最多的答案都很好,但我决定用 karma 本身替换 gulp-karma。优点是您不需要在 gulpfile.js 和 karma.conf.js 文件中复制文件列表。

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

    【讨论】:

      猜你喜欢
      • 2017-11-24
      • 1970-01-01
      • 1970-01-01
      • 2013-11-13
      • 2017-03-01
      • 2017-11-02
      • 1970-01-01
      • 2013-06-23
      • 1970-01-01
      相关资源
      最近更新 更多