Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 539 lines (454 sloc) 17.161 kb
9821eb6 Victor Jonsson initial commit...
authored
1 var filesystem = require('fs'),
2 util = require('util'),
50622d5 Victor Jonsson new version, messages about failing tests now sent to console.error
authored
3 querystring = require('querystring'),
4 colors = {
5 red : '\033[31m',
6 green : '\033[32m',
7 reset : '\033[0m'
8 };
9821eb6 Victor Jonsson initial commit...
authored
9
7ae499d Victor Jonsson wip...
authored
10
9821eb6 Victor Jonsson initial commit...
authored
11 /**
12 * @param {Object} options
13 */
14 function mergeWithDefaultOptions(options) {
66f81a6 Victor Jonsson closing in on a beta release
authored
15 if(options.url == undefined)
9821eb6 Victor Jonsson initial commit...
authored
16 throw new Error('property url missing from options');
66f81a6 Victor Jonsson closing in on a beta release
authored
17 if(options.port == undefined)
18 options.port = 80;
19 if(options.headers == undefined)
20 options.headers = {};
21 if(options.write == undefined)
22 options.write = '';
23 if(options.method == undefined)
24 options.method = 'GET';
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
25 if(options.encoding == undefined)
26 options.encoding = 'utf8';
27 if(options.keepCookies == undefined)
28 options.keepCookies = false;
7ae499d Victor Jonsson wip...
authored
29
30 if(typeof options.write != 'string')
31 options.write = querystring.stringify(options.write);
32
66f81a6 Victor Jonsson closing in on a beta release
authored
33 if(options.headers['Content-Length'] == undefined && typeof options.write == 'string')
34 options.headers['Content-Length'] = Buffer.byteLength(options.write, 'utf8');
7ae499d Victor Jonsson wip...
authored
35
66f81a6 Victor Jonsson closing in on a beta release
authored
36 if(typeof options.url == 'object')
37 options.path = querystring.stringify(options.url);
9821eb6 Victor Jonsson initial commit...
authored
38 else
66f81a6 Victor Jonsson closing in on a beta release
authored
39 options.path = options.url;
9821eb6 Victor Jonsson initial commit...
authored
40
66f81a6 Victor Jonsson closing in on a beta release
authored
41 if(options.headers['User-Agent'] == undefined)
42 options['User-Agent'] = 'node dokimon scraper';
7ae499d Victor Jonsson wip...
authored
43
44 if(options.timeout == undefined)
45 options.timeout = 8000;
9821eb6 Victor Jonsson initial commit...
authored
46 }
47
48
49 /** * * * * * * * * * * * * * * * * * * * * * * * *
50 * @class {TestManager}
51 * @param {Object} config
52 * @param {Function} testFinishCallback - Optional
53 * * * * * * * * * * * * * * * * * * * * * * * * */
54 var TestManager = function(config, testFinishCallback) {
55
df79ae9 Victor Jonsson release of version 0.1.4
authored
56 if( config.path === undefined )
57 config.path = false;
58
9821eb6 Victor Jonsson initial commit...
authored
59 this.index = 0;
60 this.successes = [];
61 this.fails = [];
62 this.tests = [];
c844427 Victor Jonsson New feature, issue #1
authored
63 this.executed = [];
9821eb6 Victor Jonsson initial commit...
authored
64
65 /**
66 * Wrapper that makes it possible to handle the
67 * message with something other then console.log
68 *
69 * @param {String} message
50622d5 Victor Jonsson new version, messages about failing tests now sent to console.error
authored
70 * @param {Boolean} [error]
9821eb6 Victor Jonsson initial commit...
authored
71 */
50622d5 Victor Jonsson new version, messages about failing tests now sent to console.error
authored
72 this.log = function(message, error) {
9821eb6 Victor Jonsson initial commit...
authored
73 if(config.log)
50622d5 Victor Jonsson new version, messages about failing tests now sent to console.error
authored
74 config.log(message, error);
75 else {
76 if(error)
77 console.error(message);
78 else
79 console.log(message)
80 }
9821eb6 Victor Jonsson initial commit...
authored
81 };
82
83 /**
7c6efcd Victor Jonsson work in progress...
authored
84 * @param {Test[]} tests
9821eb6 Victor Jonsson initial commit...
authored
85 */
86 this.setTests = function(tests) {
7c6efcd Victor Jonsson work in progress...
authored
87 this.tests = tests;
9821eb6 Victor Jonsson initial commit...
authored
88 };
89
90 /**
91 * Runs tests starting from current position of this.index
92 */
93 this.run = function() {
c844427 Victor Jonsson New feature, issue #1
authored
94 if(this.index == 0) {
95 this.executed = [];
96 }
97
98 var _self = this;
9821eb6 Victor Jonsson initial commit...
authored
99 if(config.verbose)
100 this.log('Running scripts starting from '+this.index);
101
c844427 Victor Jonsson New feature, issue #1
authored
102 var callBlockingTest = function(currentIndex) {
103 if(config.verbose)
104 _self.log('Blocking upcoming tests on index '+currentIndex+' for '+_self.tests[currentIndex].name);
105
106 _self.index = currentIndex+1;
107 _self.tests[currentIndex].execute(config.host, _self, config.verbose, function() {
108 _self.run();
df79ae9 Victor Jonsson release of version 0.1.4
authored
109 }, config.path);
c844427 Victor Jonsson New feature, issue #1
authored
110 };
111
9821eb6 Victor Jonsson initial commit...
authored
112 for(var i=this.index; i < this.tests.length; i++) {
c844427 Victor Jonsson New feature, issue #1
authored
113 var dependingTest = this.tests[i].options.dependsOn;
df79ae9 Victor Jonsson release of version 0.1.4
authored
114 if( dependingTest && this.executed.indexOf(dependingTest) == -1 ) {
c844427 Victor Jonsson New feature, issue #1
authored
115
df79ae9 Victor Jonsson release of version 0.1.4
authored
116 this.log('# -> Running depending test "'+dependingTest+'"');
c844427 Victor Jonsson New feature, issue #1
authored
117
118 this._doRunSingleTest(dependingTest, config.verbose, function() {
119 if(_self.tests[i].blocking) {
120 callBlockingTest(i);
121 }
122 else {
df79ae9 Victor Jonsson release of version 0.1.4
authored
123 this.tests[i].execute(config.host, _self, config.verbose, false, config.path);
c844427 Victor Jonsson New feature, issue #1
authored
124 _self.run();
125 }
9821eb6 Victor Jonsson initial commit...
authored
126 });
c844427 Victor Jonsson New feature, issue #1
authored
127
9821eb6 Victor Jonsson initial commit...
authored
128 break;
c844427 Victor Jonsson New feature, issue #1
authored
129
130 }
131 else {
132 // blocking request
133 if(this.tests[i].blocking) {
134 callBlockingTest(i);
135 break;
136 }
137 else
df79ae9 Victor Jonsson release of version 0.1.4
authored
138 this.tests[i].execute(config.host, this, config.verbose, false, config.path);
9821eb6 Victor Jonsson initial commit...
authored
139 }
140 }
141 };
142
143 /**
144 * Run a specific test in the test list
145 *
146 * @param {String} testName
147 */
df79ae9 Victor Jonsson release of version 0.1.4
authored
148 this.runTest = function(testName) {
c844427 Victor Jonsson New feature, issue #1
authored
149 this.executed = [];
df79ae9 Victor Jonsson release of version 0.1.4
authored
150 this._doRunSingleTest(testName, config.verbose);
c844427 Victor Jonsson New feature, issue #1
authored
151 };
152
153 /**
154 * @param name
155 * @param verbose
156 * @param callback
157 * @private
158 */
159 this._doRunSingleTest = function(name, verbose, callback) {
df79ae9 Victor Jonsson release of version 0.1.4
authored
160 var test = this.getTestByName(name);
161 var dependingTest = test.options.dependsOn;
162
163 if( dependingTest && this.executed.indexOf(dependingTest) == -1 ) {
164 var _self = this;
165 this.log('# -> Running depending test "'+dependingTest+'"');
166 this._doRunSingleTest(dependingTest, verbose, function() {
167 test.execute(config.host, _self, verbose, function() {
168 if( typeof callback == 'function' ) {
169 callback();
170 }
171 }, config.path);
172 });
173 }
174 else {
175 test.execute(config.host, this, verbose, function() {
176 if( typeof callback == 'function' ) {
177 callback();
178 }
179 }, config.path);
180 }
181 };
182
183 /**
184 * @param {String} name
185 * @return {Test}
186 */
187 this.getTestByName = function(name) {
9821eb6 Victor Jonsson initial commit...
authored
188 for(var i=0; i < this.tests.length; i++) {
c844427 Victor Jonsson New feature, issue #1
authored
189 if(this.tests[i].name == name) {
df79ae9 Victor Jonsson release of version 0.1.4
authored
190 return this.tests[i];
9821eb6 Victor Jonsson initial commit...
authored
191 }
192 }
193
c844427 Victor Jonsson New feature, issue #1
authored
194 throw new Error('Test "'+name+'" not found');
9821eb6 Victor Jonsson initial commit...
authored
195 };
196
197 /**
198 * @param {Object} success
199 */
c844427 Victor Jonsson New feature, issue #1
authored
200 this.registerSuccessfulTest = function(success) {
9821eb6 Victor Jonsson initial commit...
authored
201 this.successes.push(success);
202 this.log('* '+success.name + ' successfull');
203 _checkIfFinished(this);
204 };
205
206 /**
207 * @param {Object} fail
208 * @param {Error} err - Optional
209 */
c844427 Victor Jonsson New feature, issue #1
authored
210 this.registerFailedTest = function(fail, err) {
9821eb6 Victor Jonsson initial commit...
authored
211 this.fails.push(fail);
50622d5 Victor Jonsson new version, messages about failing tests now sent to console.error
authored
212 this.log('- '+fail.name + " FAILED! \n"+fail.message, true);
9821eb6 Victor Jonsson initial commit...
authored
213 if(err)
214 this.log(err);
7ae499d Victor Jonsson wip...
authored
215 this.log('');
9821eb6 Victor Jonsson initial commit...
authored
216 _checkIfFinished(this);
217 };
218
219 /**
220 * Get the correct path to script. Throws error if not exists
221 *
222 * @param {String} name
223 * @return {String}
224 */
225 this.scriptNameToPath = function(name) {
226 var testFileName = name.substring(0, config.testdir.length) == config.testdir ? name : config.testdir+'/'+name;
227 if(!_hasDokimonExtension(testFileName))
228 testFileName += TestManager.TEST_EXTENSION;
229
230 return testFileName;
231 };
232
233 /**
234 * Get a list of all available scripts in given directory
235 *
236 * @param {String} path
237 * @return {Array}
238 */
239 this.loadScriptsInDir = function(path) {
240 var scripts = [];
241 filesystem.readdirSync(path).forEach(function(f) {
242 if(_hasDokimonExtension(f))
243 scripts.push(f.substr(0, f.length - TestManager.TEST_EXTENSION.length));
244 });
245 return scripts;
246 };
247
248 /**
249 * Will output test result to client when test i finished
250 *
251 * @access private
252 * @param {TestManager} manager
253 */
254 var _checkIfFinished = function(manager) {
255 if(manager.tests.length == (manager.successes.length + manager.fails.length)) {
256 if(manager.fails.length == 0) {
50622d5 Victor Jonsson new version, messages about failing tests now sent to console.error
authored
257 manager.log("\n------------------------------\n"+colors.green+"Everything is fine :)"+colors.reset);
9821eb6 Victor Jonsson initial commit...
authored
258 manager.log('Executed a total of '+manager.successes.length+' successfull tests');
259 }
260 else {
50622d5 Victor Jonsson new version, messages about failing tests now sent to console.error
authored
261 manager.log("\n------------------------------\n"+colors.red+"All is not well :("+colors.reset, true);
262 manager.log(manager.successes.length+' test'+(manager.successes.length > 1 ? 's':'')+' was successfull', true);
263 manager.log(manager.fails.length+' test'+(manager.fails.length > 1 ? 's':'')+' failed', true);
7ae499d Victor Jonsson wip...
authored
264 for(var i=0; i < manager.fails.length; i++)
50622d5 Victor Jonsson new version, messages about failing tests now sent to console.error
authored
265 manager.log(" - "+manager.fails[i].name+" ("+manager.fails[i].message+")", true);
9821eb6 Victor Jonsson initial commit...
authored
266 }
267
268 manager.log("");
269 if(typeof testFinishCallback == 'function')
270 testFinishCallback(manager);
271 }
272 };
273
274 /**
275 * @access private
276 * @param {String} path
277 * @return {Boolean}
278 */
279 var _hasDokimonExtension = function(path) {
280 return path.substr(-1 * TestManager.TEST_EXTENSION.length) == TestManager.TEST_EXTENSION;
281 };
282 };
283
284
285 /**
286 * Extension for scripts containing tests
287 */
e706f86 Victor Jonsson changed test files extensions to .djs
authored
288 TestManager.TEST_EXTENSION = '.djs';
9821eb6 Victor Jonsson initial commit...
authored
289
290
291 /** * * * * * * * * * * * * * * * * * * * * * * * *
292 * @class {Test}
293 * @param {String} testName - Name of this test
294 * @param {Object} options - requires url, optional is port:Number, method:String, write:String and headers:Object
295 * @param {Function} callback - function(response, body)
296 * @param {Boolean} blocking - Optional, whether or not this test is supposed to finish before running any other tests
297 * * * * * * * * * * * * * * * * * * * * * * * * */
298 var Test = function(testName, options, callback, blocking) {
299
66f81a6 Victor Jonsson closing in on a beta release
authored
300 mergeWithDefaultOptions(options);
9821eb6 Victor Jonsson initial commit...
authored
301
c844427 Victor Jonsson New feature, issue #1
authored
302 this.options = options;
9821eb6 Victor Jonsson initial commit...
authored
303 this.blocking = blocking;
304 this.name = testName;
305
306 /**
7c6efcd Victor Jonsson work in progress...
authored
307 * @param {TestManager} manager
c844427 Victor Jonsson New feature, issue #1
authored
308 * @param {String} host
309 * @param {Boolean} [verbose] - Optional
310 * @param {Function} [callback] - Optional, will be called when request is finished and test callback is called
9821eb6 Victor Jonsson initial commit...
authored
311 */
df79ae9 Victor Jonsson release of version 0.1.4
authored
312 this.execute = function(host, manager, verbose, callback, basePath) {
c844427 Victor Jonsson New feature, issue #1
authored
313
314 var exeFinishCallback = function() {
315 manager.executed.push(testName);
316 if( typeof callback == 'function' )
317 callback();
318 };
9821eb6 Victor Jonsson initial commit...
authored
319
320 options.host = host;
df79ae9 Victor Jonsson release of version 0.1.4
authored
321 if( basePath && options.path.indexOf(basePath) !== 0)
322 options.path = basePath+options.path;
9821eb6 Victor Jonsson initial commit...
authored
323
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
324 if(options.keepCookies && Test.lastCookies)
325 options.headers['Cookie'] = Test.lastCookies;
326
9821eb6 Victor Jonsson initial commit...
authored
327 if(verbose)
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
328 manager.log("About to request "+host+" for "+testName+" with \n"+_formatJSON(options)+"\n");
9821eb6 Victor Jonsson initial commit...
authored
329
c844427 Victor Jonsson New feature, issue #1
authored
330 var _self = this;
7ae499d Victor Jonsson wip...
authored
331
9821eb6 Victor Jonsson initial commit...
authored
332 var req = require('http').request(options, function(res) {
333 var collectedBody = '';
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
334 res.setEncoding(options.encoding);
9821eb6 Victor Jonsson initial commit...
authored
335 res.on('data', function (body) {
336 collectedBody += body;
337 });
338 res.on('end', function() {
7ae499d Victor Jonsson wip...
authored
339
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
340 if(verbose)
341 manager.log(testName+" recieved response from "+options.host+options.path+" "+_formatJSON(res.headers)+"\n");
342
343 if(res.headers['set-cookie'] != undefined)
9b45b3e Victor Jonsson new release, v 0.0.17
authored
344 Test.lastCookies = _setToGetCookies(res.headers['set-cookie'], Test.lastCookies ? Test.lastCookies:'');
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
345
346 var loc = res.headers.location == undefined ? res.headers.Location : res.headers.location;
df79ae9 Victor Jonsson release of version 0.1.4
authored
347 if(loc) {
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
348
c844427 Victor Jonsson New feature, issue #1
authored
349 if( loc.indexOf('/') !== 0 )
350 loc = '/'+loc;
351
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
352 if(verbose)
353 manager.log('Redirecting '+testName+' to '+loc);
7ae499d Victor Jonsson wip...
authored
354
355 options.method = 'GET';
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
356 options.headers['Content-Length'] = 0;
7ae499d Victor Jonsson wip...
authored
357 options.write = '';
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
358 options.path = loc;
df79ae9 Victor Jonsson release of version 0.1.4
authored
359
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
360 if(options.path.indexOf(options.host) > -1) {
361 options.path = options.path.split(options.host)[1];
9b45b3e Victor Jonsson new release, v 0.0.17
authored
362 options.url = options.path;
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
363 }
7ae499d Victor Jonsson wip...
authored
364
df79ae9 Victor Jonsson release of version 0.1.4
authored
365 _self.execute(options.host, manager, verbose, exeFinishCallback, basePath);
7c6efcd Victor Jonsson work in progress...
authored
366 }
7ae499d Victor Jonsson wip...
authored
367 else {
368
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
369 res.url = options.path;
370
371 try {
df79ae9 Victor Jonsson release of version 0.1.4
authored
372 _self.runCallback(res, collectedBody, manager);
c844427 Victor Jonsson New feature, issue #1
authored
373 manager.registerSuccessfulTest({name : testName, message:''});
83bb576 Victor Jonsson Fixed bug that callback function wasnt always called when test failed, a...
authored
374 exeFinishCallback();
7ae499d Victor Jonsson wip...
authored
375 }
376 catch(e) {
c844427 Victor Jonsson New feature, issue #1
authored
377 manager.registerFailedTest({name : testName, message:e.message}, e);
83bb576 Victor Jonsson Fixed bug that callback function wasnt always called when test failed, a...
authored
378 exeFinishCallback();
7ae499d Victor Jonsson wip...
authored
379 }
7c6efcd Victor Jonsson work in progress...
authored
380 }
9821eb6 Victor Jonsson initial commit...
authored
381 });
382 });
383
384 req.on('error', function(e) {
c844427 Victor Jonsson New feature, issue #1
authored
385 manager.registerFailedTest({name : testName, message:''}, e);
83bb576 Victor Jonsson Fixed bug that callback function wasnt always called when test failed, a...
authored
386 exeFinishCallback();
9821eb6 Victor Jonsson initial commit...
authored
387 });
388
83bb576 Victor Jonsson Fixed bug that callback function wasnt always called when test failed, a...
authored
389 if(req.connection != undefined) {
390 req.connection.setTimeout(options.timeout, function() {
c844427 Victor Jonsson New feature, issue #1
authored
391 manager.registerFailedTest({name: testName, message : 'Timeout after '+options.timeout+' ms'}, '');
83bb576 Victor Jonsson Fixed bug that callback function wasnt always called when test failed, a...
authored
392 req.abort();
7ae499d Victor Jonsson wip...
authored
393 exeFinishCallback();
83bb576 Victor Jonsson Fixed bug that callback function wasnt always called when test failed, a...
authored
394 });
395 }
7ae499d Victor Jonsson wip...
authored
396
9821eb6 Victor Jonsson initial commit...
authored
397 req.write(options.write);
398 req.end();
399 };
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
400
401 /**
402 * Runs the test callback when request is finished
403 * @param {Object} res
404 * @param {String} collectedBody
df79ae9 Victor Jonsson release of version 0.1.4
authored
405 * @param {TestManager} manager
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
406 */
df79ae9 Victor Jonsson release of version 0.1.4
authored
407 this.runCallback = function(res, collectedBody,manager) {
408 callback(res, collectedBody, manager);
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
409 };
410
411 /**
412 * @access private
413 * @param {Array} responseCookies
9b45b3e Victor Jonsson new release, v 0.0.17
authored
414 * @param {String} currentCookies
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
415 * @return {String}
416 */
9b45b3e Victor Jonsson new release, v 0.0.17
authored
417 var _setToGetCookies = function(responseCookies, currentCookies) {
418 var currentCookiesObj = {};
419 var currentCookieParts = currentCookies.split(';');
420 var cookies = '', i;
421
422 // Build up an object with all current cookies
423 for(i=0; i < currentCookieParts.length; i++) {
424 var p = currentCookieParts[i].split('=');
425 if(p.length > 1)
426 currentCookiesObj[p[0].trim()] = p[1].trim();
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
427 }
428
9b45b3e Victor Jonsson new release, v 0.0.17
authored
429
430 // Go through repsonse cookies and determine which
431 // has expired or new cookies
432 var now = new Date().getTime();
433 for(i=0; i < responseCookies.length; i++) {
434 var cookieParts = responseCookies[i].split(';');
435 var cookieName = cookieParts[0].split('=')[0];
436 if(typeof currentCookiesObj[cookieName] != 'undefined') {
437 // maybe expired
438 for(var j=0; j < cookieParts.length; j++) {
439 var cookieArgs = cookieParts[j].split('=');
440 if(cookieArgs[0] == 'expires') {
441 var d = new Date(cookieArgs[0]);
442 if(d.getTime() < now) {
443 currentCookiesObj[cookieName] = false;
444 }
445 }
446 }
447 }
448
449 cookies += '; '+cookieParts[0];
450 }
451
452 // Append previous cookies (which is not deleted by expire argument)
453 Object.keys(currentCookiesObj).forEach(function(k) {
454 var val = currentCookiesObj[k];
455 if(val)
456 cookies += '; '+k+'='+val;
457 });
458
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
459 return cookies.length == 0 ? '': cookies.substr(2, cookies.length);
460 };
461
462 /**
463 * @access private
464 * @param {Object} json
465 * @return {String}
466 */
467 var _formatJSON = function(json) {
468 var str = JSON.stringify(json);
469 if(str == '[object Object]') {
470 str = '';
471 for(var x in json) {
472 var type = typeof(json[x]);
473 str += type +" : "+( type == 'string' || type == 'number' ? json[x]:json[x].toString())+"\n";
474 }
475 }
476
477 return str.replace(/\,\"/g, ",\n\"");
478 };
9821eb6 Victor Jonsson initial commit...
authored
479 };
480
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
481 /**
83bb576 Victor Jonsson Fixed bug that callback function wasnt always called when test failed, a...
authored
482 * @var {Boolean|String}
bec465f Victor Jonsson TestPostForm bug fixes, now possible to maintain a server session
authored
483 */
484 Test.lastCookies = false;
9821eb6 Victor Jonsson initial commit...
authored
485
83bb576 Victor Jonsson Fixed bug that callback function wasnt always called when test failed, a...
authored
486
9821eb6 Victor Jonsson initial commit...
authored
487 /** * * * * * * * * * * * * * * * * * * * * * * * *
488 * @class {TestFormPost}
489 * @param {String} testName - Name of this test
490 * @param {Object} options - requires url, optional is port:Number, method:String, write:String and headers:Object
491 * @param {Function} callback - function(response, body)
492 * @param {Boolean} blocking - Optional, whether or not this test is supposed to finish before running any other tests
493 * * * * * * * * * * * * * * * * * * * * * * * * */
494 var TestFormPost = function(testName, options, callback, blocking) {
7ae499d Victor Jonsson wip...
authored
495
496 TestFormPost.super_.call(this, testName, options, callback, blocking);
497
9821eb6 Victor Jonsson initial commit...
authored
498 options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
499 if(typeof(options.write) == 'object')
500 options.write = querystring.stringify(options.write);
501
502 options.headers['Content-Length'] = Buffer.byteLength(options.write, 'utf8');
503
7ae499d Victor Jonsson wip...
authored
504 options.method = 'POST';
9821eb6 Victor Jonsson initial commit...
authored
505 };
506 util.inherits(TestFormPost, Test);
507
508
509 module.exports = {
510
511 /**
512 * @param {Object} config
513 * @return {TestManager}
514 */
515 TestManager : TestManager,
516
517 /**
518 * @return {Test}
519 */
520 Test : Test,
521
522 /**
66f81a6 Victor Jonsson closing in on a beta release
authored
523 * @return {TestFormPost}
524 */
525 TestFormPost: TestFormPost,
526
527 /**
9821eb6 Victor Jonsson initial commit...
authored
528 * @param {Test} t
83bb576 Victor Jonsson Fixed bug that callback function wasnt always called when test failed, a...
authored
529 * @param {Object} config
530 * @param {Function} testFinishCallback - Optional
9821eb6 Victor Jonsson initial commit...
authored
531 */
532 runTest : function(t, config, testFinishCallback) {
533 var manager = new TestManager(config, testFinishCallback);
534 manager.setTests([t]);
535 manager.run();
536 },
537
538 TEST_EXTENSION : TestManager.TEST_EXTENSION
539 };
Something went wrong with that request. Please try again.