Skip to content
Browse files

mocha unittest style

  • Loading branch information...
1 parent f00fc04 commit 608f8e6fe287c0f70ef497ebf651c7744b07fe87 @fengmk2 committed
View
1 .gitignore
@@ -1,2 +1,3 @@
build/
+node_modules/
.lock-wscript
View
4 .travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - 0.6
+ - 0.8
View
27 Makefile
@@ -1,2 +1,25 @@
-all:
- node-waf build
+TESTS = test/*.js
+TIMEOUT = 5000
+REPORTER = spec
+MOCHAOPTS=
+
+build:
+ @node-gyp clean && node-gyp configure && node-gyp build
+
+test:
+ @NODE_ENV=test ./node_modules/mocha/bin/mocha \
+ --reporter $(REPORTER) --timeout $(TIMEOUT) $(MOCHAOPTS) $(TESTS)
+
+test-cov: lib-cov
+ @HTTPSYNC_COV=1 $(MAKE) test
+ @HTTPSYNC_COV=1 $(MAKE) test REPORTER=html-cov > coverage.html
+
+lib-cov:
+ @rm -rf lib-cov
+ @jscoverage lib lib-cov
+
+clean:
+ @rm -rf lib-cov
+ @rm -f coverage.html
+
+.PHONY: build test test-cov lib-cov clean
View
33 README.md
@@ -16,7 +16,7 @@ $ npm install httpsync
## APIs
-### curl.request (options)
+### curl.request(options)
Options:
@@ -42,7 +42,7 @@ var req = curl.request({
});
```
-### curl.get ([options | url])
+### curl.get([options | url])
It's equivalent to `curl.request` but the method is default to `GET`.
@@ -58,11 +58,11 @@ var req = curl.get({ url : "http://cnodejs.org"});
var req = curl.get("http://cnodejs.org");
```
-### request.write (chunk)
+### request.write(chunk)
Write a chunk of data to the request. The type of data can be String or Buffer.
-### request.end ([chunk])
+### request.end([chunk])
Send the request and get response.
@@ -101,3 +101,28 @@ req.endFile("/etc/passwd");
- `ip` IP address of the server.
- `statusCode` Status code that sent by server.
+## License
+
+(The MIT License)
+
+Copyright (c) 2012 fengmk2 <fengmk2@gmail.com>
+Copyright (c) 2012 zcbenz https://github.com/zcbenz
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
16 binding.gyp
@@ -0,0 +1,16 @@
+{
+ "targets": [
+ {
+ "target_name": "node_curl",
+ "cflags": ["-g", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall"],
+ "sources": [
+ "src/main.cc",
+ "src/curl.cc",
+ "src/request.cc"
+ ],
+ "libraries": [
+ "-lcurl"
+ ]
+ }
+ ]
+}
View
6 package.json
@@ -2,7 +2,7 @@
"name": "httpsync",
"version": "0.0.1",
"scripts": {
- "install": "node-waf clean ; node-waf configure build"
+ "install": "node-gyp clean && node-gyp configure && node-gyp build"
},
"description": "node-curl is a port of libcurl to node.js. Its interface emulates the `http` module of node.js. But in contrast to `http` module's asynchronous functions, node-curl provides the equivalent synchronous APIs.",
"main": "index.js",
@@ -18,6 +18,10 @@
"sync",
"http"
],
+ "devDependencies": {
+ "should": "*",
+ "mocha": "*"
+ },
"author": "zcbenz",
"license": "MIT"
}
View
0 test/README.md → test-old/README.md
File renamed without changes.
View
0 test/echo.js → test-old/echo.js
File renamed without changes.
View
0 test/lib.js → test-old/lib.js
File renamed without changes.
View
0 test/test.js → test-old/test.js
File renamed without changes.
View
44 test/curl.js
@@ -0,0 +1,44 @@
+/*!
+ * httpsync - node-curl.node test
+ * Copyright(c) 2012 fengmk2 <fengmk2@gmail.com>
+ * MIT Licensed
+ */
+
+"use strict";
+
+/**
+ * Module dependencies.
+ */
+
+var httpsync = require('../');
+var should = require('should');
+var echo = require('./support/echo');
+
+describe('curl.js', function () {
+
+ var app = echo.create();
+ var homeurl = 'http://127.0.0.1:';
+ before(function (done) {
+ app.listen(0, function () {
+ console.log(app.address());
+ homeurl += app.address().port;
+ done();
+ });
+ });
+
+ describe('get()', function () {
+ it('should GET / return status 200', function (done) {
+ require('http').get(homeurl, function (res) {
+ res.should.status(200);
+ done();
+ });
+ });
+
+ it('should GET / return status 200', function () {
+ var req = httpsync.get(homeurl);
+ var res = req.end();
+ res.should.status(200);
+ });
+ });
+
+});
View
2 test/mocha.opts
@@ -0,0 +1,2 @@
+--require should
+--growl
View
52 test/support/echo.js
@@ -0,0 +1,52 @@
+exports.create = function () {
+
+ var app = require("http").createServer(function (req, res) {
+ if (req.headers.timeout) {
+ setTimeout (function () {
+ res.end();
+ }, 6000);
+ return;
+ }
+
+ if (req.method === "HEAD") {
+ res.writeHead(200, {
+ 'Content-Type' : 'text/plain',
+ 'Date' : 'Wed, 17 Mar 2004 18 : 00 : 49 GMT',
+ 'Last-Modified' : 'Wed, 25 Feb 2004 22 : 37 : 23 GMT'
+ });
+ res.end();
+ return;
+ }
+
+ if (req.headers.customheaders) {
+ res.writeHead(42, {
+ 'Content-Type': 'text/plain',
+ 'customheaders': req.headers.customheaders
+ });
+ } else {
+ res.writeHead(200, {
+ 'Content-Type': 'text/plain',
+ 'X-REQUEST-URL': req.url
+ });
+ }
+
+ if (!req.headers.nomethod) {
+ res.write(req.method + "\n");
+ }
+
+ if (req.headers.custom) {
+ res.write(JSON.stringify(req.headers));
+ }
+
+ var data = new Buffer("");
+ req.on("data", function (chunk) {
+ data += chunk;
+ });
+ req.on("end", function (chunk) {
+ res.end(data);
+ });
+ });
+
+ return app;
+
+};

0 comments on commit 608f8e6

Please sign in to comment.
Something went wrong with that request. Please try again.