@@ -6,148 +6,154 @@ var cp=require('child_process');
6
6
var path=require('path');
7
7
var optimist=require('optimist');
8
8
var colors=require('colors');
9
+ var common=require('hopjs-common');
9
10
10
- optimist=optimist.describe("url","url to use for testing");
11
- optimist=optimist.describe("log","log file");
12
-
13
- var args = optimist.argv;
14
-
15
- var url = args.url||"http://localhost:3000/";
16
-
17
- var results={};
18
-
19
- var testExample=function(example,onComplete){
20
- var dir = path.join("./examples",example);
21
-
22
- console.log("Testing example",example);
23
- cp.exec("(cd "+dir+" && rm -rf node_modules && npm install .)",function(err,stdout,stderr){
24
- if(err) return onComplete("Error installing package:"+err);
25
-
26
- var exited=false;
27
- var testNumber=0;
28
-
29
- var appRunning=true;
30
-
31
- console.log("Starting application");
32
- var app = cp.spawn("node",["./app.js"],{ cwd: dir });
33
-
34
- app.on("exit",function(code,data){
35
- console.log("Example application exited with:",code);
36
- appRunning=false;
37
- });
38
-
39
- var appOut="";
40
-
41
- app.on("close",function(code,data){
42
- //console.log("A",arguments);
43
- });
44
-
45
- app.stderr.on("data",function(data){
46
- appOut+=data;
47
- });
48
-
49
- app.stdout.on("data",function(data){
50
- appOut+=data;
51
- });
52
-
53
- setTimeout(function(){
54
-
55
-
56
-
57
-
58
- if(!appRunning){
59
- console.error(appOut);
60
- return onComplete("Application quit before being tested");
61
- }
62
-
63
- var unitTest = cp.exec("hopjs --url "+url+" --unitTest --testDetails");
64
-
65
- var unitTestErr="";
66
- var unitTestOut="";
67
-
68
- unitTest.on("close",function(code,data){
69
-
70
- if(args.log){
71
- fs.appendFileSync(args.log,"\n"+example+": ########################################################\n");
72
- fs.appendFileSync(args.log,"\n"+example+": APP OUT ---------------------------------------------\n");
73
- fs.appendFileSync(args.log,appOut);
74
- fs.appendFileSync(args.log,"\n"+example+": TEST STDOUT ---------------------------------------------\n");
75
- fs.appendFileSync(args.log,unitTestOut);
76
- fs.appendFileSync(args.log,"\n"+example+": TEST STDERR ---------------------------------------------\n");
77
- fs.appendFileSync(args.log,unitTestErr);
78
- }
79
- app.kill();
80
- console.log("Unit test exited with",code);
81
- results[example]={ exitCode:code }
82
-
83
- var m = /^Pass.*$/gm.exec(unitTestOut);
84
- if(m){
85
- results[example].results=m[0];
86
- }
87
-
88
- app.kill("SIGKILL");
89
- cp.exec("kill -9 "+app.pid);
90
-
91
- var waitForAppExit=function(){
92
- if(appRunning){
93
- setTimeout(waitForAppExit,200);
94
- } else {
95
- return onComplete();
96
- }
97
- }
98
- waitForAppExit();
99
- });
100
-
101
- unitTest.stderr.on("data",function(data){
102
- console.log(data.toString());
103
- });
104
-
105
- unitTest.stdout.on("data",function(data){
106
- console.log(data);
107
- unitTestOut+=data;
108
- var m = /^#([0-9]+)/gm.exec(data);
109
- if(m){
110
- testNumber=m[1];
111
- }
112
- });
113
-
114
- },3000);
115
-
116
-
117
- });
118
-
119
- }
120
-
121
- fs.readdir("./examples",function(err,examples){
122
- var run=function(){
123
- if(examples.length>0){
124
- var example = examples.shift();
125
- testExample(example,function(err,res){
126
- if(err){
127
- console.error(err,example);
128
- process.exit();
129
- }
130
- run();
131
- })
132
- } else {
133
- console.log("--------------------------");
134
- var str="";
135
- for(var i in results){
136
- console.log(i+":");
137
- str+="#"+i+":\n";
138
- if(results[i].results){
139
- console.log("\t",results[i].results);
140
- str+="\t"+results[i].results.toString()+"\n";
141
- } else {
142
- console.log("\t exited with",results[i].exitCode)
143
- str+=("\t exited with "+results[i].exitCode+"\n");
11
+ common.requireOnDemand(['hopjs-remote'],function(){
12
+
13
+ optimist=optimist.describe("url","url to use for testing");
14
+ optimist=optimist.describe("log","log file");
15
+
16
+ var args = optimist.argv;
17
+
18
+ var url = args.url||"http://localhost:3000/";
19
+
20
+ var results={};
21
+
22
+ var testExample=function(example,onComplete){
23
+ var dir = path.join("./examples",example);
24
+
25
+ console.log("Testing example",example);
26
+ cp.exec("(cd "+dir+" && rm -rf node_modules && npm install .)",function(err,stdout,stderr){
27
+ if(err) return onComplete("Error installing package:"+err);
28
+
29
+ var exited=false;
30
+ var testNumber=0;
31
+
32
+ var appRunning=true;
33
+
34
+ console.log("Starting application");
35
+ var app = cp.spawn("node",["./app.js"],{ cwd: dir });
36
+
37
+ app.on("exit",function(code,data){
38
+ console.log("Example application exited with:",code);
39
+ appRunning=false;
40
+ });
41
+
42
+ var appOut="";
43
+
44
+ app.on("close",function(code,data){
45
+ //console.log("A",arguments);
46
+ });
47
+
48
+ app.stderr.on("data",function(data){
49
+ appOut+=data;
50
+ });
51
+
52
+ app.stdout.on("data",function(data){
53
+ appOut+=data;
54
+ });
55
+
56
+ setTimeout(function(){
57
+
58
+
59
+
60
+
61
+ if(!appRunning){
62
+ console.error(appOut);
63
+ return onComplete("Application quit before being tested");
144
64
}
145
- }
146
- fs.writeFileSync("testresults.md",str);
147
- process.exit();
148
- }
149
- }
150
- run();
151
65
152
- });
66
+ var hopjsPath = path.join(__dirname,"node_modules","hopjs-remote","bin","hopjs");
67
+
68
+ var unitTest = cp.exec(hopjsPath+" --url "+url+" --unitTest --testDetails");
69
+
70
+ var unitTestErr="";
71
+ var unitTestOut="";
72
+
73
+ unitTest.on("close",function(code,data){
74
+
75
+ if(args.log){
76
+ fs.appendFileSync(args.log,"\n"+example+": ########################################################\n");
77
+ fs.appendFileSync(args.log,"\n"+example+": APP OUT ---------------------------------------------\n");
78
+ fs.appendFileSync(args.log,appOut);
79
+ fs.appendFileSync(args.log,"\n"+example+": TEST STDOUT ---------------------------------------------\n");
80
+ fs.appendFileSync(args.log,unitTestOut);
81
+ fs.appendFileSync(args.log,"\n"+example+": TEST STDERR ---------------------------------------------\n");
82
+ fs.appendFileSync(args.log,unitTestErr);
83
+ }
84
+ app.kill();
85
+ console.log("Unit test exited with",code);
86
+ results[example]={ exitCode:code }
87
+
88
+ var m = /^Pass.*$/gm.exec(unitTestOut);
89
+ if(m){
90
+ results[example].results=m[0];
91
+ }
92
+
93
+ app.kill("SIGKILL");
94
+ cp.exec("kill -9 "+app.pid);
95
+
96
+ var waitForAppExit=function(){
97
+ if(appRunning){
98
+ setTimeout(waitForAppExit,200);
99
+ } else {
100
+ return onComplete();
101
+ }
102
+ }
103
+ waitForAppExit();
104
+ });
105
+
106
+ unitTest.stderr.on("data",function(data){
107
+ console.log(data.toString());
108
+ });
109
+
110
+ unitTest.stdout.on("data",function(data){
111
+ console.log(data);
112
+ unitTestOut+=data;
113
+ var m = /^#([0-9]+)/gm.exec(data);
114
+ if(m){
115
+ testNumber=m[1];
116
+ }
117
+ });
118
+
119
+ },3000);
120
+
121
+
122
+ });
123
+
124
+ }
125
+
126
+ fs.readdir("./examples",function(err,examples){
127
+ var run=function(){
128
+ if(examples.length>0){
129
+ var example = examples.shift();
130
+ testExample(example,function(err,res){
131
+ if(err){
132
+ console.error(err,example);
133
+ process.exit();
134
+ }
135
+ run();
136
+ })
137
+ } else {
138
+ console.log("--------------------------");
139
+ var str="";
140
+ for(var i in results){
141
+ console.log(i+":");
142
+ str+="#"+i+":\n";
143
+ if(results[i].results){
144
+ console.log("\t",results[i].results);
145
+ str+="\t"+results[i].results.toString()+"\n";
146
+ } else {
147
+ console.log("\t exited with",results[i].exitCode)
148
+ str+=("\t exited with "+results[i].exitCode+"\n");
149
+ }
150
+ }
151
+ fs.writeFileSync("testresults.md",str);
152
+ process.exit();
153
+ }
154
+ }
155
+ run();
156
+
157
+ });
153
158
159
+ });
0 commit comments