@@ -17,7 +17,7 @@ export interface IOptions {
1717 reporters : Reporter [ ] ;
1818}
1919
20- export interface ExampleCall {
20+ export interface Call {
2121 methodName : string ;
2222 params : any [ ] ;
2323 url : string ;
@@ -47,75 +47,75 @@ export default async (options: IOptions) => {
4747 throw new Error ( "No methods to test" ) ;
4848 }
4949
50- let exampleCalls : ExampleCall [ ] = [ ] ;
50+ let calls : Call [ ] = [ ] ;
5151
5252 let rules : Rule [ ] = [ new JsonSchemaFakerRule ( ) , new ExamplesRule ( ) ] ;
5353 if ( options . rules && options . rules . length > 0 ) {
5454 rules = options . rules ;
5555 }
5656
5757 for ( const reporter of options . reporters ) {
58- reporter . onBegin ( options , exampleCalls ) ;
58+ reporter . onBegin ( options , calls ) ;
5959 }
6060
6161 for ( const rule of rules ) {
6262 await Promise . resolve ( rule . onBegin ?.( options ) ) ;
6363 }
6464
65- // getExampleCalls could be async or sync
66- const exampleCallsPromises = await Promise . all ( filteredMethods . map ( ( method ) =>
65+ // getCalls could be async or sync
66+ const callsPromises = await Promise . all ( filteredMethods . map ( ( method ) =>
6767 Promise . all (
6868 rules . map ( async ( rule ) => {
69- const calls = await Promise . resolve ( rule . getExampleCalls ( options . openrpcDocument , method ) )
70- calls . forEach ( ( call ) => {
69+ const _calls = await Promise . resolve ( rule . getCalls ( options . openrpcDocument , method ) )
70+ _calls . forEach ( ( call ) => {
7171 // this adds the rule after the fact, it's a bit of a hack
7272 call . rule = rule ;
7373 } ) ;
74- return calls ;
74+ return _calls ;
7575 }
7676 )
7777 )
7878 ) ) ;
79- exampleCalls . push ( ...exampleCallsPromises . flat ( ) . flat ( ) ) ;
79+ calls . push ( ...callsPromises . flat ( ) . flat ( ) ) ;
8080
81- for ( const exampleCall of exampleCalls ) {
81+ for ( const call of calls ) {
8282 for ( const reporter of options . reporters ) {
83- reporter . onTestBegin ( options , exampleCall ) ;
83+ reporter . onTestBegin ( options , call ) ;
8484 }
8585 // lifecycle methods could be async or sync
86- await Promise . resolve ( exampleCall . rule ?. beforeRequest ?.( options , exampleCall ) ) ;
86+ await Promise . resolve ( call . rule ?. beforeRequest ?.( options , call ) ) ;
8787
8888 // transport is async but the await needs to happen later
8989 // so that afterRequest is run immediately after the request is made
9090 const callResultPromise = options . transport (
91- exampleCall . url ,
92- exampleCall . methodName ,
93- exampleCall . params
91+ call . url ,
92+ call . methodName ,
93+ call . params
9494 ) ;
95- await Promise . resolve ( exampleCall . rule ?. afterRequest ?.( options , exampleCall ) ) ;
95+ await Promise . resolve ( call . rule ?. afterRequest ?.( options , call ) ) ;
9696 try {
9797 const callResult = await callResultPromise ;
98- exampleCall . result = callResult . result ;
99- exampleCall . error = callResult . error ;
98+ call . result = callResult . result ;
99+ call . error = callResult . error ;
100100 } catch ( e ) {
101- exampleCall . valid = false ;
102- exampleCall . requestError = e ;
101+ call . valid = false ;
102+ call . requestError = e ;
103103 }
104- if ( exampleCall . requestError === undefined ) {
105- await Promise . resolve ( exampleCall . rule ?. validateExampleCall ( exampleCall ) ) ;
104+ if ( call . requestError === undefined ) {
105+ await Promise . resolve ( call . rule ?. validateCall ( call ) ) ;
106106 }
107- await Promise . resolve ( exampleCall . rule ?. afterResponse ?.( options , exampleCall ) ) ;
107+ await Promise . resolve ( call . rule ?. afterResponse ?.( options , call ) ) ;
108108 for ( const reporter of options . reporters ) {
109- reporter . onTestEnd ( options , exampleCall ) ;
109+ reporter . onTestEnd ( options , call ) ;
110110 }
111111 }
112112
113113 for ( const rule of rules ) {
114- await Promise . resolve ( rule . onEnd ?.( options , exampleCalls ) ) ;
114+ await Promise . resolve ( rule . onEnd ?.( options , calls ) ) ;
115115 }
116116
117117 for ( const reporter of options . reporters ) {
118- reporter . onEnd ( options , exampleCalls ) ;
118+ reporter . onEnd ( options , calls ) ;
119119 }
120- return exampleCalls ;
120+ return calls ;
121121} ;
0 commit comments