Skip to content

Commit 1e0c201

Browse files
committed
update tests, add multipart/form-data processing support
1 parent ef5c20a commit 1e0c201

File tree

12 files changed

+362
-219
lines changed

12 files changed

+362
-219
lines changed

Gruntfile.js

Lines changed: 8 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var sys = require('sys');
2+
var path = require('path');
23
module.exports = function(grunt) {
34
grunt.initConfig({
45
pkg: grunt.file.readJSON('package.json'),
@@ -106,89 +107,24 @@ module.exports = function(grunt) {
106107
src: ['src/**/*.js']
107108
}
108109
},
109-
connect: {
110-
server: {
110+
express: {
111+
testServer: {
111112
options: {
112-
port: 8000,
113-
base: './test',
114-
middleware: function(connect, options, middlewares) {
115-
middlewares.push(function(req, res, next) {
116-
if (req.url === '/data/test-json' && req.method === 'GET') {
117-
res.setHeader('Content-Type', 'application/json');
118-
res.end(JSON.stringify({abc: 123}));
119-
return true;
120-
} else {
121-
return next();
122-
}
123-
});
124-
middlewares.push(function(req, res, next) {
125-
if (req.url === '/data/test-bad-json' && req.method === 'GET') {
126-
res.setHeader('Content-Type', 'application/json');
127-
res.end('lllll');
128-
return true;
129-
} else {
130-
return next();
131-
}
132-
});
133-
middlewares.push(function(req, res, next) {
134-
if (req.url === '/data/test-empty-json' && req.method === 'GET') {
135-
res.setHeader('Content-Type', 'application/json');
136-
res.end('');
137-
return true;
138-
} else {
139-
return next();
140-
}
141-
});
142-
middlewares.push(function(req, res, next) {
143-
if (req.url === '/test-post' && req.method === 'POST') {
144-
res.setHeader('Content-Type', 'application/json');
145-
res.end(JSON.stringify({abc: 123}));
146-
return true;
147-
} else {
148-
return next();
149-
}
150-
});
151-
middlewares.push(function(req, res, next) {
152-
if (req.url === '/data/test' && req.method === 'GET') {
153-
res.end("Hi There");
154-
return true;
155-
} else {
156-
return next();
157-
}
158-
});
159-
middlewares.push(function(req, res, next) {
160-
if (req.url === '/data/test/weird-status' && req.method === 'GET') {
161-
res.statusCode = 444;
162-
res.end("Hi There");
163-
return true;
164-
} else {
165-
return next();
166-
}
167-
});
168-
middlewares.push(function(req, res, next) {
169-
if (req.url === '/data/test/server-error' && req.method === 'GET') {
170-
res.statusCode = 500;
171-
res.end("Hi There");
172-
return true;
173-
} else {
174-
return next();
175-
}
176-
});
177-
return middlewares;
178-
}
113+
server: path.resolve(__dirname, 'test/server.js'),
114+
port: 8000
179115
}
180116
}
181117
}
182118
});
183119

184-
grunt.loadNpmTasks('grunt-contrib-connect');
185120
grunt.loadNpmTasks('grunt-requirejs');
186121
grunt.loadNpmTasks('grunt-contrib-jshint');
187122
grunt.loadNpmTasks('grunt-contrib-qunit');
188123
grunt.loadNpmTasks('grunt-contrib-watch');
189124
grunt.loadNpmTasks('grunt-contrib-clean');
125+
grunt.loadNpmTasks('grunt-express');
190126

191127
grunt.registerTask('test', ['jshint', 'requirejs:compile', 'requirejs:compileForTest', 'qunit', 'clean']);
192-
grunt.registerTask('build', ['connect', 'jshint', 'requirejs:compile', 'qunit']);
193-
grunt.registerTask('default', ['connect', 'watch']);
128+
grunt.registerTask('build', ['express', 'test']); //jshint', 'requirejs:compile', 'requirejs:compileForTest', 'qunit', 'clean']);
129+
grunt.registerTask('default', ['express', 'watch']);
194130
};

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,17 @@ The form client is a convenience method to encode and serialize data as form POS
191191
console.log(req);
192192
}
193193
});
194+
195+
If `data` is a plain object, it will send the form POST/PUT as a urlencoded request. If `data` is a `form` element or a `FormData` object, it will send it as a multipart/form-data post (handy for file uploads).
194196

195197

196-
Supported Browsers
197-
==================
198+
Developing
199+
==========
198200

199-
* Google Chrome 22+ (Desktop, Android)
200-
* Firefox 10+
201-
* Safari 5.x+, iOS
202-
* IE8+ (and probably 6/7, but need tests!)
203-
* Opera
201+
You'll need node installed to develop net.js. Just clone the repo and run `npm install` to get set up.
202+
203+
`grunt` is used to manage build and development tasks:
204+
205+
* `grunt` (with no arguments) starts up the test API server, testing/linting/compiling on file changes.
206+
* `grunt build` does the test/lint/compile once and exits.
204207

dist/net.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "net.js",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"description": "Minimalistic network communications for browsers",
55
"main": "Gruntfile.js",
66
"directories": {
@@ -16,7 +16,10 @@
1616
"grunt-contrib-connect": "~0.7.1",
1717
"grunt-contrib-watch": "~0.6.0",
1818
"grunt-jasmine-runner": "~0.6.0",
19-
"grunt-contrib-clean": "~0.5.0"
19+
"grunt-contrib-clean": "~0.5.0",
20+
"grunt-express": "~1.2.1",
21+
"express": "^3.5.1",
22+
"formidable": "^1.0.14"
2023
},
2124
"scripts": {
2225
"test": "echo \"Error: no test specified\" && exit 1"

0 commit comments

Comments
 (0)