Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Required modules don't get cleared from cache #24

Closed
demisx opened this issue Aug 23, 2014 · 3 comments
Closed

Required modules don't get cleared from cache #24

demisx opened this issue Aug 23, 2014 · 3 comments

Comments

@demisx
Copy link

demisx commented Aug 23, 2014

I have a simple module:

// in app/modules/session/app-token.js
var AppToken, config, uuid;
uuid = require('node-uuid');
config = require('../../config');

module.exports = AppToken = (function() {
  var generateSecureToken;

  function AppToken() {
    this.token = generateSecureToken();
    this.expires = config.get('appTokenExpires');
  }

  generateSecureToken = function() {
    console.log("---> Generating secure token...");
    return uuid.v4();
  };

  return AppToken;
})();

with a corresponding Jasmine unit test:

// in app/modules/session/app-token-spec.js
var AppToken;
AppToken = require('./app-token');

describe('AppToken', function() {
  return it("generates uuid version 4 token", function() {
    var appToken, regex;
    appToken = new AppToken();
    console.log("appToken: " + appToken.token);
    regex = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
    expect(appToken.token).toMatch(regex);
  });
});

The nodemon is restarted on a change to a *.js file and the 'unit' task is run.

// in gulfile.js
... ... ...
gulp.task('unit', function () {
  return gulp.src(['app/**/*-spec.js'])
    .pipe(using())
    .pipe(jasmine());
});

gulp.task('watch-unit', function() {
  gulp.watch('app/**/*-spec.js', ['unit']);
});

gulp.task('restart-node', function () {
  nodemon(
    {
      // verbose: true,
      script: 'app/app.js',
      watch: 'app/',
      ext: 'js',
      ignore: ['*-spec.*'],
      env: { 'NODE_ENV': 'development' }
    }
  )

  .on('change', ['unit'])
  .on('restart', function () {
    console.log('restarted!')
  });

gulp.task('watch', ['watch-coffee', 'watch-unit', 'restart-node']);
gulp.task('default', ['watch']);

The problem I am facing is that changes to the module app-token.js aren't picked when tests are run up unless I shutdown and restart gulp. My guess that the module is cached because of this
require line in the spec:

AppToken = require('./app-token');

If I require it this way, then everything works as expected:

requireUncached = require('require-uncached');
AppToken = requireUncached('./app-token');

What can be done, so the changes in the modules are automatically picked up? Thank you.

@qw3r
Copy link

qw3r commented Sep 2, 2014

+1

@navelpluisje
Copy link
Contributor

Last June I did a Pull request which would solve this issue.
Sindresorhus closed it without doing anything with it. You can take a look #21 or read an article about this issue on http://navelpluisje.nl/entry/fix-cache-problem-jasmine-tests-with-gulp.

I hope he will take another look at the pull request and add the mod anyway.

@sindresorhus
Copy link
Owner

Fixed in #21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants