@@ -45,12 +45,7 @@ export function defineTests(
4545 runtimeRef . current [ lang ] . mutex || emptyMutex
4646 ) . runExclusive ( ( ) => runtimeRef . current [ lang ] . runCommand ! ( printCode ) ) ;
4747 console . log ( `${ lang } REPL stdout test: ` , result ) ;
48- expect ( result ) . to . be . deep . equal ( [
49- {
50- type : "stdout" ,
51- message : msg ,
52- } ,
53- ] ) ;
48+ expect ( result ) . to . be . deep . include ( { type : "stdout" , message : msg } ) ;
5449 } ) ;
5550
5651 it ( "should preserve variables across commands" , async function ( ) {
@@ -78,12 +73,10 @@ export function defineTests(
7873 return runtimeRef . current [ lang ] . runCommand ! ( printIntVarCode ) ;
7974 } ) ;
8075 console . log ( `${ lang } REPL variable preservation test: ` , result ) ;
81- expect ( result ) . to . be . deep . equal ( [
82- {
83- type : "stdout" ,
84- message : value . toString ( ) ,
85- } ,
86- ] ) ;
76+ expect ( result ) . to . be . deep . include ( {
77+ type : "stdout" ,
78+ message : value . toString ( ) ,
79+ } ) ;
8780 } ) ;
8881
8982 it ( "should capture errors" , async function ( ) {
@@ -146,12 +139,31 @@ export function defineTests(
146139 runtimeRef . current [ lang ] . runCommand ! ( printIntVarCode )
147140 ) ;
148141 console . log ( `${ lang } REPL interrupt recovery test: ` , result ) ;
149- expect ( result ) . to . be . deep . equal ( [
142+ expect ( result ) . to . be . deep . include ( { type : "stdout" , message : "42" } ) ;
143+ } ) ;
144+
145+ it ( "should capture files modified by command" , async function ( ) {
146+ const targetFile = "test.txt" ;
147+ const msg = "Hello, World!" ;
148+ const writeCode = (
150149 {
151- type : "stdout" ,
152- message : "42" ,
153- } ,
154- ] ) ;
150+ python : `with open("${ targetFile } ", "w") as f:\n f.write("${ msg } ")` ,
151+ ruby : `File.open("${ targetFile } ", "w") {|f| f.write("${ msg } ") }` ,
152+ cpp : null ,
153+ javascript : null ,
154+ typescript : null ,
155+ } satisfies Record < RuntimeLang , string | null >
156+ ) [ lang ] ;
157+ if ( ! writeCode ) {
158+ this . skip ( ) ;
159+ }
160+ const result = await (
161+ runtimeRef . current [ lang ] . mutex || emptyMutex
162+ ) . runExclusive ( ( ) => runtimeRef . current [ lang ] . runCommand ! ( writeCode ) ) ;
163+ console . log ( `${ lang } REPL file modify test: ` , result ) ;
164+ // wait for files to be updated
165+ await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
166+ expect ( filesRef . current [ targetFile ] ) . to . equal ( msg ) ;
155167 } ) ;
156168 } ) ;
157169
@@ -177,12 +189,7 @@ export function defineTests(
177189 [ filename ] : code ,
178190 } ) ;
179191 console . log ( `${ lang } single file stdout test: ` , result ) ;
180- expect ( result ) . to . be . deep . equal ( [
181- {
182- type : "stdout" ,
183- message : msg ,
184- } ,
185- ] ) ;
192+ expect ( result ) . to . be . deep . include ( { type : "stdout" , message : msg } ) ;
186193 } ) ;
187194
188195 it ( "should capture errors" , async function ( ) {
@@ -256,12 +263,37 @@ export function defineTests(
256263 codes
257264 ) ;
258265 console . log ( `${ lang } multifile stdout test: ` , result ) ;
259- expect ( result ) . to . be . deep . equal ( [
266+ expect ( result ) . to . be . deep . include ( { type : "stdout" , message : msg } ) ;
267+ } ) ;
268+
269+ it ( "should capture files modified by script" , async function ( ) {
270+ const targetFile = "test.txt" ;
271+ const msg = "Hello, World!" ;
272+ const [ filename , code ] = (
260273 {
261- type : "stdout" ,
262- message : msg ,
263- } ,
264- ] ) ;
274+ python : [
275+ "test.py" ,
276+ `with open("${ targetFile } ", "w") as f:\n f.write("${ msg } ")` ,
277+ ] ,
278+ ruby : [
279+ "test.rb" ,
280+ `File.open("${ targetFile } ", "w") {|f| f.write("${ msg } ") }` ,
281+ ] ,
282+ cpp : [ null , null ] ,
283+ javascript : [ null , null ] ,
284+ typescript : [ null , null ] ,
285+ } satisfies Record < RuntimeLang , [ string , string ] | [ null , null ] >
286+ ) [ lang ] ;
287+ if ( ! filename || ! code ) {
288+ this . skip ( ) ;
289+ }
290+ const result = await runtimeRef . current [ lang ] . runFiles ( [ filename ] , {
291+ [ filename ] : code ,
292+ } ) ;
293+ console . log ( `${ lang } file modify test: ` , result ) ;
294+ // wait for files to be updated
295+ await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
296+ expect ( filesRef . current [ targetFile ] ) . to . equal ( msg ) ;
265297 } ) ;
266298 } ) ;
267299 } ) ;
0 commit comments