Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Fixed require() leak spotted by [guillermo]

Tj Holowaychukf38bfd59a54a
diff --git a/.gitignore b/.gitignore
index fbb64d6a..4154cb7f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
node_modules
*.sock
testing
+_mocha.js
diff --git a/Makefile b/Makefile
index 4c3da634..49c30016 100644
--- a/Makefile
+++ b/Makefile
@@ -11,7 +11,7 @@ mocha.css: test/browser/style.css
mocha.js: $(SRC)
@node support/compile $^
- @cat support/tail.js >> mocha.js
+ @cat support/head.js _mocha.js support/{tail,foot}.js > mocha.js
clean:
rm -f mocha.{js,css}
diff --git a/mocha.js b/mocha.js
index 27b6f812..ba7029f7 100644
--- a/mocha.js
+++ b/mocha.js
@@ -1,3 +1,5 @@
+;(function(){
+
// CommonJS require()
@@ -2528,3 +2530,4 @@ mocha = require('mocha');
return runner.run();
};
})();
+})();
\ No newline at end of file
diff --git a/support/compile.js b/support/compile.js
index 74c3128f..66161311 100644
--- a/support/compile.js
+++ b/support/compile.js
@@ -80,7 +80,7 @@ function compile() {
buf += js;
buf += '\n}); // module: ' + file + '\n';
});
- fs.writeFile('mocha.js', buf, function(err){
+ fs.writeFile('_mocha.js', buf, function(err){
if (err) throw err;
console.log(' \033[90m create : \033[0m\033[36m%s\033[0m', 'mocha.js');
console.log();
diff --git a/support/foot.js b/support/foot.js
new file mode 100644
index 00000000..158693a0
--- /dev/null
+++ b/support/foot.js
@@ -0,0 +1 @@
+})();
\ No newline at end of file
diff --git a/support/head.js b/support/head.js
new file mode 100644
index 00000000..aad8ad25
--- /dev/null
+++ b/support/head.js
@@ -0,0 +1,2 @@
+;(function(){
+