@@ -3,7 +3,7 @@ const Koa = require('koa');
3
3
const { getRequestFromURL, App} = require ( './main' ) ;
4
4
// const { createBundleRenderer } = require('vue-server-renderer')
5
5
6
- // const JSONResponse = require('../apijson/JSONResponse');
6
+ const JSONResponse = require ( '../apijson/JSONResponse' ) ;
7
7
const StringUtil = require ( '../apijson/StringUtil' ) ;
8
8
9
9
var isCrossEnabled = true ; // false;
@@ -49,8 +49,8 @@ function update() {
49
49
deepProgress = App . deepDoneCount >= App . deepAllCount ? 1 : ( App . deepDoneCount / App . deepAllCount ) . toFixed ( 2 ) ;
50
50
randomProgress = App . randomDoneCount >= App . randomAllCount ? 1 : ( App . randomDoneCount / App . randomAllCount ) . toFixed ( 2 ) ;
51
51
// progress = accountProgress*testCaseProgress*deepProgress*randomProgress;
52
- progress = accountProgress >= 1 ? 1 : ( accountProgress + ( accountAllCount <= 0 ? 1 : 1 / accountAllCount ) * ( testCaseProgress
53
- + ( App . allCount <= 0 ? 1 : 1 / App . allCount ) * ( deepProgress + ( App . deepAllCount <= 0 ? 1 : 1 / App . deepAllCount ) * randomProgress ) ) ) ;
52
+ progress = accountProgress >= 1 ? 1 : ( accountProgress + ( accountAllCount <= 0 ? 1 : 1 / accountAllCount * ( testCaseProgress
53
+ + ( App . allCount <= 0 ? 1 : 1 / App . allCount * ( deepProgress + ( App . deepAllCount <= 0 ? 1 : 1 / App . deepAllCount * randomProgress ) ) ) ) ) ) ;
54
54
55
55
if ( progress >= 1 ) {
56
56
isLoading = false ;
@@ -66,14 +66,29 @@ function update() {
66
66
const PORT = 3002 ;
67
67
68
68
const app = new Koa ( ) ;
69
+ var done = false ;
70
+
69
71
app . use ( async ctx => {
70
- console . log ( ctx )
72
+ console . log ( ctx ) ;
73
+ var origin = ctx . get ( 'Origin' ) || ctx . get ( 'origin' ) ;
74
+ console . log ( 'origin = ' + origin ) ;
75
+ ctx . set ( 'Access-Control-Max-Age' , "1000000" ) ; // "-1");
76
+ ctx . set ( 'Access-Control-Allow-Origin' , origin ) ;
77
+ ctx . set ( 'Access-Control-Allow-Headers' , "*" ) ;
78
+ ctx . set ( 'Access-Control-Allow-Credentials' , 'true' ) ;
79
+ ctx . set ( 'Access-Control-Allow-Methods' , 'GET,HEAD,POST,PUT,DELETE,OPTIONS,TRACE' ) ;
80
+ // ctx.set('Access-Control-Expose-Headers', "*");
81
+
82
+ if ( ctx . method == null || ctx . method . toUpperCase ( ) == 'OPTIONS' ) {
83
+ ctx . status = 200 ;
84
+ return ;
85
+ }
71
86
72
87
if ( ctx . path == '/test/start' || ( isLoading != true && ctx . path == '/test' ) ) {
73
88
if ( isLoading && ctx . path == '/test/start' ) {
74
- ctx . body = 'Already started auto testing in node, please wait for minutes...' ;
75
- ctx . status = 200
76
- return
89
+ ctx . status = 200 ;
90
+ ctx . body = ctx . response . body = 'Already started auto testing in node, please wait for minutes...' ;
91
+ return ;
77
92
}
78
93
79
94
App . isCrossEnabled = isCrossEnabled ; // isCrossEnabled = App.isCrossEnabled;
@@ -115,7 +130,7 @@ app.use(async ctx => {
115
130
isCrossEnabled = App . isCrossEnabled ;
116
131
117
132
ctx . status = ctx . response . status = 200 ; // 302;
118
- ctx . body = 'Auto testing in node...' ;
133
+ ctx . body = ctx . response . body = 'Auto testing in node...' ;
119
134
120
135
// setTimeout(function () { // 延迟无效
121
136
ctx . redirect ( '/test/status' ) ;
@@ -129,7 +144,42 @@ app.use(async ctx => {
129
144
}
130
145
131
146
ctx . status = ctx . response . status = 200 ; // progress >= 1 ? 200 : 302;
132
- ctx . body = ( message || ( progress < 1 || isLoading ? 'Auto testing in node...' : 'Done auto testing in node.' ) ) + timeMsg + progressMsg ;
147
+ ctx . body = ctx . response . body = ( message || ( progress < 1 || isLoading ? 'Auto testing in node...' : 'Done auto testing in node.' ) ) + timeMsg + progressMsg ;
148
+ }
149
+ else if ( ctx . path == '/test/compare' || ctx . path == '/test/ml' ) {
150
+ done = false ;
151
+ var json = '' ;
152
+ ctx . req . addListener ( 'data' , ( data ) => {
153
+ json += data ;
154
+ } )
155
+ ctx . req . addListener ( 'end' , function ( ) {
156
+ console . log ( json ) ;
157
+ // })
158
+
159
+ var body = JSON . parse ( json ) || ctx . body || ctx . req . body || ctx . request . body || { } ;
160
+ console . log ( body ) ;
161
+ var isML = ctx . path == '/test/ml' || body . isML ;
162
+ var res = body . response ;
163
+ var stdd = body . standard ;
164
+
165
+ var response = typeof res != 'string' ? res : ( StringUtil . isEmpty ( res , true ) ? null : JSON . parse ( res ) ) ;
166
+ var standard = typeof stdd != 'string' ? stdd : ( StringUtil . isEmpty ( stdd , true ) ? null : JSON . parse ( stdd ) ) ;
167
+
168
+ console . log ( '\n\nresponse = ' + JSON . stringify ( response ) ) ;
169
+ console . log ( '\n\nstdd = ' + JSON . stringify ( stdd ) ) ;
170
+ var compare = JSONResponse . compareResponse ( standard , response || { } , '' , isML , null , null , false ) || { }
171
+ console . log ( '\n\ncompare = ' + JSON . stringify ( compare ) ) ;
172
+
173
+ ctx . status = ctx . response . status = 200 ;
174
+ ctx . body = ctx . response . body = compare == null ? '' : JSON . stringify ( compare ) ;
175
+ done = true ;
176
+ } )
177
+
178
+ while ( true ) {
179
+ if ( done ) {
180
+ break ;
181
+ }
182
+ }
133
183
}
134
184
} ) ;
135
185
0 commit comments