Skip to content

armgit / mocha

Public Imported from GitHub
0

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

move query-string parser to utils.js

TJ Holowaychuk98323fb5932f
diff --git a/lib/utils.js b/lib/utils.js
index 2563adea..bc2f6bed 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -231,6 +231,25 @@ exports.trim = function(str){
return str.replace(/^\s+|\s+$/g, '');
};
+/**
+ * Parse the given `qs`.
+ *
+ * @param {String} qs
+ * @return {Object}
+ * @api private
+ */
+
+exports.parseQuery = function(qs){
+ return exports.reduce(qs.replace('?', '').split('&'), function(obj, pair){
+ var i = pair.indexOf('=')
+ , key = pair.slice(0, i)
+ , val = pair.slice(++i);
+
+ obj[key] = decodeURIComponent(val);
+ return obj;
+ }, {});
+};
+
/**
* Highlight the given string of `js`.
*
diff --git a/support/tail.js b/support/tail.js
index 842e92e6..9a359ef3 100644
--- a/support/tail.js
+++ b/support/tail.js
@@ -70,21 +70,6 @@ process.on = function(e, fn){
var Mocha = window.Mocha = require('mocha'),
mocha = window.mocha = new Mocha({ reporter: 'html' });
- /**
- * Parse the given `qs`.
- */
-
- function parse(qs) {
- return Mocha.utils.reduce(qs.replace('?', '').split('&'), function(obj, pair){
- var i = pair.indexOf('=')
- , key = pair.slice(0, i)
- , val = pair.slice(++i);
-
- obj[key] = decodeURIComponent(val);
- return obj;
- }, {});
- }
-
/**
* Override ui to ensure that the ui functions are initialized.
* Normally this would happen in Mocha.prototype.loadFiles.
@@ -115,7 +100,7 @@ process.on = function(e, fn){
options.globals = options.globals || [];
options.globals.push('location');
- var query = parse(window.location.search || "");
+ var query = Mocha.utils.parseQuery(window.location.search || "");
if (query.grep) this.grep(query.grep);
return Mocha.prototype.run.call(this, function () {