UNPKG

1.86 kBJavaScriptView Raw
1var assert = require('assert');
2
3var util = require ('util');
4var path = require ('path');
5
6var baseName = path.basename (__filename, path.extname (__filename));
7
8var flow = require ("../flow");
9
10var httpi = require ("../initiator/http");
11
12var tests = [];
13
14//process.on('uncaughtException', failure ('unhadled exception'));
15
16var config = require ("./"+baseName+".json");
17
18//var testOnly = "redirect";
19//var testOnly = "post";
20
21var verbose = false;
22
23describe (baseName + " running http presenter tests", function () {
24
25 var httpDaemon;
26
27 before (function (done) {
28 // runs before all tests in this block
29 httpDaemon = new httpi (config.initiator.http);
30 httpDaemon.on ('ready', done);
31 });
32
33 after(function() {
34 // runs after all tests in this block
35 // httpDaemon.server.close();
36 });
37
38 Object.keys (config.tests).forEach (function (token) {
39 var item = config.tests[token];
40 var method = it;
41
42 if (typeof testOnly !== "undefined" && testOnly) {
43 if (testOnly === token) {
44 method = it.only;
45 verbose = true;
46 } else {
47 return;
48 }
49 }
50
51 method (item.description ? item.description + ' ('+token+')' : token, function (done) {
52
53 var df = new flow ({
54 tasks: item.tasks,
55 templates: config.templates.task,
56 logger: verbose || "VERBOSE" in process.env ? undefined : function () {}
57 }, {
58 // dataflow parameters
59 initiator: config.initiator // for host name and port
60 });
61
62 if (!df.ready) {
63 console.log ("dataflow not ready");
64 assert (item.expect === "fail" ? true : false);
65 done ();
66 return;
67 }
68
69 df.on ('completed', function () {
70 assert (item.expect === "ok" ? true : false);
71 done ();
72 });
73
74 df.on ('failed', function () {
75 assert (item.expect === "fail" ? true : false);
76 done ();
77 });
78
79 if (item.autoRun || item.autoRun == void 0)
80 df.run();
81
82 });
83 });
84});