【问题标题】:Where can i mention source js files that needs to be tested in gulp-jasmine?我在哪里可以提到需要在 gulp-jasmine 中测试的源 js 文件?
【发布时间】:2017-08-24 19:33:17
【问题描述】:

这是我现在使用的。

gulp.task('test', function () {
    return gulp.src([ './app/spec/*.js'])
    .pipe(jasmine());
});

但如果是 grunt,你可以像这样提及源文件

jasmine: {
        src: 'js/**/*.js',
        options: {
            specs: 'spec/**/*.js'
        }
    }
  1. 如果是 gulp,我在哪里可以提及源文件的位置?
  2. 另一个问题是 gulp 仅从第一个文件运行测试用例,到目前为止,它们都失败了,并且不会转到 spec 文件夹中的第二个文件。

【问题讨论】:

    标签: gulp jasmine gulp-jasmine


    【解决方案1】:

    对于问题 2,我看到了这个 gulp-jasmine 选项:

    errorOnFail

    Default: true
    
    Stops the stream on failed tests.
    
    .pipe(jasmine({errorOnFail: false})) 
    

    应该运行其余的测试。

    问题 1:有多种方法可以指示 gulp.src 的多个来源,例如

    return gulp.src([ './app/spec/*.js', 'spec/**/*.js']) 
    

    或者设置一个变量:

    var testSources = ['./app/spec/*.js', 'spec/**/*.js'];
    return gulp.src(testSources)
    

    或者我使用这样的东西:

    var paths = {
      html: {
        src: "home.html",
        temp: "./temp",
        deploy: "./deploy/html"
      },
      sass: {
        src: "./src/styles/scss/**/*.scss",
        stylesFile: "./src/styles/scss/styles.scss"
      },
      css: {
        src: "./temp/css/styles.css",
        temp: "./temp/css",
        deploy: "./deploy/css"
     },
      js: {
        src: "./src/js/**/*.js",
        temp: "./temp/js",
        deploy: "./deploy/js"
      }
    };
    

    然后使用:

    function reloadJS() {
      return gulp.src(paths.js.src)
        .pipe(sourcemaps.init())
        .pipe(sourcemaps.write("../sourcemaps", {includeContent:false,sourceRoot:"/js"}))
        .pipe(gulp.dest(paths.js.temp))
        .pipe(reload({ stream:true }));
    }
    

    顺便说一句,将两个问题放在一篇文章中通常是不受欢迎的。

    【讨论】:

      猜你喜欢
      • 2013-11-24
      • 1970-01-01
      • 2020-12-04
      • 2010-11-19
      • 2011-10-31
      • 2020-10-06
      • 2014-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多