5

I am working on setting up test runner tasks for our project and ran into something unexpected. Our task wasn't getting any of the files using the below pattern:

'/tests/**/*.spec.js'

Our directory structure is like this:

--Scripts
     --app
     --tests
         -test.spec.js

     -gulp.js
     -karma.conf.js
     etc.

However, this was bring forward 0 test cases. When I changed the pattern to this, instead:

'/tests/*.spec.js'

Then it works as expected. Now, I know the /**/*spec.js is a pattern for "files that end with 'spec.js' in zero or more sub directories". But, it feels like there should be a simple pattern to say "all files that end with 'spec.js' in this directory and in zero or more sub-directories". Otherwise, I know have to use both patterns if my structure looks like this:

--Scripts
     --app
     --tests
         -test.spec.js
         --subTests
             -test2.spec.js
     -gulp.js
     -karma.conf.js
     etc.

The above would require my gulp task to look something like below:

gulp.task('unit-test', ['lint'], function (done) {
    gulputil.log('Running unit tests...');
    //return gulp.src(testFilesDirect).pipe(jasmine({ verbose: true, includeStackTrace: true }));
    new KarmaServer({
        configFile: __dirname + '/karma.conf.js',
        files: ['/tests/*.spec.js', '/tests/**/*.spec.js'],
        // Continuous Integration mode
        // if true, Karma captures browsers, runs the tests and exits
        singleRun: false
    }, done).start();
});

Is that correct or am I missing something fundamental that wouldn't require two test patterns?

There is another article that talks about symlinks here: Gulp - Target all files in a folder and its subfolders

But that seems to be directed towards a more localized setup whereas my situation needs to be part of an automated build system, additionally, those solutions involved Linux or Mac and our systems are Windows based.

Community
  • 1
  • 1
JasonWilczak
  • 2,303
  • 2
  • 21
  • 37
  • Could be a NodeJS or Gulp version issue? I set up a glob in the same structure you have and it was able to stream with both files with just `'/scripts/**/*.spec.js'`. This is on `node v5.6.0` and `gulp 3.9.0` – JSess Apr 25 '16 at 21:27
  • Nice thought, I just checked my versions: Gulp 3.9.0 and Node v5.7.0.... – JasonWilczak Apr 26 '16 at 12:34
  • So frustrating that this never got a good answer! – bnieland Mar 07 '23 at 03:48

0 Answers0