@@ -3,7 +3,7 @@ const Koa = require('koa');
33const { getRequestFromURL, App} = require ( './main' ) ;
44// const { createBundleRenderer } = require('vue-server-renderer')
55
6- // const JSONResponse = require('../apijson/JSONResponse');
6+ const JSONResponse = require ( '../apijson/JSONResponse' ) ;
77const StringUtil = require ( '../apijson/StringUtil' ) ;
88
99var isCrossEnabled = true ; // false;
@@ -49,8 +49,8 @@ function update() {
4949 deepProgress = App . deepDoneCount >= App . deepAllCount ? 1 : ( App . deepDoneCount / App . deepAllCount ) . toFixed ( 2 ) ;
5050 randomProgress = App . randomDoneCount >= App . randomAllCount ? 1 : ( App . randomDoneCount / App . randomAllCount ) . toFixed ( 2 ) ;
5151 // 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 ) ) ) ) ) ) ;
5454
5555 if ( progress >= 1 ) {
5656 isLoading = false ;
@@ -66,14 +66,29 @@ function update() {
6666const PORT = 3002 ;
6767
6868const app = new Koa ( ) ;
69+ var done = false ;
70+
6971app . 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+ }
7186
7287 if ( ctx . path == '/test/start' || ( isLoading != true && ctx . path == '/test' ) ) {
7388 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 ;
7792 }
7893
7994 App . isCrossEnabled = isCrossEnabled ; // isCrossEnabled = App.isCrossEnabled;
@@ -115,7 +130,7 @@ app.use(async ctx => {
115130 isCrossEnabled = App . isCrossEnabled ;
116131
117132 ctx . status = ctx . response . status = 200 ; // 302;
118- ctx . body = 'Auto testing in node...' ;
133+ ctx . body = ctx . response . body = 'Auto testing in node...' ;
119134
120135 // setTimeout(function () { // 延迟无效
121136 ctx . redirect ( '/test/status' ) ;
@@ -129,7 +144,42 @@ app.use(async ctx => {
129144 }
130145
131146 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+ }
133183 }
134184} ) ;
135185
0 commit comments