11import { expect } from "chai" ;
22import { RefObject } from "react" ;
33import { emptyMutex , RuntimeContext , RuntimeLang } from "./runtime" ;
4+ import { ReplOutput } from "./repl" ;
45
56export function defineTests (
67 lang : RuntimeLang ,
@@ -42,10 +43,8 @@ export function defineTests(
4243 if ( ! printCode ) {
4344 this . skip ( ) ;
4445 }
45- const outputs : any [ ] = [ ] ;
46- await (
47- runtimeRef . current [ lang ] . mutex || emptyMutex
48- ) . runExclusive ( ( ) =>
46+ const outputs : ReplOutput [ ] = [ ] ;
47+ await ( runtimeRef . current [ lang ] . mutex || emptyMutex ) . runExclusive ( ( ) =>
4948 runtimeRef . current [ lang ] . runCommand ! ( printCode , ( output ) => {
5049 outputs . push ( output ) ;
5150 } )
@@ -73,15 +72,18 @@ export function defineTests(
7372 if ( ! setIntVarCode || ! printIntVarCode ) {
7473 this . skip ( ) ;
7574 }
76- const outputs : any [ ] = [ ] ;
77- await (
78- runtimeRef . current [ lang ] . mutex || emptyMutex
79- ) . runExclusive ( async ( ) => {
80- await runtimeRef . current [ lang ] . runCommand ! ( setIntVarCode , ( ) => { } ) ;
81- await runtimeRef . current [ lang ] . runCommand ! ( printIntVarCode , ( output ) => {
82- outputs . push ( output ) ;
83- } ) ;
84- } ) ;
75+ const outputs : ReplOutput [ ] = [ ] ;
76+ await ( runtimeRef . current [ lang ] . mutex || emptyMutex ) . runExclusive (
77+ async ( ) => {
78+ await runtimeRef . current [ lang ] . runCommand ! ( setIntVarCode , ( ) => { } ) ;
79+ await runtimeRef . current [ lang ] . runCommand ! (
80+ printIntVarCode ,
81+ ( output ) => {
82+ outputs . push ( output ) ;
83+ }
84+ ) ;
85+ }
86+ ) ;
8587 console . log ( `${ lang } REPL variable preservation test: ` , outputs ) ;
8688 expect ( outputs ) . to . be . deep . include ( {
8789 type : "stdout" ,
@@ -104,10 +106,8 @@ export function defineTests(
104106 if ( ! errorCode ) {
105107 this . skip ( ) ;
106108 }
107- const outputs : any [ ] = [ ] ;
108- await (
109- runtimeRef . current [ lang ] . mutex || emptyMutex
110- ) . runExclusive ( ( ) =>
109+ const outputs : ReplOutput [ ] = [ ] ;
110+ await ( runtimeRef . current [ lang ] . mutex || emptyMutex ) . runExclusive ( ( ) =>
111111 runtimeRef . current [ lang ] . runCommand ! ( errorCode , ( output ) => {
112112 outputs . push ( output ) ;
113113 } )
@@ -150,10 +150,8 @@ export function defineTests(
150150 while ( ! runtimeRef . current [ lang ] . ready ) {
151151 await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
152152 }
153- const outputs : any [ ] = [ ] ;
154- await (
155- runtimeRef . current [ lang ] . mutex || emptyMutex
156- ) . runExclusive ( ( ) =>
153+ const outputs : ReplOutput [ ] = [ ] ;
154+ await ( runtimeRef . current [ lang ] . mutex || emptyMutex ) . runExclusive ( ( ) =>
157155 runtimeRef . current [ lang ] . runCommand ! ( printIntVarCode , ( output ) => {
158156 outputs . push ( output ) ;
159157 } )
@@ -178,9 +176,9 @@ export function defineTests(
178176 if ( ! writeCode ) {
179177 this . skip ( ) ;
180178 }
181- await (
182- runtimeRef . current [ lang ] . mutex || emptyMutex
183- ) . runExclusive ( ( ) => runtimeRef . current [ lang ] . runCommand ! ( writeCode , ( ) => { } ) ) ;
179+ await ( runtimeRef . current [ lang ] . mutex || emptyMutex ) . runExclusive ( ( ) =>
180+ runtimeRef . current [ lang ] . runCommand ! ( writeCode , ( ) => { } )
181+ ) ;
184182 // wait for files to be updated
185183 await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
186184 expect ( filesRef . current [ targetFile ] ) . to . equal ( msg ) ;
@@ -206,12 +204,16 @@ export function defineTests(
206204 if ( ! filename || ! code ) {
207205 this . skip ( ) ;
208206 }
209- const outputs : any [ ] = [ ] ;
210- await runtimeRef . current [ lang ] . runFiles ( [ filename ] , {
211- [ filename ] : code ,
212- } , ( output ) => {
213- outputs . push ( output ) ;
214- } ) ;
207+ const outputs : ReplOutput [ ] = [ ] ;
208+ await runtimeRef . current [ lang ] . runFiles (
209+ [ filename ] ,
210+ {
211+ [ filename ] : code ,
212+ } ,
213+ ( output ) => {
214+ outputs . push ( output ) ;
215+ }
216+ ) ;
215217 console . log ( `${ lang } single file stdout test: ` , outputs ) ;
216218 expect ( outputs ) . to . be . deep . include ( { type : "stdout" , message : msg } ) ;
217219 } ) ;
@@ -238,12 +240,16 @@ export function defineTests(
238240 if ( ! filename || ! code ) {
239241 this . skip ( ) ;
240242 }
241- const outputs : any [ ] = [ ] ;
242- await runtimeRef . current [ lang ] . runFiles ( [ filename ] , {
243- [ filename ] : code ,
244- } , ( output ) => {
245- outputs . push ( output ) ;
246- } ) ;
243+ const outputs : ReplOutput [ ] = [ ] ;
244+ await runtimeRef . current [ lang ] . runFiles (
245+ [ filename ] ,
246+ {
247+ [ filename ] : code ,
248+ } ,
249+ ( output ) => {
250+ outputs . push ( output ) ;
251+ }
252+ ) ;
247253 console . log ( `${ lang } single file error capture test: ` , outputs ) ;
248254 // eslint-disable-next-line @typescript-eslint/no-unused-expressions
249255 expect ( outputs . filter ( ( r ) => r . message . includes ( errorMsg ) ) ) . to . not . be
@@ -297,14 +303,10 @@ export function defineTests(
297303 if ( ! codes || ! execFiles ) {
298304 this . skip ( ) ;
299305 }
300- const outputs : any [ ] = [ ] ;
301- await runtimeRef . current [ lang ] . runFiles (
302- execFiles ,
303- codes ,
304- ( output ) => {
305- outputs . push ( output ) ;
306- }
307- ) ;
306+ const outputs : ReplOutput [ ] = [ ] ;
307+ await runtimeRef . current [ lang ] . runFiles ( execFiles , codes , ( output ) => {
308+ outputs . push ( output ) ;
309+ } ) ;
308310 console . log ( `${ lang } multifile stdout test: ` , outputs ) ;
309311 expect ( outputs ) . to . be . deep . include ( { type : "stdout" , message : msg } ) ;
310312 } ) ;
@@ -331,9 +333,13 @@ export function defineTests(
331333 if ( ! filename || ! code ) {
332334 this . skip ( ) ;
333335 }
334- await runtimeRef . current [ lang ] . runFiles ( [ filename ] , {
335- [ filename ] : code ,
336- } , ( ) => { } ) ;
336+ await runtimeRef . current [ lang ] . runFiles (
337+ [ filename ] ,
338+ {
339+ [ filename ] : code ,
340+ } ,
341+ ( ) => { }
342+ ) ;
337343 // wait for files to be updated
338344 await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
339345 expect ( filesRef . current [ targetFile ] ) . to . equal ( msg ) ;
0 commit comments