@@ -3,6 +3,8 @@ var path = require('path');
33var assert = require ( 'assert' ) ;
44var fake = require ( 'fake' ) ;
55var mime = require ( 'mime-types' ) ;
6+ var http = require ( 'http' ) ;
7+ var IncomingForm = require ( 'formidable' ) . IncomingForm ;
68
79var common = module . exports ;
810
@@ -13,7 +15,9 @@ common.dir = {
1315 tmp : path . join ( rootDir , '/test/tmp' )
1416} ;
1517
16- common . defaultTypeValue = function ( ) { return new Buffer ( [ 1 , 2 , 3 ] ) ; } ;
18+ common . defaultTypeValue = function ( ) {
19+ return new Buffer ( [ 1 , 2 , 3 ] ) ;
20+ } ;
1721
1822common . assert = assert ;
1923common . fake = fake ;
@@ -27,6 +31,25 @@ common.httpsPort = 9443;
2731common . httpsServerKey = fs . readFileSync ( path . join ( __dirname , './fixture/key.pem' ) ) ;
2832common . httpsServerCert = fs . readFileSync ( path . join ( __dirname , './fixture/cert.pem' ) ) ;
2933
34+ common . testFields = function ( FIELDS , callback ) {
35+
36+ var fieldsPassed = Object . keys ( FIELDS ) . length ;
37+
38+ return http . createServer ( function ( req , res ) {
39+
40+ var incomingForm = new IncomingForm ( { uploadDir : common . dir . tmp } ) ;
41+
42+ incomingForm . parse ( req ) ;
43+
44+ common . actions . checkForm ( incomingForm , FIELDS , function ( fieldsChecked ) {
45+ // keep track of number of the processed fields
46+ callback ( fieldsPassed - fieldsChecked ) ;
47+ // finish it
48+ common . actions . formOnEnd ( res ) ;
49+ } ) ;
50+ } ) ;
51+ } ;
52+
3053// Actions
3154
3255common . actions = { } ;
0 commit comments