Skip to content

Instantly share code, notes, and snippets.

@konobi
Created July 28, 2013 03:01
Show Gist options
  • Save konobi/6097192 to your computer and use it in GitHub Desktop.
Save konobi/6097192 to your computer and use it in GitHub Desktop.
update to node-mocked to reflect reality better... uses a kinda hacky method, but should work.
diff --git a/lib/index.js b/lib/index.js
index e3fde1b..5dd58ae 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -22,8 +22,15 @@ module = module.exports = function (mock_path, libs){
var new_path = path;
var foo = libs.filter(function(libname){
- // XXX - this check may not be sufficient =0(
- return path.match(new RegExp(libname+'$'));
+ // NB - We need a lookbehind assertion here, which JS
+ // doesn't support, but we can fake using reversed
+ // strings and lookahead... yes it's a mindwarp
+ var tmp_path = path.reverse();
+ var tmp_libname = libname.reverse();
+
+ // In proper Regexp this would map to:
+ // '(?<=(?:^|/))' + libname + '$'
+ return tmp_path.match(new RegExp('^' + tmp_libname + '(?=(?:/|$)');
});
if(foo.length > 0) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment