javascript - Gulp, Mocha, Watch Not Reloading My Source Files -


i attempting gulp working automate unit testing. have following gulp file.

var gulp = require('gulp'),     mocha = require('gulp-mocha');  gulp.task('unit', function() {     return gulp.src('test/unit/**/*.js')         .pipe(mocha({ reporter: 'spec' }))         .on('error', handleerror); });  gulp.task('watch', function() {     gulp.watch(['src/**/*.js', 'test/unit/**/*.js'], ['unit']); });  gulp.task('test', ['unit', 'watch']); 

when run 'gulp unit', tests run fine.

when run 'gulp test', tests run, , appears 'watch' working. if make change 1 of test files, tests rerun correctly, taking account changes made in test file.

if make changes source files, tests re-run, not run against updated version of source file.

my thought somehow, source file being cached, cannot find others seem have had issue or find solution.

thanks helping gulp/node/mocha newbie!

i had same issue found fix,

the issue require in nodejs caching src files when running tests via watch

i used following function in test file invalidate cache of src file, in replace of require.

apparently doing can dangerous, please see link @ bottom of post more information. development use ;)

coffeescript - module-test.coffee

nocache = (module) ->     delete require.cache[require.resolve(module)]     return require(module)  module = nocache("../module") describe "module test suite", () ->     newmodule = new module();     ... 

javascript - module-test.js

var module, nocache; nocache = function(module) {     delete require.cache[require.resolve(module)];     return require(module); }; module = nocache("../src/module");  describe("module test suite", function () {     newmodule = new module();     ... 

see here more information: node.js require() cache - possible invalidate?


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -