@@ -255,6 +255,34 @@ func TestRuntime(t *testing.T) {
255255 require .NoError (t , err , "Normal runtime creation should still work after invalid attempt" )
256256 defer rt2 .Close ()
257257 })
258+
259+ t .Run ("CacheDirOption" , func (t * testing.T ) {
260+ rt1 , err := qjs .New (qjs.Option {CacheDir : t .TempDir ()})
261+ require .NoError (t , err )
262+ defer rt1 .Close ()
263+
264+ val , err := rt1 .Eval ("test.js" , qjs .Code ("21 + 21" ))
265+ require .NoError (t , err )
266+ assert .Equal (t , int32 (42 ), val .Int32 ())
267+ val .Free ()
268+ })
269+
270+ t .Run ("CacheDirWithEmptyString" , func (t * testing.T ) {
271+ rt , err := qjs .New (qjs.Option {CacheDir : "" })
272+ require .NoError (t , err )
273+ defer rt .Close ()
274+
275+ val , err := rt .Eval ("test.js" , qjs .Code ("2 * 21" ))
276+ require .NoError (t , err )
277+ assert .Equal (t , int32 (42 ), val .Int32 ())
278+ val .Free ()
279+ })
280+
281+ t .Run ("CacheDirWithInvalidPath" , func (t * testing.T ) {
282+ _ , err := qjs .New (qjs.Option {CacheDir : "/invalid/path/that/does/not/exist" , QuickJSWasmBytes : []byte ("cachedir" )})
283+ require .Error (t , err )
284+ assert .Contains (t , err .Error (), "failed to create compilation cache" )
285+ })
258286}
259287
260288// Concurrent Runtime Usage Tests
0 commit comments