11import { Framework } from './Framework' ;
22import { SourceMap } from '../sourcemap/SourceMap' ;
33import { Message , Request } from '../messaging/Message' ;
4- import { Testbed } from '../testbeds/Testbed' ;
4+ import { Testbed , TestbedEvents } from '../testbeds/Testbed' ;
55import { TestbedFactory } from '../testbeds/TestbedFactory' ;
66import { Kind } from './scenario/Step' ;
77import { SourceMapFactory } from '../sourcemap/SourceMapFactory' ;
@@ -11,6 +11,7 @@ import {CompileOutput, CompilerFactory} from '../manage/Compiler';
1111import { WABT } from '../util/env' ;
1212import { Completion , expect , Result , ScenarioResult , SuiteResults } from './Reporter' ;
1313import { WASM } from '../sourcemap/Wasm' ;
14+ import { DummyProxy } from '../testbeds/Emulator' ;
1415
1516export function timeout < T > ( label : string , time : number , promise : Promise < T > ) : Promise < T > {
1617 if ( time === 0 ) {
@@ -70,7 +71,7 @@ export class Testee { // TODO unified with testbed interface
7071
7172 private testbed ?: Testbed ;
7273
73- private proxy ?: Testbed ;
74+ private proxy ?: DummyProxy ;
7475
7576 private current ?: string ; // current program
7677
@@ -94,20 +95,33 @@ export class Testee { // TODO unified with testbed interface
9495 const proxy : Testbed | void = await this . connector . initialize ( spec , program , args ?? [ ] ) . catch ( ( e ) => {
9596 reject ( e )
9697 } ) ;
97- if ( proxy ) {
98- this . proxy = proxy ;
99- await this . proxy . sendRequest ( new SourceMap . Mapping ( ) , Message . proxifyRequest ) ;
100- args = args . concat ( [ '--proxy' , `${ spec . dummy . port } ` ] ) ;
98+
99+ if ( ! proxy ) {
100+ return ;
101101 }
102- }
103102
104- const testbed : Testbed | void = await this . connector . initialize ( this . specification , program , args ) . catch ( ( e ) => {
105- reject ( e )
106- } ) ;
107- if ( testbed ) {
108- this . testbed = testbed ;
103+ this . proxy = proxy as DummyProxy ;
104+ this . proxy . on ( TestbedEvents . Ready , ( ) => {
105+ resolve ( this ) ;
106+ } ) ;
107+ await this . proxy . sendRequest ( new SourceMap . Mapping ( ) , Message . proxifyRequest ) ;
108+ args = args . concat ( [ '--proxy' , `${ spec . dummy . port } ` ] ) ;
109+
110+ const testbed : Testbed | void = await this . connector . initialize ( this . specification , program , args ) . catch ( ( e ) => {
111+ reject ( e ) ;
112+ } ) ;
113+ if ( testbed ) {
114+ this . testbed = testbed ;
115+ }
116+ } else {
117+ const testbed : Testbed | void = await this . connector . initialize ( this . specification , program , args ) . catch ( ( e ) => {
118+ reject ( e )
119+ } ) ;
120+ if ( testbed ) {
121+ this . testbed = testbed ;
122+ }
123+ resolve ( this ) ;
109124 }
110- resolve ( this ) ;
111125 } ) ;
112126 }
113127
@@ -159,16 +173,22 @@ export class Testee { // TODO unified with testbed interface
159173 } catch ( e ) {
160174 await testee . initialize ( description . program , description . args ?? [ ] ) . catch ( ( o ) => Promise . reject ( o ) ) ;
161175 }
162- } ) . catch ( ( e : Error | string ) => {
163- if ( typeof e === 'string' ) scenarioResult . error = new Error ( e ) ;
164- else scenarioResult . error = e ;
176+ } ) . catch ( ( e : Error | string ) => {
177+ if ( typeof e === 'string' ) {
178+ scenarioResult . error = new Error ( e ) ;
179+ } else {
180+ scenarioResult . error = e ;
181+ }
165182 } ) ;
166183
167184 await this . run ( 'Get source mapping' , testee . connector . timeout , async function ( ) {
168185 map = await testee . mapper . map ( description . program ) ;
169- } ) . catch ( ( e : Error | string ) => {
170- if ( typeof e === 'string' ) scenarioResult . error = new Error ( e ) ;
171- else scenarioResult . error = e ;
186+ } ) . catch ( ( e : Error | string ) => {
187+ if ( typeof e === 'string' ) {
188+ scenarioResult . error = new Error ( e ) ;
189+ } else {
190+ scenarioResult . error = e ;
191+ }
172192 } ) ;
173193
174194 if ( scenarioResult . error ) {
0 commit comments