[Pkg-javascript-commits] [node-mocks-http] 47/296: Cleans up mockRequest.js and mockResponse.js by moving the returns and exports to the bottom.

Thorsten Alteholz alteholz at moszumanska.debian.org
Mon Feb 8 18:13:19 UTC 2016


This is an automated email from the git hooks/post-receive script.

alteholz pushed a commit to branch master
in repository node-mocks-http.

commit a783d38c7608ef5e759a4020e4a82d0a1403959f
Author: Alan James <alanjames1987 at gmail.com>
Date:   Tue Sep 23 21:58:49 2014 -0400

    Cleans up mockRequest.js and mockResponse.js by moving the returns and exports to the bottom.
---
 lib/mockRequest.js  | 16 +++++++--------
 lib/mockResponse.js | 56 ++++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 55 insertions(+), 17 deletions(-)

diff --git a/lib/mockRequest.js b/lib/mockRequest.js
index e0f20e6..f725b9a 100644
--- a/lib/mockRequest.js
+++ b/lib/mockRequest.js
@@ -28,13 +28,13 @@
  *   body   - The body values, , see <mockRequest._setBody>
  */
 
-exports.createRequest = function(options) {
+function createRequest(options) {
 
     if (!options) {
         options = {};
     }
 
-    return {
+    var mockRequest = {
 
         method: (options.method) ? options.method : 'GET',
         url: (options.url) ? options.url : '',
@@ -57,7 +57,6 @@ exports.createRequest = function(options) {
          *   key - The key. For instance, 'bob' would be accessed: request.params.bob
          *   value - The value to return when accessed.
          */
-
         _setParameter: function(key, value) {
             this.params[key] = value;
         },
@@ -114,7 +113,6 @@ exports.createRequest = function(options) {
          *
          * Note: We don't validate the string. We just return it.
          */
-
         _setMethod: function(method) {
             this.method = method;
         },
@@ -132,7 +130,6 @@ exports.createRequest = function(options) {
          * Note: We don't validate the string. We just return it. Typically, these
          * do not include hostname, port or that part of the URL.
          */
-
         _setURL: function(url) {
             this.url = url;
         },
@@ -157,7 +154,6 @@ exports.createRequest = function(options) {
          * If the client is expecting a JSON object through a REST interface, then
          * this object could be anything.
          */
-
         _setBody: function(body) {
             this.body = body;
         },
@@ -174,10 +170,14 @@ exports.createRequest = function(options) {
          *   key - The key. For instance, 'bob' would be accessed: request.params.bob
          *   value - The value to return when accessed.
          */
-
         _addBody: function(key, value) {
             this.body[key] = value;
         }
 
     };
-};
\ No newline at end of file
+
+    return mockRequest;
+
+}
+
+module.exports.createRequest = createRequest;
\ No newline at end of file
diff --git a/lib/mockResponse.js b/lib/mockResponse.js
index 4183129..76d5abc 100644
--- a/lib/mockResponse.js
+++ b/lib/mockResponse.js
@@ -10,7 +10,6 @@
  * @author Howard Abrams <howard.abrams at gmail.com>
  */
 
-
 /**
  * Function: createResponse
  *
@@ -29,7 +28,7 @@
 var WritableStream = require('./mockWritableStream');
 var EventEmitter = require('./mockEventEmitter');
 
-exports.createResponse = function(options) {
+function createResponse(options) {
 
     if (!options) {
         options = {};
@@ -47,17 +46,19 @@ exports.createResponse = function(options) {
     var writableStream = options.writableStream ? new options.writableStream() : new WritableStream();
     var eventEmitter = options.eventEmitter ? new options.eventEmitter() : new EventEmitter();
 
-    return {
+    var mockResponse = {
 
         statusCode: -1,
 
         cookies: {},
 
         cookie: function(name, value, options) {
+
             this.cookies[name] = {
                 value: value,
                 options: options
             };
+
         },
 
         clearCookie: function(name) {
@@ -81,6 +82,7 @@ exports.createResponse = function(options) {
          *               the HTTP headers.
          */
         writeHead: function(statusCode, phrase, headers) {
+
             if (_endCalled) {
                 throw 'The end() method has already been called.';
             }
@@ -94,6 +96,7 @@ exports.createResponse = function(options) {
             } else {
                 _headers = phrase;
             }
+
         },
 
         /**
@@ -103,7 +106,9 @@ exports.createResponse = function(options) {
          * @param data The data to return. Must be a string.
          */
         send: function(a, b, c) {
+
             var _self = this;
+
             var _formatData = function(a) {
                 if (typeof a === 'object') {
                     if (a.statusCode) {
@@ -157,6 +162,7 @@ exports.createResponse = function(options) {
 
             this.emit('send');
             this.emit('end');
+
         },
 
         /**
@@ -164,6 +170,7 @@ exports.createResponse = function(options) {
          *  to the client.  Should not be called multiple times.
          */
         json: function(a, b) {
+
             this.setHeader('Content-Type', 'application/json');
 
             switch (arguments.length) {
@@ -185,6 +192,7 @@ exports.createResponse = function(options) {
                 default:
                     break;
             }
+
         },
 
         /**
@@ -200,10 +208,13 @@ exports.createResponse = function(options) {
          */
 
         write: function(data, encoding) {
+
             _data += data;
+
             if (encoding) {
                 _encoding = encoding;
             }
+
         },
 
         /**
@@ -219,14 +230,19 @@ exports.createResponse = function(options) {
          *  encoding - Optional encoding value.
          */
         end: function(data, encoding) {
+
             _endCalled = true;
+
             if (data) {
                 _data += data;
             }
+
             if (encoding) {
                 _encoding = encoding;
             }
+
             this.emit('end');
+
         },
 
         /**
@@ -236,11 +252,13 @@ exports.createResponse = function(options) {
          *   the amount of passed parameters.
          */
         header: function(name, value) {
+
             if (typeof value !== 'undefined') {
                 return this.setHeader(name, value);
             } else {
                 return this.getHeader(name);
             }
+
         },
 
         /**
@@ -255,9 +273,11 @@ exports.createResponse = function(options) {
         /**
          * Function: get
          *
-         *   An alias of getHeader.
+         *   An copy of getHeader.
          */
-        get: this.getHeader,
+        get: function(name) {
+            return _headers[name];
+        },
 
         /**
          * Function: setHeader
@@ -272,9 +292,12 @@ exports.createResponse = function(options) {
         /**
          * Function: set
          *
-         *   An alias of setHeader.
+         *   An copy of setHeader.
          */
-        set: this.setHeader,
+        set: function(name, value) {
+            _headers[name] = value;
+            return value;
+        },
 
         /**
          * Function: removeHeader
@@ -304,6 +327,7 @@ exports.createResponse = function(options) {
          *     Redirect to a url with response code
          */
         redirect: function(a, b) {
+
             switch (arguments.length) {
                 case 1:
                     _redirectUrl = a;
@@ -319,6 +343,7 @@ exports.createResponse = function(options) {
                 default:
                     break;
             }
+
         },
 
         /**
@@ -328,7 +353,9 @@ exports.createResponse = function(options) {
          *     rendered string.
          */
         render: function(a, b, c) {
+
             _renderView = a;
+
             switch (arguments.length) {
                 case 2:
                     break;
@@ -343,6 +370,7 @@ exports.createResponse = function(options) {
 
             this.emit('render');
             this.emit('end');
+
         },
 
         writable: function() {
@@ -406,7 +434,6 @@ exports.createResponse = function(options) {
             return _endCalled;
         },
 
-
         /**
          * Function: _getHeaders
          *
@@ -456,10 +483,13 @@ exports.createResponse = function(options) {
          *   False if the encoding wasn't set and wasn't set to "utf8".
          */
         _isUTF8: function() {
+
             if (!_encoding) {
                 return false;
             }
+
             return (_encoding === 'utf8');
+
         },
 
         /**
@@ -475,10 +505,13 @@ exports.createResponse = function(options) {
          *   set. Otherwise, it compares it.
          */
         _isDataLengthValid: function() {
+
             if (_headers['Content-Length']) {
                 return (_headers['Content-Length'].toString() === _data.length.toString());
             }
+
             return true;
+
         },
 
         /**
@@ -521,4 +554,9 @@ exports.createResponse = function(options) {
         }
 
     };
-};
\ No newline at end of file
+
+    return mockResponse;
+
+}
+
+module.exports.createResponse = createResponse;
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-mocks-http.git



More information about the Pkg-javascript-commits mailing list