Permalink
Browse files

Better tests and README.

Still not the best, but it should at least help node users understand
the goals and mechanics of this library a little better.

Signed-off-by: Tim Smart <tim@fostle.com>
  • Loading branch information...
1 parent 1511824 commit ff99dbfb9c59402db87c608f8b3bdb3ed5c06784 @tim-smart committed Jun 10, 2012
Showing with 35 additions and 9 deletions.
  1. +1 −1 package.json
  2. +34 −8 test/simple.js
View
@@ -4,7 +4,7 @@
, "homepage" : "https://github.com/tim-smart/node-multipart/"
, "repository" :
{ "type" : "git"
- , "url": : "git://github.com/tim-smart/node-multipart.git"
+ , "url" : "git://github.com/tim-smart/node-multipart.git"
}
, "dependencies" :
{ "mime" : "1.2.x"
View
@@ -1,13 +1,24 @@
-var multipart = require('../')
- , fs = require('fs')
- , mp = multipart.createMultipartStream()
- , mp2 = multipart.createMultipartStream()
+var multipart = require('../')
+ , fs = require('fs')
+ , path = require('path')
+ , assert = require('assert').ok
+ , mp = multipart.createMultipartStream()
+ , mp2 = multipart.createMultipartStream()
, file
-console.log = function () {}
+// Comment for logging.
+console.log = function () {}
-process.stdout.write('HEADERS\r\n\r\n')
-mp.pipe(process.stdout)
+var PROJECTDIR = path.resolve(path.join(__dirname, '..'))
+
+var EXPECTED = fs.readFileSync(
+ PROJECTDIR + '/test/fixtures/simple-expected.txt'
+ , 'utf8'
+ )
+var OUTPUTFILE = PROJECTDIR + '/test/fixtures/simple.out'
+var OUTPUTSTREAM = fs.createWriteStream(OUTPUTFILE)
+
+mp.pipe(OUTPUTSTREAM)
mp.writeForm(
{ data :
@@ -30,7 +41,7 @@ mp.write(
}
)
-mp2.writeFile({ filename : '/tmp/js.js' }, function () {
+mp2.writeFile({ filename : PROJECTDIR + '/test/fixtures/simple-file.txt' }, function () {
console.log('FILEWRITTEN')
})
@@ -40,4 +51,19 @@ mp2.end(function () {
mp.end(function () {
console.log('DONE')
+ // Assert the output is what we are expecting.
+ var output = fs.readFileSync(OUTPUTFILE, 'utf8')
+ var error = null
+
+ try {
+ assert(EXPECTED == output)
+ } catch (err) {
+ error = err
+ }
+
+ fs.unlink(OUTPUTFILE)
+
+ if (error) {
+ throw error
+ }
})

0 comments on commit ff99dbf

Please sign in to comment.