diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ec79ee5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# editorconfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.js] +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false diff --git a/lib/server.js b/lib/server.js index afcd3c4..9b45604 100644 --- a/lib/server.js +++ b/lib/server.js @@ -322,9 +322,13 @@ var SolidusServer = function( options ){ // updates the source of a preprocessor this.updatePreprocessor = function( preprocessor_path ){ + var preprocessor_paths = _.values(preprocessors).map(function (preprocessor) { + return preprocessor.path + }); - delete require.cache[require.resolve(preprocessor_path)]; - + _.each(preprocessor_paths, function ( path ){ + delete require.cache[path]; + }); }; // removes an existing preprocessor object diff --git a/test/solidus.js b/test/solidus.js index 1f1b006..dbc2645 100644 --- a/test/solidus.js +++ b/test/solidus.js @@ -1042,18 +1042,33 @@ describe( 'Solidus', function(){ }, FILESYSTEM_DELAY ); }); - var test_preprocessor_contents_2 = 'module.exports=function(context){context.test2 = true;return context;};'; + var parent_preprocessor_contents = 'var child = require("./child");module.exports=function(context){context.test = child();return context;};'; + var child_preprocessor_contents = 'module.exports=function(){return "ok";};'; + var child_preprocessor_contents_2 = 'module.exports=function(){return "okok";};'; - it( 'Updates preprocessors when their files change', function( done ){ + it( 'Invalidates all cached preprocessor modules on a change to any of them', function( done ){ + this.timeout(FILESYSTEM_DELAY * 2.5); var s_request = request( solidus_server.router ); - fs.writeFileSync( 'preprocessors/test.js', test_preprocessor_contents_2, DEFAULT_ENCODING ); + fs.writeFileSync( 'preprocessors/test.js', parent_preprocessor_contents, DEFAULT_ENCODING ); + fs.writeFileSync( 'preprocessors/child.js', child_preprocessor_contents, DEFAULT_ENCODING ); setTimeout( function(){ s_request.get('/test.json') .expect( 200 ) .end( function( err, res ){ if( err ) throw err; - assert( res.body.test2 ); - done(); + assert( res.body.test === 'ok' ); + + fs.writeFileSync( 'preprocessors/child.js', child_preprocessor_contents_2, DEFAULT_ENCODING ); + + setTimeout( function(){ + s_request.get('/test.json') + .expect( 200 ) + .end( function( err, res ){ + if( err ) throw err; + assert( res.body.test === 'okok' ); + done(); + }); + }, FILESYSTEM_DELAY ); }); }, FILESYSTEM_DELAY ); });