jasmine/gulp-jasmine-browser

Fail with files with the same name

Closed this issue · 2 comments

I have a simple gulp task:

gulp.task('jasmine', function() {
  return gulp.src([
    'node_modules/underscore/underscore.js',
    'node_modules/angular/angular.js',
    'node_modules/angular-mocks/angular-mocks.js',
    '.tmp/app/all.js',
    '.tmp/test/unit/all.js'
  ])
    .pipe($.jasmineBrowser.specRunner())
    .pipe($.jasmineBrowser.server());
});

.tmp/app/all.js is reduced to simply all.js, same for .tmp/test/unit/all.js because of this code: https://github.com/jasmine/gulp-jasmine-browser/blob/master/index.js#L78

Suggestion: keep the full path for the filenames, after all this is what people do when they manually write a SpecRunner.html file, example:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Jasmine Spec Runner</title>

    <link rel="shortcut icon" href="node_modules/jasmine-core/images/jasmine_favicon.png">
    <link rel="stylesheet" href="node_modules/jasmine-core/lib/jasmine-core/jasmine.css">

    <script src="node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
    <script src="node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
    <script src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>

    <!-- Source dependencies -->
    <script src="node_modules/underscore/underscore.js"></script>
    <script src="node_modules/angular/angular.js"></script>

    <!-- Spec dependencies -->
    <script src="node_modules/angular-mocks/angular-mocks.js"></script>

    <!-- Source files -->
    <script src=".tmp/app/all.js"></script>

    <!-- Spec files -->
    <script src=".tmp/test/unit/all.js"></script>
  </head>
  <body>
  </body>
</html>

Edit: just to understand the use case, .tmp/app/all.js and .tmp/test/unit/all.js are produced by TypeScript (concatenation from multiple .ts files).

We need to use file.relative so we don't get the absolute path to the file on disk. After some digging, it looks like with the particular src you're giving gulp, it can't figure out what a reasonable relative directory is. (See http://stackoverflow.com/questions/21386940/why-does-gulp-src-not-like-being-passed-an-array-of-complete-paths-to-files/21387311#21387311) If you tell gulp.src what the base directory should be in a second param, you should get the correct output.

Wow, you are right! this works:

gulp.task('jasmine', function() {
  return gulp.src(
    [
      'node_modules/underscore/underscore.js',
      'node_modules/angular/angular.js',
      'node_modules/angular-mocks/angular-mocks.js',
      '.tmp/app/all.js',
      '.tmp/test/unit/all.js'
    ],
    { base: '.' }
  )
    .pipe($.jasmineBrowser.specRunner())
    .pipe($.jasmineBrowser.server());
});

gulp is non intuitive on this.