Where can i mention source js files that needs to be tested in gulp-jasmine?

40 Views Asked by At

Here is what i am using as of now.

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

But in case of grunt, you can mention source files like this

jasmine: {
        src: 'js/**/*.js',
        options: {
            specs: 'spec/**/*.js'
        }
    }
  1. Where can i mention the location for source files in case of gulp ?
  2. Another issues is that gulp only runs the test cases from first file, as of now all of them fails, and it doesn't go to the second files in the spec folder.
1

There are 1 best solutions below

0
On

For issue 2 I see this gulp-jasmine option:

errorOnFail

Default: true

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

should run the rest of the tests.

Issue 1: There are a number of ways to indicate multiple sources for gulp.src such as

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

or set up a variable:

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

or I use something like this:

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"
  }
};

and then to use:

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 }));
}

BTW, putting two questions into one post is generally frowned upon on SO.