Coder Social home page Coder Social logo

Comments (8)

jbblanchet avatar jbblanchet commented on July 29, 2024 1

Closing because not an issue AND not related to gulp-jasmine. Stack overflow would be a much better option for asking such a question.

I can still say that if you look at the source code, there's a well identified section of code that clears the cache. Not sure if that's your problem, but it's as good a place as any to start.

from gulp-jasmine.

jbblanchet avatar jbblanchet commented on July 29, 2024 1

Good news is I'm able to reproduce your problem. Bad news is, I'm not familiar with the helpers and their usage. I understand what's happening, but I don't understand the fix yet.

When we load the config, the helper files are identified correctly. When jasmine is executed, it calls the loadHelpers method that requires each helper file. Since the node require mechanism is used, these files are cached. Every other require will simply use the cache, and the file will not be run again.

When the helper is required for the first time, you attach some methods to the jasmine instance. When your tests are run again, we use a new jasmine instance, and since the files have been cached, they are not executed again.

We normally clear the cache for every spec files and its children since they are loaded through gulp. We do not do that with helper files. The most obvious solution would be to clear the files in gulp-jasmine, but that would imply either reading the config file ourselves, or accessing the lists of helpers file and clearing them from the cache just before we run the execute method. My favorite method would be for jasmine to clear the cached files itself, but I'm not sure if they're interested in such a solution.

@sindresorhus @amavisca what do you think?

from gulp-jasmine.

mrozbarry avatar mrozbarry commented on July 29, 2024

Yes, the cache is cleared, but gulp-jasmine does not reload my helpers. This is certainly an issue with gulp-jasmine, unless I misunderstand the scope of this repo.

from gulp-jasmine.

jbblanchet avatar jbblanchet commented on July 29, 2024

I'm not sure I understand what you're doing. Are you using gulp-jasmine to run your tests, or are you using jasmine directly through the shell?

from gulp-jasmine.

mrozbarry avatar mrozbarry commented on July 29, 2024

I have tried both. I would prefer using gulp-jasmine, but when I run it in a watch task, the first time it detects a change, jasmine runs as expected - the second time, it runs but fails on all tests that use any helper libraries I'm loading in (ie jasmine-matchers, and other similar tools). These are installed as node_modules, which I'm under the impression is being cleared in the cache delete, so it means either jasmine doesn't know to re-require the helpers, or gulp-jasmine isn't reloading those.

from gulp-jasmine.

jbblanchet avatar jbblanchet commented on July 29, 2024

OK, sorry I misunderstood your problem. I'll reopen the issue. Do you have a simplified code sample of a test file so I can try to reproduce your issue?

from gulp-jasmine.

mrozbarry avatar mrozbarry commented on July 29, 2024

Sure

gulpfile.js

var coffee, gulp, gutil, jasmine, rm, watch;

gulp = require('gulp');
jasmine = require('gulp-jasmine');
watch = require('gulp-watch');
coffee = require('gulp-coffee');
gutil = require('gulp-util');
rm = require('gulp-rm');

gulp.task('test', ['jasmine']);

gulp.task('watch', function() {
  return watch(['app/**/*.coffee', 'spec/**/*.coffee'], function() {
    return gulp.run(['clean', 'compile', 'test']);
  });
});

gulp.task('clean', function() {
  return gulp.src(['./spec/full/**/*.js', './spec/factories/*.js', './spec/fixtures/*.js']).pipe(rm());
});

gulp.task('compile', ['clean'], function() {
  return gulp.src('./spec/**/*.coffee').pipe(coffee({
    bare: true
  })).on('error', gutil.log).pipe(gulp.dest('./spec/'));
});

gulp.task('jasmine', ['compile'], function() {
  return gulp.src('./spec/**/*.spec.js').pipe(jasmine({
    config: require('./spec/support/jasmine.json')
  }));
});

spec/support/jasmine.json

{
  "spec_dir": "spec",
  "spec_files": [
    "**/*.spec.js"
  ],
  "helpers": [
    "helpers/**/*.js"
  ]
}

Running gulp test works perfectly. Running gulp watch seems to run fine; I can trigger the test task when I save a file as expected, but when I trigger the task by saving a second time, I get a ton of errors saying the methods the helpers install are no longer available.

My tests are all written in coffeescript, and they are compiled into javascript, and the fact that gulp test works every time tells me this isn't the issue, so I just wanted to clear that off the table.

from gulp-jasmine.

jbblanchet avatar jbblanchet commented on July 29, 2024

Submitted a pull request, @mrozbarry if you could try it to confirm it fixes your issue it would be appreciated.

from gulp-jasmine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.