You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pm...@apache.org on 2014/08/30 20:42:39 UTC
[06/14] pre-compile CoffeeScript files in server
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/Makefile
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/Makefile b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/Makefile
deleted file mode 100644
index 8945872..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
-SHELL := /bin/bash
-
-test:
- @./test/run.js
-
-build: npm test
-
-npm:
- npm install .
-
-clean:
- rm test/tmp/*
-
-.PHONY: test clean build
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/Readme.md
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/Readme.md b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/Readme.md
index a5ca104..0f8cc61 100644
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/Readme.md
+++ b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/Readme.md
@@ -20,8 +20,299 @@ a large variety of clients and is considered production-ready.
* Graceful error handling
* Very high test coverage
+## Installation
+
+This is a low level package, and if you're using a high level framework such as Express, chances are it's already included in it. You can [read this discussion](http://stackoverflow.com/questions/11295554/how-to-disable-express-bodyparser-for-file-uploads-node-js) about how Formidable is integrated with Express.
+
+Via [npm](http://github.com/isaacs/npm):
+```
+npm install formidable@latest
+```
+Manually:
+```
+git clone git://github.com/felixge/node-formidable.git formidable
+vim my.js
+# var formidable = require('./formidable');
+```
+
+Note: Formidable requires [gently](http://github.com/felixge/node-gently) to run the unit tests, but you won't need it for just using the library.
+
+## Example
+
+Parse an incoming file upload.
+```javascript
+var formidable = require('formidable'),
+ http = require('http'),
+ util = require('util');
+
+http.createServer(function(req, res) {
+ if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
+ // parse a file upload
+ var form = new formidable.IncomingForm();
+
+ form.parse(req, function(err, fields, files) {
+ res.writeHead(200, {'content-type': 'text/plain'});
+ res.write('received upload:\n\n');
+ res.end(util.inspect({fields: fields, files: files}));
+ });
+
+ return;
+ }
+
+ // show a file upload form
+ res.writeHead(200, {'content-type': 'text/html'});
+ res.end(
+ '<form action="/upload" enctype="multipart/form-data" method="post">'+
+ '<input type="text" name="title"><br>'+
+ '<input type="file" name="upload" multiple="multiple"><br>'+
+ '<input type="submit" value="Upload">'+
+ '</form>'
+ );
+}).listen(8080);
+```
+## API
+
+### Formidable.IncomingForm
+```javascript
+var form = new formidable.IncomingForm()
+```
+Creates a new incoming form.
+
+```javascript
+form.encoding = 'utf-8';
+```
+Sets encoding for incoming form fields.
+
+```javascript
+form.uploadDir = "/my/dir";
+```
+Sets the directory for placing file uploads in. You can move them later on using
+`fs.rename()`. The default is `os.tmpDir()`.
+
+```javascript
+form.keepExtensions = false;
+```
+If you want the files written to `form.uploadDir` to include the extensions of the original files, set this property to `true`.
+
+```javascript
+form.type
+```
+Either 'multipart' or 'urlencoded' depending on the incoming request.
+
+```javascript
+form.maxFieldsSize = 2 * 1024 * 1024;
+```
+Limits the amount of memory a field (not file) can allocate in bytes.
+If this value is exceeded, an `'error'` event is emitted. The default
+size is 2MB.
+
+```javascript
+form.maxFields = 1000;
+```
+Limits the number of fields that the querystring parser will decode. Defaults
+to 1000 (0 for unlimited).
+
+```javascript
+form.hash = false;
+```
+If you want checksums calculated for incoming files, set this to either `'sha1'` or `'md5'`.
+
+```javascript
+form.multiples = false;
+```
+If this option is enabled, when you call `form.parse`, the `files` argument will contain arrays of files for inputs which submit multiple files using the HTML5 `multiple` attribute.
+
+```javascript
+form.bytesReceived
+```
+The amount of bytes received for this form so far.
+
+```javascript
+form.bytesExpected
+```
+The expected number of bytes in this form.
+
+```javascript
+form.parse(request, [cb]);
+```
+Parses an incoming node.js `request` containing form data. If `cb` is provided, all fields and files are collected and passed to the callback:
+
+
+```javascript
+form.parse(req, function(err, fields, files) {
+ // ...
+});
+
+form.onPart(part);
+```
+You may overwrite this method if you are interested in directly accessing the multipart stream. Doing so will disable any `'field'` / `'file'` events processing which would occur otherwise, making you fully responsible for handling the processing.
+
+```javascript
+form.onPart = function(part) {
+ part.addListener('data', function() {
+ // ...
+ });
+}
+```
+If you want to use formidable to only handle certain parts for you, you can do so:
+```javascript
+form.onPart = function(part) {
+ if (!part.filename) {
+ // let formidable handle all non-file parts
+ form.handlePart(part);
+ }
+}
+```
+Check the code in this method for further inspiration.
+
+
+### Formidable.File
+```javascript
+file.size = 0
+```
+The size of the uploaded file in bytes. If the file is still being uploaded (see `'fileBegin'` event), this property says how many bytes of the file have been written to disk yet.
+```javascript
+file.path = null
+```
+The path this file is being written to. You can modify this in the `'fileBegin'` event in
+case you are unhappy with the way formidable generates a temporary path for your files.
+```javascript
+file.name = null
+```
+The name this file had according to the uploading client.
+```javascript
+file.type = null
+```
+The mime type of this file, according to the uploading client.
+```javascript
+file.lastModifiedDate = null
+```
+A date object (or `null`) containing the time this file was last written to. Mostly
+here for compatibility with the [W3C File API Draft](http://dev.w3.org/2006/webapi/FileAPI/).
+```javascript
+file.hash = null
+```
+If hash calculation was set, you can read the hex digest out of this var.
+
+#### Formidable.File#toJSON()
+
+ This method returns a JSON-representation of the file, allowing you to
+ `JSON.stringify()` the file which is useful for logging and responding
+ to requests.
+
+### Events
+
+
+#### 'progress'
+```javascript
+form.on('progress', function(bytesReceived, bytesExpected) {
+});
+```
+Emitted after each incoming chunk of data that has been parsed. Can be used to roll your own progress bar.
+
+
+
+#### 'field'
+```javascript
+form.on('field', function(name, value) {
+});
+```
+
+#### 'fileBegin'
+
+Emitted whenever a field / value pair has been received.
+```javascript
+form.on('fileBegin', function(name, file) {
+});
+```
+
+#### 'file'
+
+Emitted whenever a new file is detected in the upload stream. Use this even if
+you want to stream the file to somewhere else while buffering the upload on
+the file system.
+
+Emitted whenever a field / file pair has been received. `file` is an instance of `File`.
+```javascript
+form.on('file', function(name, file) {
+});
+```
+
+#### 'error'
+
+Emitted when there is an error processing the incoming form. A request that experiences an error is automatically paused, you will have to manually call `request.resume()` if you want the request to continue firing `'data'` events.
+```javascript
+form.on('error', function(err) {
+});
+```
+
+#### 'aborted'
+
+
+Emitted when the request was aborted by the user. Right now this can be due to a 'timeout' or 'close' event on the socket. In the future there will be a separate 'timeout' event (needs a change in the node core).
+```javascript
+form.on('aborted', function() {
+});
+```
+
+##### 'end'
+```javascript
+form.on('end', function() {
+});
+```
+Emitted when the entire request has been received, and all contained files have finished flushing to disk. This is a great place for you to send your response.
+
+
+
## Changelog
+### v1.0.14
+
+* Add failing hash tests. (Ben Trask)
+* Enable hash calculation again (Eugene Girshov)
+* Test for immediate data events (Tim Smart)
+* Re-arrange IncomingForm#parse (Tim Smart)
+
+### v1.0.13
+
+* Only update hash if update method exists (Sven Lito)
+* According to travis v0.10 needs to go quoted (Sven Lito)
+* Bumping build node versions (Sven Lito)
+* Additional fix for empty requests (Eugene Girshov)
+* Change the default to 1000, to match the new Node behaviour. (OrangeDog)
+* Add ability to control maxKeys in the querystring parser. (OrangeDog)
+* Adjust test case to work with node 0.9.x (Eugene Girshov)
+* Update package.json (Sven Lito)
+* Path adjustment according to eb4468b (Markus Ast)
+
+### v1.0.12
+
+* Emit error on aborted connections (Eugene Girshov)
+* Add support for empty requests (Eugene Girshov)
+* Fix name/filename handling in Content-Disposition (jesperp)
+* Tolerate malformed closing boundary in multipart (Eugene Girshov)
+* Ignore preamble in multipart messages (Eugene Girshov)
+* Add support for application/json (Mike Frey, Carlos Rodriguez)
+* Add support for Base64 encoding (Elmer Bulthuis)
+* Add File#toJSON (TJ Holowaychuk)
+* Remove support for Node.js 0.4 & 0.6 (Andrew Kelley)
+* Documentation improvements (Sven Lito, Andre Azevedo)
+* Add support for application/octet-stream (Ion Lupascu, Chris Scribner)
+* Use os.tmpDir() to get tmp directory (Andrew Kelley)
+* Improve package.json (Andrew Kelley, Sven Lito)
+* Fix benchmark script (Andrew Kelley)
+* Fix scope issue in incoming_forms (Sven Lito)
+* Fix file handle leak on error (OrangeDog)
+
+### v1.0.11
+
+* Calculate checksums for incoming files (sreuter)
+* Add definition parameters to "IncomingForm" as an argument (Math-)
+
+### v1.0.10
+
+* Make parts to be proper Streams (Matt Robenolt)
+
### v1.0.9
* Emit progress when content length header parsed (Tim Koschützki)
@@ -121,183 +412,6 @@ These releases were done before starting to maintain the above Changelog:
* [v0.9.0](https://github.com/felixge/node-formidable/compare/v0.8.0...v0.9.0)
* [v0.1.0](https://github.com/felixge/node-formidable/commits/v0.1.0)
-## Installation
-
-Via [npm](http://github.com/isaacs/npm):
-
- npm install formidable@latest
-
-Manually:
-
- git clone git://github.com/felixge/node-formidable.git formidable
- vim my.js
- # var formidable = require('./formidable');
-
-Note: Formidable requires [gently](http://github.com/felixge/node-gently) to run the unit tests, but you won't need it for just using the library.
-
-## Example
-
-Parse an incoming file upload.
-
- var formidable = require('formidable'),
- http = require('http'),
-
- util = require('util');
-
- http.createServer(function(req, res) {
- if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
- // parse a file upload
- var form = new formidable.IncomingForm();
- form.parse(req, function(err, fields, files) {
- res.writeHead(200, {'content-type': 'text/plain'});
- res.write('received upload:\n\n');
- res.end(util.inspect({fields: fields, files: files}));
- });
- return;
- }
-
- // show a file upload form
- res.writeHead(200, {'content-type': 'text/html'});
- res.end(
- '<form action="/upload" enctype="multipart/form-data" method="post">'+
- '<input type="text" name="title"><br>'+
- '<input type="file" name="upload" multiple="multiple"><br>'+
- '<input type="submit" value="Upload">'+
- '</form>'
- );
- }).listen(80);
-
-## API
-
-### formidable.IncomingForm
-
-__new formidable.IncomingForm()__
-
-Creates a new incoming form.
-
-__incomingForm.encoding = 'utf-8'__
-
-The encoding to use for incoming form fields.
-
-__incomingForm.uploadDir = process.env.TMP || '/tmp' || process.cwd()__
-
-The directory for placing file uploads in. You can move them later on using
-`fs.rename()`. The default directory is picked at module load time depending on
-the first existing directory from those listed above.
-
-__incomingForm.keepExtensions = false__
-
-If you want the files written to `incomingForm.uploadDir` to include the extensions of the original files, set this property to `true`.
-
-__incomingForm.type__
-
-Either 'multipart' or 'urlencoded' depending on the incoming request.
-
-__incomingForm.maxFieldsSize = 2 * 1024 * 1024__
-
-Limits the amount of memory a field (not file) can allocate in bytes.
-If this value is exceeded, an `'error'` event is emitted. The default
-size is 2MB.
-
-__incomingForm.hash = false__
-
-If you want checksums calculated for incoming files, set this to either `'sha1'` or `'md5'`.
-
-__incomingForm.bytesReceived__
-
-The amount of bytes received for this form so far.
-
-__incomingForm.bytesExpected__
-
-The expected number of bytes in this form.
-
-__incomingForm.parse(request, [cb])__
-
-Parses an incoming node.js `request` containing form data. If `cb` is provided, all fields an files are collected and passed to the callback:
-
- incomingForm.parse(req, function(err, fields, files) {
- // ...
- });
-
-__incomingForm.onPart(part)__
-
-You may overwrite this method if you are interested in directly accessing the multipart stream. Doing so will disable any `'field'` / `'file'` events processing which would occur otherwise, making you fully responsible for handling the processing.
-
- incomingForm.onPart = function(part) {
- part.addListener('data', function() {
- // ...
- });
- }
-
-If you want to use formidable to only handle certain parts for you, you can do so:
-
- incomingForm.onPart = function(part) {
- if (!part.filename) {
- // let formidable handle all non-file parts
- incomingForm.handlePart(part);
- }
- }
-
-Check the code in this method for further inspiration.
-
-__Event: 'progress' (bytesReceived, bytesExpected)__
-
-Emitted after each incoming chunk of data that has been parsed. Can be used to roll your own progress bar.
-
-__Event: 'field' (name, value)__
-
-Emitted whenever a field / value pair has been received.
-
-__Event: 'fileBegin' (name, file)__
-
-Emitted whenever a new file is detected in the upload stream. Use this even if
-you want to stream the file to somewhere else while buffering the upload on
-the file system.
-
-__Event: 'file' (name, file)__
-
-Emitted whenever a field / file pair has been received. `file` is an instance of `File`.
-
-__Event: 'error' (err)__
-
-Emitted when there is an error processing the incoming form. A request that experiences an error is automatically paused, you will have to manually call `request.resume()` if you want the request to continue firing `'data'` events.
-
-__Event: 'aborted'__
-
-Emitted when the request was aborted by the user. Right now this can be due to a 'timeout' or 'close' event on the socket. In the future there will be a separate 'timeout' event (needs a change in the node core).
-
-__Event: 'end' ()__
-
-Emitted when the entire request has been received, and all contained files have finished flushing to disk. This is a great place for you to send your response.
-
-### formidable.File
-
-__file.size = 0__
-
-The size of the uploaded file in bytes. If the file is still being uploaded (see `'fileBegin'` event), this property says how many bytes of the file have been written to disk yet.
-
-__file.path = null__
-
-The path this file is being written to. You can modify this in the `'fileBegin'` event in
-case you are unhappy with the way formidable generates a temporary path for your files.
-
-__file.name = null__
-
-The name this file had according to the uploading client.
-
-__file.type = null__
-
-The mime type of this file, according to the uploading client.
-
-__file.lastModifiedDate = null__
-
-A date object (or `null`) containing the time this file was last written to. Mostly
-here for compatibility with the [W3C File API Draft](http://dev.w3.org/2006/webapi/FileAPI/).
-
-__file.hash = null__
-
-If hash calculation was set, you can read the hex digest out of this var.
-
## License
Formidable is licensed under the MIT license.
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/TODO
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/TODO b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/TODO
deleted file mode 100644
index e1107f2..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/TODO
+++ /dev/null
@@ -1,3 +0,0 @@
-- Better bufferMaxSize handling approach
-- Add tests for JSON parser pull request and merge it
-- Implement QuerystringParser the same way as MultipartParser
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/benchmark/bench-multipart-parser.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/benchmark/bench-multipart-parser.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/benchmark/bench-multipart-parser.js
deleted file mode 100644
index bff41f1..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/benchmark/bench-multipart-parser.js
+++ /dev/null
@@ -1,70 +0,0 @@
-require('../test/common');
-var multipartParser = require('../lib/multipart_parser'),
- MultipartParser = multipartParser.MultipartParser,
- parser = new MultipartParser(),
- Buffer = require('buffer').Buffer,
- boundary = '-----------------------------168072824752491622650073',
- mb = 100,
- buffer = createMultipartBuffer(boundary, mb * 1024 * 1024),
- callbacks =
- { partBegin: -1,
- partEnd: -1,
- headerField: -1,
- headerValue: -1,
- partData: -1,
- end: -1,
- };
-
-
-parser.initWithBoundary(boundary);
-parser.onHeaderField = function() {
- callbacks.headerField++;
-};
-
-parser.onHeaderValue = function() {
- callbacks.headerValue++;
-};
-
-parser.onPartBegin = function() {
- callbacks.partBegin++;
-};
-
-parser.onPartData = function() {
- callbacks.partData++;
-};
-
-parser.onPartEnd = function() {
- callbacks.partEnd++;
-};
-
-parser.onEnd = function() {
- callbacks.end++;
-};
-
-var start = +new Date(),
- nparsed = parser.write(buffer),
- duration = +new Date - start,
- mbPerSec = (mb / (duration / 1000)).toFixed(2);
-
-console.log(mbPerSec+' mb/sec');
-
-assert.equal(nparsed, buffer.length);
-
-function createMultipartBuffer(boundary, size) {
- var head =
- '--'+boundary+'\r\n'
- + 'content-disposition: form-data; name="field1"\r\n'
- + '\r\n'
- , tail = '\r\n--'+boundary+'--\r\n'
- , buffer = new Buffer(size);
-
- buffer.write(head, 'ascii', 0);
- buffer.write(tail, 'ascii', buffer.length - tail.length);
- return buffer;
-}
-
-process.on('exit', function() {
- for (var k in callbacks) {
- assert.equal(0, callbacks[k], k+' count off by '+callbacks[k]);
- }
-});
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/example/post.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/example/post.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/example/post.js
deleted file mode 100644
index f6c15a6..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/example/post.js
+++ /dev/null
@@ -1,43 +0,0 @@
-require('../test/common');
-var http = require('http'),
- util = require('util'),
- formidable = require('formidable'),
- server;
-
-server = http.createServer(function(req, res) {
- if (req.url == '/') {
- res.writeHead(200, {'content-type': 'text/html'});
- res.end(
- '<form action="/post" method="post">'+
- '<input type="text" name="title"><br>'+
- '<input type="text" name="data[foo][]"><br>'+
- '<input type="submit" value="Submit">'+
- '</form>'
- );
- } else if (req.url == '/post') {
- var form = new formidable.IncomingForm(),
- fields = [];
-
- form
- .on('error', function(err) {
- res.writeHead(200, {'content-type': 'text/plain'});
- res.end('error:\n\n'+util.inspect(err));
- })
- .on('field', function(field, value) {
- console.log(field, value);
- fields.push([field, value]);
- })
- .on('end', function() {
- console.log('-> post done');
- res.writeHead(200, {'content-type': 'text/plain'});
- res.end('received fields:\n\n '+util.inspect(fields));
- });
- form.parse(req);
- } else {
- res.writeHead(404, {'content-type': 'text/plain'});
- res.end('404');
- }
-});
-server.listen(TEST_PORT);
-
-console.log('listening on http://localhost:'+TEST_PORT+'/');
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/example/upload.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/example/upload.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/example/upload.js
deleted file mode 100644
index 050cdd9..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/example/upload.js
+++ /dev/null
@@ -1,48 +0,0 @@
-require('../test/common');
-var http = require('http'),
- util = require('util'),
- formidable = require('formidable'),
- server;
-
-server = http.createServer(function(req, res) {
- if (req.url == '/') {
- res.writeHead(200, {'content-type': 'text/html'});
- res.end(
- '<form action="/upload" enctype="multipart/form-data" method="post">'+
- '<input type="text" name="title"><br>'+
- '<input type="file" name="upload" multiple="multiple"><br>'+
- '<input type="submit" value="Upload">'+
- '</form>'
- );
- } else if (req.url == '/upload') {
- var form = new formidable.IncomingForm(),
- files = [],
- fields = [];
-
- form.uploadDir = TEST_TMP;
-
- form
- .on('field', function(field, value) {
- console.log(field, value);
- fields.push([field, value]);
- })
- .on('file', function(field, file) {
- console.log(field, file);
- files.push([field, file]);
- })
- .on('end', function() {
- console.log('-> upload done');
- res.writeHead(200, {'content-type': 'text/plain'});
- res.write('received fields:\n\n '+util.inspect(fields));
- res.write('\n\n');
- res.end('received files:\n\n '+util.inspect(files));
- });
- form.parse(req);
- } else {
- res.writeHead(404, {'content-type': 'text/plain'});
- res.end('404');
- }
-});
-server.listen(TEST_PORT);
-
-console.log('listening on http://localhost:'+TEST_PORT+'/');
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/index.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/index.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/index.js
index be41032..4cc88b3 100644
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/index.js
+++ b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/index.js
@@ -1 +1 @@
-module.exports = require('./lib/formidable');
\ No newline at end of file
+module.exports = require('./lib');
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/file.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/file.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/file.js
index dad8d5f..e34c10e 100644
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/file.js
+++ b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/file.js
@@ -1,6 +1,6 @@
if (global.GENTLY) require = GENTLY.hijack(require);
-var util = require('./util'),
+var util = require('util'),
WriteStream = require('fs').WriteStream,
EventEmitter = require('events').EventEmitter,
crypto = require('crypto');
@@ -23,37 +23,36 @@ function File(properties) {
if(typeof this.hash === 'string') {
this.hash = crypto.createHash(properties.hash);
+ } else {
+ this.hash = null;
}
-
- this._backwardsCompatibility();
}
module.exports = File;
util.inherits(File, EventEmitter);
-// @todo Next release: Show error messages when accessing these
-File.prototype._backwardsCompatibility = function() {
- var self = this;
- this.__defineGetter__('length', function() {
- return self.size;
- });
- this.__defineGetter__('filename', function() {
- return self.name;
- });
- this.__defineGetter__('mime', function() {
- return self.type;
- });
-};
-
File.prototype.open = function() {
this._writeStream = new WriteStream(this.path);
};
+File.prototype.toJSON = function() {
+ return {
+ size: this.size,
+ path: this.path,
+ name: this.name,
+ type: this.type,
+ mtime: this.lastModifiedDate,
+ length: this.length,
+ filename: this.filename,
+ mime: this.mime
+ };
+};
+
File.prototype.write = function(buffer, cb) {
var self = this;
+ if (self.hash) {
+ self.hash.update(buffer);
+ }
this._writeStream.write(buffer, function() {
- if(self.hash) {
- self.hash.update(buffer);
- }
self.lastModifiedDate = new Date();
self.size += buffer.length;
self.emit('progress', self.size);
@@ -63,10 +62,10 @@ File.prototype.write = function(buffer, cb) {
File.prototype.end = function(cb) {
var self = this;
+ if (self.hash) {
+ self.hash = self.hash.digest('hex');
+ }
this._writeStream.end(function() {
- if(self.hash) {
- self.hash = self.hash.digest('hex');
- }
self.emit('end');
cb();
});
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js
index 060eac2..27b9aed 100644
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js
+++ b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/incoming_form.js
@@ -1,31 +1,36 @@
if (global.GENTLY) require = GENTLY.hijack(require);
var fs = require('fs');
-var util = require('./util'),
+var util = require('util'),
path = require('path'),
File = require('./file'),
MultipartParser = require('./multipart_parser').MultipartParser,
QuerystringParser = require('./querystring_parser').QuerystringParser,
+ OctetParser = require('./octet_parser').OctetParser,
+ JSONParser = require('./json_parser').JSONParser,
StringDecoder = require('string_decoder').StringDecoder,
EventEmitter = require('events').EventEmitter,
- Stream = require('stream').Stream;
+ Stream = require('stream').Stream,
+ os = require('os');
-function IncomingForm(opts) {
- if (!(this instanceof IncomingForm)) return new IncomingForm;
+function IncomingForm(opts) {
+ if (!(this instanceof IncomingForm)) return new IncomingForm(opts);
EventEmitter.call(this);
opts=opts||{};
-
+
this.error = null;
this.ended = false;
+ this.maxFields = opts.maxFields || 1000;
this.maxFieldsSize = opts.maxFieldsSize || 2 * 1024 * 1024;
this.keepExtensions = opts.keepExtensions || false;
- this.uploadDir = opts.uploadDir || IncomingForm.UPLOAD_DIR;
+ this.uploadDir = opts.uploadDir || os.tmpDir();
this.encoding = opts.encoding || 'utf-8';
this.headers = null;
this.type = null;
- this.hash = false;
+ this.hash = opts.hash || false;
+ this.multiples = opts.multiples || false;
this.bytesReceived = null;
this.bytesExpected = null;
@@ -33,24 +38,13 @@ function IncomingForm(opts) {
this._parser = null;
this._flushing = 0;
this._fieldsSize = 0;
-};
+ this.openedFiles = [];
+
+ return this;
+}
util.inherits(IncomingForm, EventEmitter);
exports.IncomingForm = IncomingForm;
-IncomingForm.UPLOAD_DIR = (function() {
- var dirs = [process.env.TMP, '/tmp', process.cwd()];
- for (var i = 0; i < dirs.length; i++) {
- var dir = dirs[i];
- var isDirectory = false;
-
- try {
- isDirectory = fs.statSync(dir).isDirectory();
- } catch (e) {}
-
- if (isDirectory) return dir;
- }
-})();
-
IncomingForm.prototype.parse = function(req, cb) {
this.pause = function() {
try {
@@ -81,8 +75,40 @@ IncomingForm.prototype.parse = function(req, cb) {
return true;
};
+ // Setup callback first, so we don't miss anything from data events emitted
+ // immediately.
+ if (cb) {
+ var fields = {}, files = {};
+ this
+ .on('field', function(name, value) {
+ fields[name] = value;
+ })
+ .on('file', function(name, file) {
+ if (this.multiples) {
+ if (files[name]) {
+ if (!Array.isArray(files[name])) {
+ files[name] = [files[name]];
+ }
+ files[name].push(file);
+ } else {
+ files[name] = file;
+ }
+ } else {
+ files[name] = file;
+ }
+ })
+ .on('error', function(err) {
+ cb(err, fields, files);
+ })
+ .on('end', function() {
+ cb(null, fields, files);
+ });
+ }
+
+ // Parse headers and setup the parser, ready to start listening for data.
this.writeHeaders(req.headers);
+ // Start listening for data.
var self = this;
req
.on('error', function(err) {
@@ -90,6 +116,7 @@ IncomingForm.prototype.parse = function(req, cb) {
})
.on('aborted', function() {
self.emit('aborted');
+ self._error(new Error('Request aborted'));
})
.on('data', function(buffer) {
self.write(buffer);
@@ -105,23 +132,6 @@ IncomingForm.prototype.parse = function(req, cb) {
}
});
- if (cb) {
- var fields = {}, files = {};
- this
- .on('field', function(name, value) {
- fields[name] = value;
- })
- .on('file', function(name, file) {
- files[name] = file;
- })
- .on('error', function(err) {
- cb(err, fields, files);
- })
- .on('end', function() {
- cb(null, fields, files);
- });
- }
-
return this;
};
@@ -132,8 +142,11 @@ IncomingForm.prototype.writeHeaders = function(headers) {
};
IncomingForm.prototype.write = function(buffer) {
+ if (this.error) {
+ return;
+ }
if (!this._parser) {
- this._error(new Error('unintialized parser'));
+ this._error(new Error('uninitialized parser'));
return;
}
@@ -197,8 +210,12 @@ IncomingForm.prototype.handlePart = function(part) {
this.emit('fileBegin', part.name, file);
file.open();
+ this.openedFiles.push(file);
part.on('data', function(buffer) {
+ if (buffer.length == 0) {
+ return;
+ }
self.pause();
file.write(buffer, function() {
self.resume();
@@ -214,20 +231,40 @@ IncomingForm.prototype.handlePart = function(part) {
});
};
+function dummyParser(self) {
+ return {
+ end: function () {
+ self.ended = true;
+ self._maybeEnd();
+ return null;
+ }
+ };
+}
+
IncomingForm.prototype._parseContentType = function() {
+ if (this.bytesExpected === 0) {
+ this._parser = dummyParser(this);
+ return;
+ }
+
if (!this.headers['content-type']) {
this._error(new Error('bad content-type header, no content-type'));
return;
}
+ if (this.headers['content-type'].match(/octet-stream/i)) {
+ this._initOctetStream();
+ return;
+ }
+
if (this.headers['content-type'].match(/urlencoded/i)) {
this._initUrlencoded();
return;
}
if (this.headers['content-type'].match(/multipart/i)) {
- var m;
- if (m = this.headers['content-type'].match(/boundary=(?:"([^"]+)"|([^;]+))/i)) {
+ var m = this.headers['content-type'].match(/boundary=(?:"([^"]+)"|([^;]+))/i);
+ if (m) {
this._initMultipart(m[1] || m[2]);
} else {
this._error(new Error('bad content-type header, no multipart boundary'));
@@ -235,23 +272,39 @@ IncomingForm.prototype._parseContentType = function() {
return;
}
+ if (this.headers['content-type'].match(/json/i)) {
+ this._initJSONencoded();
+ return;
+ }
+
this._error(new Error('bad content-type header, unknown content-type: '+this.headers['content-type']));
};
IncomingForm.prototype._error = function(err) {
- if (this.error) {
+ if (this.error || this.ended) {
return;
}
this.error = err;
- this.pause();
this.emit('error', err);
+
+ if (Array.isArray(this.openedFiles)) {
+ this.openedFiles.forEach(function(file) {
+ file._writeStream.destroy();
+ setTimeout(fs.unlink, 0, file.path, function(error) { });
+ });
+ }
};
IncomingForm.prototype._parseContentLength = function() {
+ this.bytesReceived = 0;
if (this.headers['content-length']) {
- this.bytesReceived = 0;
this.bytesExpected = parseInt(this.headers['content-length'], 10);
+ } else if (this.headers['transfer-encoding'] === undefined) {
+ this.bytesExpected = 0;
+ }
+
+ if (this.bytesExpected !== null) {
this.emit('progress', this.bytesReceived, this.bytesExpected);
}
};
@@ -278,6 +331,10 @@ IncomingForm.prototype._initMultipart = function(boundary) {
part.name = null;
part.filename = null;
part.mime = null;
+
+ part.transferEncoding = 'binary';
+ part.transferBuffer = '';
+
headerField = '';
headerValue = '';
};
@@ -294,15 +351,17 @@ IncomingForm.prototype._initMultipart = function(boundary) {
headerField = headerField.toLowerCase();
part.headers[headerField] = headerValue;
- var m;
+ var m = headerValue.match(/\bname="([^"]+)"/i);
if (headerField == 'content-disposition') {
- if (m = headerValue.match(/name="([^"]+)"/i)) {
+ if (m) {
part.name = m[1];
}
part.filename = self._fileName(headerValue);
} else if (headerField == 'content-type') {
part.mime = headerValue;
+ } else if (headerField == 'content-transfer-encoding') {
+ part.transferEncoding = headerValue.toLowerCase();
}
headerField = '';
@@ -310,16 +369,47 @@ IncomingForm.prototype._initMultipart = function(boundary) {
};
parser.onHeadersEnd = function() {
- self.onPart(part);
- };
+ switch(part.transferEncoding){
+ case 'binary':
+ case '7bit':
+ case '8bit':
+ parser.onPartData = function(b, start, end) {
+ part.emit('data', b.slice(start, end));
+ };
+
+ parser.onPartEnd = function() {
+ part.emit('end');
+ };
+ break;
+
+ case 'base64':
+ parser.onPartData = function(b, start, end) {
+ part.transferBuffer += b.slice(start, end).toString('ascii');
+
+ /*
+ four bytes (chars) in base64 converts to three bytes in binary
+ encoding. So we should always work with a number of bytes that
+ can be divided by 4, it will result in a number of buytes that
+ can be divided vy 3.
+ */
+ var offset = parseInt(part.transferBuffer.length / 4, 10) * 4;
+ part.emit('data', new Buffer(part.transferBuffer.substring(0, offset), 'base64'));
+ part.transferBuffer = part.transferBuffer.substring(offset);
+ };
+
+ parser.onPartEnd = function() {
+ part.emit('data', new Buffer(part.transferBuffer, 'base64'));
+ part.emit('end');
+ };
+ break;
+
+ default:
+ return self._error(new Error('unknown transfer-encoding'));
+ }
- parser.onPartData = function(b, start, end) {
- part.emit('data', b.slice(start, end));
+ self.onPart(part);
};
- parser.onPartEnd = function() {
- part.emit('end');
- };
parser.onEnd = function() {
self.ended = true;
@@ -330,7 +420,7 @@ IncomingForm.prototype._initMultipart = function(boundary) {
};
IncomingForm.prototype._fileName = function(headerValue) {
- var m = headerValue.match(/filename="(.*?)"($|; )/i)
+ var m = headerValue.match(/\bfilename="(.*?)"($|; )/i);
if (!m) return;
var filename = m[1].substr(m[1].lastIndexOf('\\') + 1);
@@ -344,7 +434,7 @@ IncomingForm.prototype._fileName = function(headerValue) {
IncomingForm.prototype._initUrlencoded = function() {
this.type = 'urlencoded';
- var parser = new QuerystringParser()
+ var parser = new QuerystringParser(this.maxFields)
, self = this;
parser.onField = function(key, val) {
@@ -359,6 +449,84 @@ IncomingForm.prototype._initUrlencoded = function() {
this._parser = parser;
};
+IncomingForm.prototype._initOctetStream = function() {
+ this.type = 'octet-stream';
+ var filename = this.headers['x-file-name'];
+ var mime = this.headers['content-type'];
+
+ var file = new File({
+ path: this._uploadPath(filename),
+ name: filename,
+ type: mime
+ });
+
+ this.emit('fileBegin', filename, file);
+ file.open();
+
+ this._flushing++;
+
+ var self = this;
+
+ self._parser = new OctetParser();
+
+ //Keep track of writes that haven't finished so we don't emit the file before it's done being written
+ var outstandingWrites = 0;
+
+ self._parser.on('data', function(buffer){
+ self.pause();
+ outstandingWrites++;
+
+ file.write(buffer, function() {
+ outstandingWrites--;
+ self.resume();
+
+ if(self.ended){
+ self._parser.emit('doneWritingFile');
+ }
+ });
+ });
+
+ self._parser.on('end', function(){
+ self._flushing--;
+ self.ended = true;
+
+ var done = function(){
+ file.end(function() {
+ self.emit('file', 'file', file);
+ self._maybeEnd();
+ });
+ };
+
+ if(outstandingWrites === 0){
+ done();
+ } else {
+ self._parser.once('doneWritingFile', done);
+ }
+ });
+};
+
+IncomingForm.prototype._initJSONencoded = function() {
+ this.type = 'json';
+
+ var parser = new JSONParser()
+ , self = this;
+
+ if (this.bytesExpected) {
+ parser.initWithLength(this.bytesExpected);
+ }
+
+ parser.onField = function(key, val) {
+ self.emit('field', key, val);
+ };
+
+ parser.onEnd = function() {
+ self.ended = true;
+ self._maybeEnd();
+ };
+
+ this._parser = parser;
+};
+
IncomingForm.prototype._uploadPath = function(filename) {
var name = '';
for (var i = 0; i < 32; i++) {
@@ -367,7 +535,7 @@ IncomingForm.prototype._uploadPath = function(filename) {
if (this.keepExtensions) {
var ext = path.extname(filename);
- ext = ext.replace(/(\.[a-z0-9]+).*/, '$1')
+ ext = ext.replace(/(\.[a-z0-9]+).*/i, '$1');
name += ext;
}
@@ -376,9 +544,10 @@ IncomingForm.prototype._uploadPath = function(filename) {
};
IncomingForm.prototype._maybeEnd = function() {
- if (!this.ended || this._flushing) {
+ if (!this.ended || this._flushing || this.error) {
return;
}
this.emit('end');
};
+
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/json_parser.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/json_parser.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/json_parser.js
new file mode 100644
index 0000000..db39c31
--- /dev/null
+++ b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/json_parser.js
@@ -0,0 +1,35 @@
+if (global.GENTLY) require = GENTLY.hijack(require);
+
+var Buffer = require('buffer').Buffer;
+
+function JSONParser() {
+ this.data = new Buffer('');
+ this.bytesWritten = 0;
+}
+exports.JSONParser = JSONParser;
+
+JSONParser.prototype.initWithLength = function(length) {
+ this.data = new Buffer(length);
+};
+
+JSONParser.prototype.write = function(buffer) {
+ if (this.data.length >= this.bytesWritten + buffer.length) {
+ buffer.copy(this.data, this.bytesWritten);
+ } else {
+ this.data = Buffer.concat([this.data, buffer]);
+ }
+ this.bytesWritten += buffer.length;
+ return buffer.length;
+};
+
+JSONParser.prototype.end = function() {
+ try {
+ var fields = JSON.parse(this.data.toString('utf8'));
+ for (var field in fields) {
+ this.onField(field, fields[field]);
+ }
+ } catch (e) {}
+ this.data = null;
+
+ this.onEnd();
+};
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/multipart_parser.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/multipart_parser.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/multipart_parser.js
index 9ca567c..d70dd4d 100644
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/multipart_parser.js
+++ b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/multipart_parser.js
@@ -13,13 +13,13 @@ var Buffer = require('buffer').Buffer,
PART_DATA_START: s++,
PART_DATA: s++,
PART_END: s++,
- END: s++,
+ END: s++
},
f = 1,
F =
{ PART_BOUNDARY: f,
- LAST_BOUNDARY: f *= 2,
+ LAST_BOUNDARY: f *= 2
},
LF = 10,
@@ -34,7 +34,7 @@ var Buffer = require('buffer').Buffer,
return c | 0x20;
};
-for (var s in S) {
+for (s in S) {
exports[s] = S[s];
}
@@ -46,7 +46,7 @@ function MultipartParser() {
this.index = null;
this.flags = 0;
-};
+}
exports.MultipartParser = MultipartParser;
MultipartParser.stateToString = function(stateNumber) {
@@ -127,25 +127,34 @@ MultipartParser.prototype.write = function(buffer) {
state = S.START_BOUNDARY;
case S.START_BOUNDARY:
if (index == boundary.length - 2) {
- if (c != CR) {
+ if (c == HYPHEN) {
+ flags |= F.LAST_BOUNDARY;
+ } else if (c != CR) {
return i;
}
index++;
break;
} else if (index - 1 == boundary.length - 2) {
- if (c != LF) {
+ if (flags & F.LAST_BOUNDARY && c == HYPHEN){
+ callback('end');
+ state = S.END;
+ flags = 0;
+ } else if (!(flags & F.LAST_BOUNDARY) && c == LF) {
+ index = 0;
+ callback('partBegin');
+ state = S.HEADER_FIELD_START;
+ } else {
return i;
}
- index = 0;
- callback('partBegin');
- state = S.HEADER_FIELD_START;
break;
}
if (c != boundary[index+2]) {
- return i;
+ index = -2;
+ }
+ if (c == boundary[index+2]) {
+ index++;
}
- index++;
break;
case S.HEADER_FIELD_START:
state = S.HEADER_FIELD;
@@ -207,12 +216,12 @@ MultipartParser.prototype.write = function(buffer) {
state = S.PART_DATA_START;
break;
case S.PART_DATA_START:
- state = S.PART_DATA
+ state = S.PART_DATA;
mark('partData');
case S.PART_DATA:
prevIndex = index;
- if (index == 0) {
+ if (index === 0) {
// boyer-moore derrived algorithm to safely skip non-boundary data
i += boundaryEnd;
while (i < bufferLength && !(buffer[i] in boundaryChars)) {
@@ -224,7 +233,7 @@ MultipartParser.prototype.write = function(buffer) {
if (index < boundary.length) {
if (boundary[index] == c) {
- if (index == 0) {
+ if (index === 0) {
dataCallback('partData', true);
}
index++;
@@ -258,6 +267,7 @@ MultipartParser.prototype.write = function(buffer) {
callback('partEnd');
callback('end');
state = S.END;
+ flags = 0;
} else {
index = 0;
}
@@ -302,7 +312,17 @@ MultipartParser.prototype.write = function(buffer) {
};
MultipartParser.prototype.end = function() {
- if (this.state != S.END) {
+ var callback = function(self, name) {
+ var callbackSymbol = 'on'+name.substr(0, 1).toUpperCase()+name.substr(1);
+ if (callbackSymbol in self) {
+ self[callbackSymbol]();
+ }
+ };
+ if ((this.state == S.HEADER_FIELD_START && this.index === 0) ||
+ (this.state == S.PART_DATA && this.index == this.boundary.length)) {
+ callback(this, 'partEnd');
+ callback(this, 'end');
+ } else if (this.state != S.END) {
return new Error('MultipartParser.end(): stream ended unexpectedly: ' + this.explain());
}
};
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/octet_parser.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/octet_parser.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/octet_parser.js
new file mode 100644
index 0000000..6e8b551
--- /dev/null
+++ b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/octet_parser.js
@@ -0,0 +1,20 @@
+var EventEmitter = require('events').EventEmitter
+ , util = require('util');
+
+function OctetParser(options){
+ if(!(this instanceof OctetParser)) return new OctetParser(options);
+ EventEmitter.call(this);
+}
+
+util.inherits(OctetParser, EventEmitter);
+
+exports.OctetParser = OctetParser;
+
+OctetParser.prototype.write = function(buffer) {
+ this.emit('data', buffer);
+ return buffer.length;
+};
+
+OctetParser.prototype.end = function() {
+ this.emit('end');
+};
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/querystring_parser.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/querystring_parser.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/querystring_parser.js
index 63f109e..fcaffe0 100644
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/querystring_parser.js
+++ b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/querystring_parser.js
@@ -4,9 +4,10 @@ if (global.GENTLY) require = GENTLY.hijack(require);
// If I find time I'll rewrite this to be fully streaming as well
var querystring = require('querystring');
-function QuerystringParser() {
+function QuerystringParser(maxKeys) {
+ this.maxKeys = maxKeys;
this.buffer = '';
-};
+}
exports.QuerystringParser = QuerystringParser;
QuerystringParser.prototype.write = function(buffer) {
@@ -15,11 +16,12 @@ QuerystringParser.prototype.write = function(buffer) {
};
QuerystringParser.prototype.end = function() {
- var fields = querystring.parse(this.buffer);
+ var fields = querystring.parse(this.buffer, '&', '=', { maxKeys: this.maxKeys });
for (var field in fields) {
this.onField(field, fields[field]);
}
this.buffer = '';
this.onEnd();
-};
\ No newline at end of file
+};
+
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/util.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/util.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/util.js
deleted file mode 100644
index e9493e9..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/lib/util.js
+++ /dev/null
@@ -1,6 +0,0 @@
-// Backwards compatibility ...
-try {
- module.exports = require('util');
-} catch (e) {
- module.exports = require('sys');
-}
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/Makefile
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/Makefile b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/Makefile
deleted file mode 100644
index 01f7140..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
-test:
- @find test/simple/test-*.js | xargs -n 1 -t node
-
-.PHONY: test
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/Readme.md
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/Readme.md b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/Readme.md
deleted file mode 100644
index f8f0c66..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/Readme.md
+++ /dev/null
@@ -1,167 +0,0 @@
-# Gently
-
-## Purpose
-
-A node.js module that helps with stubbing and behavior verification. It allows you to test the most remote and nested corners of your code while keeping being fully unobtrusive.
-
-## Features
-
-* Overwrite and stub individual object functions
-* Verify that all expected calls have been made in the expected order
-* Restore stubbed functions to their original behavior
-* Detect object / class names from obj.constructor.name and obj.toString()
-* Hijack any required module function or class constructor
-
-## Installation
-
-Via [npm](http://github.com/isaacs/npm):
-
- npm install gently@latest
-
-## Example
-
-Make sure your dog is working properly:
-
- function Dog() {}
-
- Dog.prototype.seeCat = function() {
- this.bark('whuf, whuf');
- this.run();
- }
-
- Dog.prototype.bark = function(bark) {
- require('sys').puts(bark);
- }
-
- var gently = new (require('gently'))
- , assert = require('assert')
- , dog = new Dog();
-
- gently.expect(dog, 'bark', function(bark) {
- assert.equal(bark, 'whuf, whuf');
- });
- gently.expect(dog, 'run');
-
- dog.seeCat();
-
-You can also easily test event emitters with this, for example a simple sequence of 2 events emitted by `fs.WriteStream`:
-
- var gently = new (require('gently'))
- , stream = new (require('fs').WriteStream)('my_file.txt');
-
- gently.expect(stream, 'emit', function(event) {
- assert.equal(event, 'open');
- });
-
- gently.expect(stream, 'emit', function(event) {
- assert.equal(event, 'drain');
- });
-
-For a full read world example, check out this test case: [test-incoming-form.js](http://github.com/felixge/node-formidable/blob/master/test/simple/test-incoming-form.js) (in [node-formdiable](http://github.com/felixge/node-formidable)).
-
-## API
-
-### Gently
-
-#### new Gently()
-
-Creates a new gently instance. It listens to the process `'exit'` event to make sure all expectations have been verified.
-
-#### gently.expect(obj, method, [[count], stubFn])
-
-Creates an expectation for an objects method to be called. You can optionally specify the call `count` you are expecting, as well as `stubFn` function that will run instead of the original function.
-
-Returns a reference to the function that is getting overwritten.
-
-#### gently.expect([count], stubFn)
-
-Returns a function that is supposed to be executed `count` times, delegating any calls to the provided `stubFn` function. Naming your stubFn closure will help to properly diagnose errors that are being thrown:
-
- childProcess.exec('ls', gently.expect(function lsCallback(code) {
- assert.equal(0, code);
- }));
-
-#### gently.restore(obj, method)
-
-Restores an object method that has been previously overwritten using `gently.expect()`.
-
-#### gently.hijack(realRequire)
-
-Returns a new require functions that catches a reference to all required modules into `gently.hijacked`.
-
-To use this function, include a line like this in your `'my-module.js'`.
-
- if (global.GENTLY) require = GENTLY.hijack(require);
-
- var sys = require('sys');
- exports.hello = function() {
- sys.log('world');
- };
-
-Now you can write a test for the module above:
-
- var gently = global.GENTLY = new (require('gently'))
- , myModule = require('./my-module');
-
- gently.expect(gently.hijacked.sys, 'log', function(str) {
- assert.equal(str, 'world');
- });
-
- myModule.hello();
-
-#### gently.stub(location, [exportsName])
-
-Returns a stub class that will be used instead of the real class from the module at `location` with the given `exportsName`.
-
-This allows to test an OOP version of the previous example, where `'my-module.js'`.
-
- if (global.GENTLY) require = GENTLY.hijack(require);
-
- var World = require('./world');
-
- exports.hello = function() {
- var world = new World();
- world.hello();
- }
-
-And `world.js` looks like this:
-
- var sys = require('sys');
-
- function World() {
-
- }
- module.exports = World;
-
- World.prototype.hello = function() {
- sys.log('world');
- };
-
-Testing `'my-module.js'` can now easily be accomplished:
-
- var gently = global.GENTLY = new (require('gently'))
- , WorldStub = gently.stub('./world')
- , myModule = require('./my-module')
- , WORLD;
-
- gently.expect(WorldStub, 'new', function() {
- WORLD = this;
- });
-
- gently.expect(WORLD, 'hello');
-
- myModule.hello();
-
-#### gently.hijacked
-
-An object that holds the references to all hijacked modules.
-
-#### gently.verify([msg])
-
-Verifies that all expectations of this gently instance have been satisfied. If not called manually, this method is called when the process `'exit'` event is fired.
-
-If `msg` is given, it will appear in any error that might be thrown.
-
-## License
-
-Gently is licensed under the MIT license.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/example/dog.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/example/dog.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/example/dog.js
deleted file mode 100644
index 022fae0..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/example/dog.js
+++ /dev/null
@@ -1,22 +0,0 @@
-require('../test/common');
-function Dog() {}
-
-Dog.prototype.seeCat = function() {
- this.bark('whuf, whuf');
- this.run();
-}
-
-Dog.prototype.bark = function(bark) {
- require('sys').puts(bark);
-}
-
-var gently = new (require('gently'))
- , assert = require('assert')
- , dog = new Dog();
-
-gently.expect(dog, 'bark', function(bark) {
- assert.equal(bark, 'whuf, whuf');
-});
-gently.expect(dog, 'run');
-
-dog.seeCat();
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/example/event_emitter.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/example/event_emitter.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/example/event_emitter.js
deleted file mode 100644
index 7def134..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/example/event_emitter.js
+++ /dev/null
@@ -1,11 +0,0 @@
-require('../test/common');
-var gently = new (require('gently'))
- , stream = new (require('fs').WriteStream)('my_file.txt');
-
-gently.expect(stream, 'emit', function(event) {
- assert.equal(event, 'open');
-});
-
-gently.expect(stream, 'emit', function(event) {
- assert.equal(event, 'drain');
-});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/index.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/index.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/index.js
deleted file mode 100644
index 69122bd..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/index.js
+++ /dev/null
@@ -1 +0,0 @@
-module.exports = require('./lib/gently');
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/lib/gently/gently.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/lib/gently/gently.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/lib/gently/gently.js
deleted file mode 100644
index 8af0e1e..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/lib/gently/gently.js
+++ /dev/null
@@ -1,184 +0,0 @@
-var path = require('path');
-
-function Gently() {
- this.expectations = [];
- this.hijacked = {};
-
- var self = this;
- process.addListener('exit', function() {
- self.verify('process exit');
- });
-};
-module.exports = Gently;
-
-Gently.prototype.stub = function(location, exportsName) {
- function Stub() {
- return Stub['new'].apply(this, arguments);
- };
-
- Stub['new'] = function () {};
-
- var stubName = 'require('+JSON.stringify(location)+')';
- if (exportsName) {
- stubName += '.'+exportsName;
- }
-
- Stub.prototype.toString = Stub.toString = function() {
- return stubName;
- };
-
- var exports = this.hijacked[location] || {};
- if (exportsName) {
- exports[exportsName] = Stub;
- } else {
- exports = Stub;
- }
-
- this.hijacked[location] = exports;
- return Stub;
-};
-
-Gently.prototype.hijack = function(realRequire) {
- var self = this;
- return function(location) {
- return self.hijacked[location] = (self.hijacked[location])
- ? self.hijacked[location]
- : realRequire(location);
- };
-};
-
-Gently.prototype.expect = function(obj, method, count, stubFn) {
- if (typeof obj != 'function' && typeof obj != 'object' && typeof obj != 'number') {
- throw new Error
- ( 'Bad 1st argument for gently.expect(), '
- + 'object, function, or number expected, got: '+(typeof obj)
- );
- } else if (typeof obj == 'function' && (typeof method != 'string')) {
- // expect(stubFn) interface
- stubFn = obj;
- obj = null;
- method = null;
- count = 1;
- } else if (typeof method == 'function') {
- // expect(count, stubFn) interface
- count = obj;
- stubFn = method;
- obj = null;
- method = null;
- } else if (typeof count == 'function') {
- // expect(obj, method, stubFn) interface
- stubFn = count;
- count = 1;
- } else if (count === undefined) {
- // expect(obj, method) interface
- count = 1;
- }
-
- var name = this._name(obj, method, stubFn);
- this.expectations.push({obj: obj, method: method, stubFn: stubFn, name: name, count: count});
-
- var self = this;
- function delegate() {
- return self._stubFn(this, obj, method, name, Array.prototype.slice.call(arguments));
- }
-
- if (!obj) {
- return delegate;
- }
-
- var original = (obj[method])
- ? obj[method]._original || obj[method]
- : undefined;
-
- obj[method] = delegate;
- return obj[method]._original = original;
-};
-
-Gently.prototype.restore = function(obj, method) {
- if (!obj[method] || !obj[method]._original) {
- throw new Error(this._name(obj, method)+' is not gently stubbed');
- }
- obj[method] = obj[method]._original;
-};
-
-Gently.prototype.verify = function(msg) {
- if (!this.expectations.length) {
- return;
- }
-
- var validExpectations = [];
- for (var i = 0, l = this.expectations.length; i < l; i++) {
- var expectation = this.expectations[i];
-
- if (expectation.count > 0) {
- validExpectations.push(expectation);
- }
- }
-
- this.expectations = []; // reset so that no duplicate verification attempts are made
-
- if (!validExpectations.length) {
- return;
- }
-
- var expectation = validExpectations[0];
-
- throw new Error
- ( 'Expected call to '+expectation.name+' did not happen'
- + ( (msg)
- ? ' ('+msg+')'
- : ''
- )
- );
-};
-
-Gently.prototype._stubFn = function(self, obj, method, name, args) {
- var expectation = this.expectations[0], obj, method;
-
- if (!expectation) {
- throw new Error('Unexpected call to '+name+', no call was expected');
- }
-
- if (expectation.obj !== obj || expectation.method !== method) {
- throw new Error('Unexpected call to '+name+', expected call to '+ expectation.name);
- }
-
- expectation.count -= 1;
- if (expectation.count === 0) {
- this.expectations.shift();
-
- // autorestore original if its not a closure
- // and no more expectations on that object
- var has_more_expectations = this.expectations.reduce(function (memo, expectation) {
- return memo || (expectation.obj === obj && expectation.method === method);
- }, false);
- if (obj !== null && method !== null && !has_more_expectations) {
- if (typeof obj[method]._original !== 'undefined') {
- obj[method] = obj[method]._original;
- delete obj[method]._original;
- } else {
- delete obj[method];
- }
- }
- }
-
- if (expectation.stubFn) {
- return expectation.stubFn.apply(self, args);
- }
-};
-
-Gently.prototype._name = function(obj, method, stubFn) {
- if (obj) {
- var objectName = obj.toString();
- if (objectName == '[object Object]' && obj.constructor.name) {
- objectName = '['+obj.constructor.name+']';
- }
- return (objectName)+'.'+method+'()';
- }
-
- if (stubFn.name) {
- return stubFn.name+'()';
- }
-
- return '>> '+stubFn.toString()+' <<';
-};
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/lib/gently/index.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/lib/gently/index.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/lib/gently/index.js
deleted file mode 100644
index 64c1977..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/lib/gently/index.js
+++ /dev/null
@@ -1 +0,0 @@
-module.exports = require('./gently');
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/package.json
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/package.json b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/package.json
deleted file mode 100644
index 9c1b7a0..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/package.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "name": "gently",
- "version": "0.9.2",
- "directories": {
- "lib": "./lib/gently"
- },
- "main": "./lib/gently/index",
- "dependencies": {},
- "devDependencies": {},
- "engines": {
- "node": "*"
- },
- "optionalDependencies": {}
-}
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/test/common.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/test/common.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/test/common.js
deleted file mode 100644
index 978b5c5..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/test/common.js
+++ /dev/null
@@ -1,8 +0,0 @@
-var path = require('path')
- , sys = require('sys');
-
-require.paths.unshift(path.dirname(__dirname)+'/lib');
-
-global.puts = sys.puts;
-global.p = function() {sys.error(sys.inspect.apply(null, arguments))};;
-global.assert = require('assert');
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-weinre/blob/9b06777d/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/test/simple/test-gently.js
----------------------------------------------------------------------
diff --git a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/test/simple/test-gently.js b/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/test/simple/test-gently.js
deleted file mode 100644
index 4f8fe2d..0000000
--- a/weinre.server/node_modules/express/node_modules/connect/node_modules/formidable/node-gently/test/simple/test-gently.js
+++ /dev/null
@@ -1,348 +0,0 @@
-require('../common');
-var Gently = require('gently')
- , gently;
-
-function test(test) {
- process.removeAllListeners('exit');
- gently = new Gently();
- test();
-}
-
-test(function constructor() {
- assert.deepEqual(gently.expectations, []);
- assert.deepEqual(gently.hijacked, {});
- assert.equal(gently.constructor.name, 'Gently');
-});
-
-test(function expectBadArgs() {
- var BAD_ARG = 'oh no';
- try {
- gently.expect(BAD_ARG);
- assert.ok(false, 'throw needs to happen');
- } catch (e) {
- assert.equal(e.message, 'Bad 1st argument for gently.expect(), object, function, or number expected, got: '+(typeof BAD_ARG));
- }
-});
-
-test(function expectObjMethod() {
- var OBJ = {}, NAME = 'foobar';
- OBJ.foo = function(x) {
- return x;
- };
-
- gently._name = function() {
- return NAME;
- };
-
- var original = OBJ.foo
- , stubFn = function() {};
-
- (function testAddOne() {
- assert.strictEqual(gently.expect(OBJ, 'foo', stubFn), original);
-
- assert.equal(gently.expectations.length, 1);
- var expectation = gently.expectations[0];
- assert.strictEqual(expectation.obj, OBJ);
- assert.strictEqual(expectation.method, 'foo');
- assert.strictEqual(expectation.stubFn, stubFn);
- assert.strictEqual(expectation.name, NAME);
- assert.strictEqual(OBJ.foo._original, original);
- })();
-
- (function testAddTwo() {
- gently.expect(OBJ, 'foo', 2, stubFn);
- assert.equal(gently.expectations.length, 2);
- assert.strictEqual(OBJ.foo._original, original);
- })();
-
- (function testAddOneWithoutMock() {
- gently.expect(OBJ, 'foo');
- assert.equal(gently.expectations.length, 3);
- })();
-
- var stubFnCalled = 0, SELF = {};
- gently._stubFn = function(self, obj, method, name, args) {
- stubFnCalled++;
- assert.strictEqual(self, SELF);
- assert.strictEqual(obj, OBJ);
- assert.strictEqual(method, 'foo');
- assert.strictEqual(name, NAME);
- assert.deepEqual(args, [1, 2]);
- return 23;
- };
- assert.equal(OBJ.foo.apply(SELF, [1, 2]), 23);
- assert.equal(stubFnCalled, 1);
-});
-
-test(function expectClosure() {
- var NAME = 'MY CLOSURE';
- function closureFn() {};
-
- gently._name = function() {
- return NAME;
- };
-
- var fn = gently.expect(closureFn);
- assert.equal(gently.expectations.length, 1);
- var expectation = gently.expectations[0];
- assert.strictEqual(expectation.obj, null);
- assert.strictEqual(expectation.method, null);
- assert.strictEqual(expectation.stubFn, closureFn);
- assert.strictEqual(expectation.name, NAME);
-
- var stubFnCalled = 0, SELF = {};
- gently._stubFn = function(self, obj, method, name, args) {
- stubFnCalled++;
- assert.strictEqual(self, SELF);
- assert.strictEqual(obj, null);
- assert.strictEqual(method, null);
- assert.strictEqual(name, NAME);
- assert.deepEqual(args, [1, 2]);
- return 23;
- };
- assert.equal(fn.apply(SELF, [1, 2]), 23);
- assert.equal(stubFnCalled, 1);
-});
-
-test(function expectClosureCount() {
- var stubFnCalled = 0;
- function closureFn() {stubFnCalled++};
-
- var fn = gently.expect(2, closureFn);
- assert.equal(gently.expectations.length, 1);
- fn();
- assert.equal(gently.expectations.length, 1);
- fn();
- assert.equal(stubFnCalled, 2);
-});
-
-test(function restore() {
- var OBJ = {}, NAME = '[my object].myFn()';
- OBJ.foo = function(x) {
- return x;
- };
-
- gently._name = function() {
- return NAME;
- };
-
- var original = OBJ.foo;
- gently.expect(OBJ, 'foo');
- gently.restore(OBJ, 'foo');
- assert.strictEqual(OBJ.foo, original);
-
- (function testError() {
- try {
- gently.restore(OBJ, 'foo');
- assert.ok(false, 'throw needs to happen');
- } catch (e) {
- assert.equal(e.message, NAME+' is not gently stubbed');
- }
- })();
-});
-
-test(function _stubFn() {
- var OBJ1 = {toString: function() {return '[OBJ 1]'}}
- , OBJ2 = {toString: function() {return '[OBJ 2]'}, foo: function () {return 'bar';}}
- , SELF = {};
-
- gently.expect(OBJ1, 'foo', function(x) {
- assert.strictEqual(this, SELF);
- return x * 2;
- });
-
- assert.equal(gently._stubFn(SELF, OBJ1, 'foo', 'dummy_name', [5]), 10);
-
- (function testAutorestore() {
- assert.equal(OBJ2.foo(), 'bar');
-
- gently.expect(OBJ2, 'foo', function() {
- return 'stubbed foo';
- });
-
- gently.expect(OBJ2, 'foo', function() {
- return "didn't restore yet";
- });
-
- assert.equal(gently._stubFn(SELF, OBJ2, 'foo', 'dummy_name', []), 'stubbed foo');
- assert.equal(gently._stubFn(SELF, OBJ2, 'foo', 'dummy_name', []), "didn't restore yet");
- assert.equal(OBJ2.foo(), 'bar');
- assert.deepEqual(gently.expectations, []);
- })();
-
- (function testNoMoreCallExpected() {
- try {
- gently._stubFn(SELF, OBJ1, 'foo', 'dummy_name', [5]);
- assert.ok(false, 'throw needs to happen');
- } catch (e) {
- assert.equal(e.message, 'Unexpected call to dummy_name, no call was expected');
- }
- })();
-
- (function testDifferentCallExpected() {
- gently.expect(OBJ2, 'bar');
- try {
- gently._stubFn(SELF, OBJ1, 'foo', 'dummy_name', [5]);
- assert.ok(false, 'throw needs to happen');
- } catch (e) {
- assert.equal(e.message, 'Unexpected call to dummy_name, expected call to '+gently._name(OBJ2, 'bar'));
- }
-
- assert.equal(gently.expectations.length, 1);
- })();
-
- (function testNoMockCallback() {
- OBJ2.bar();
- assert.equal(gently.expectations.length, 0);
- })();
-});
-
-test(function stub() {
- var LOCATION = './my_class';
-
- (function testRegular() {
- var Stub = gently.stub(LOCATION);
- assert.ok(Stub instanceof Function);
- assert.strictEqual(gently.hijacked[LOCATION], Stub);
- assert.ok(Stub['new'] instanceof Function);
- assert.equal(Stub.toString(), 'require('+JSON.stringify(LOCATION)+')');
-
- (function testConstructor() {
- var newCalled = 0
- , STUB
- , ARGS = ['foo', 'bar'];
-
- Stub['new'] = function(a, b) {
- assert.equal(a, ARGS[0]);
- assert.equal(b, ARGS[1]);
- newCalled++;
- STUB = this;
- };
-
- var stub = new Stub(ARGS[0], ARGS[1]);
- assert.strictEqual(stub, STUB);
- assert.equal(newCalled, 1);
- assert.equal(stub.toString(), 'require('+JSON.stringify(LOCATION)+')');
- })();
-
- (function testUseReturnValueAsInstance() {
- var R = {};
-
- Stub['new'] = function() {
- return R;
- };
-
- var stub = new Stub();
- assert.strictEqual(stub, R);
-
- })();
- })();
-
- var EXPORTS_NAME = 'MyClass';
- test(function testExportsName() {
- var Stub = gently.stub(LOCATION, EXPORTS_NAME);
- assert.strictEqual(gently.hijacked[LOCATION][EXPORTS_NAME], Stub);
- assert.equal(Stub.toString(), 'require('+JSON.stringify(LOCATION)+').'+EXPORTS_NAME);
-
- (function testConstructor() {
- var stub = new Stub();
- assert.equal(Stub.toString(), 'require('+JSON.stringify(LOCATION)+').'+EXPORTS_NAME);
- })();
- });
-});
-
-test(function hijack() {
- var LOCATION = './foo'
- , REQUIRE_CALLS = 0
- , EXPORTS = {}
- , REQUIRE = function() {
- REQUIRE_CALLS++;
- return EXPORTS;
- };
-
- var hijackedRequire = gently.hijack(REQUIRE);
- hijackedRequire(LOCATION);
- assert.strictEqual(gently.hijacked[LOCATION], EXPORTS);
-
- assert.equal(REQUIRE_CALLS, 1);
-
- // make sure we are caching the hijacked module
- hijackedRequire(LOCATION);
- assert.equal(REQUIRE_CALLS, 1);
-});
-
-test(function verify() {
- var OBJ = {toString: function() {return '[OBJ]'}};
- gently.verify();
-
- gently.expect(OBJ, 'foo');
- try {
- gently.verify();
- assert.ok(false, 'throw needs to happen');
- } catch (e) {
- assert.equal(e.message, 'Expected call to [OBJ].foo() did not happen');
- }
-
- try {
- gently.verify('foo');
- assert.ok(false, 'throw needs to happen');
- } catch (e) {
- assert.equal(e.message, 'Expected call to [OBJ].foo() did not happen (foo)');
- }
-});
-
-test(function processExit() {
- var verifyCalled = 0;
- gently.verify = function(msg) {
- verifyCalled++;
- assert.equal(msg, 'process exit');
- };
-
- process.emit('exit');
- assert.equal(verifyCalled, 1);
-});
-
-test(function _name() {
- (function testNamedClass() {
- function Foo() {};
- var foo = new Foo();
- assert.equal(gently._name(foo, 'bar'), '[Foo].bar()');
- })();
-
- (function testToStringPreference() {
- function Foo() {};
- Foo.prototype.toString = function() {
- return '[Superman 123]';
- };
- var foo = new Foo();
- assert.equal(gently._name(foo, 'bar'), '[Superman 123].bar()');
- })();
-
- (function testUnamedClass() {
- var Foo = function() {};
- var foo = new Foo();
- assert.equal(gently._name(foo, 'bar'), foo.toString()+'.bar()');
- })();
-
- (function testNamedClosure() {
- function myClosure() {};
- assert.equal(gently._name(null, null, myClosure), myClosure.name+'()');
- })();
-
- (function testUnamedClosure() {
- var myClosure = function() {2+2 == 5};
- assert.equal(gently._name(null, null, myClosure), '>> '+myClosure.toString()+' <<');
- })();
-});
-
-test(function verifyExpectNone() {
- var OBJ = {toString: function() {return '[OBJ]'}};
- gently.verify();
-
- gently.expect(OBJ, 'foo', 0);
- try {
- gently.verify();
- } catch (e) {
- assert.fail('Exception should not have been thrown');
- }
-});
\ No newline at end of file