11#!/usr/bin/env tsx
22
3- import { RIVET_ENDPOINT , RIVET_TOKEN , createActor , destroyActor } from "./utils" ;
3+ import { RIVET_ENDPOINT , RIVET_TOKEN , RIVET_NAMESPACE , createActor , destroyActor } from "./utils" ;
44
55async function main ( ) {
6+ let actorId ;
7+
68 try {
79 console . log ( "Starting actor E2E test..." ) ;
810
911 // Create an actor
1012 console . log ( "Creating actor..." ) ;
11- const actorResponse = await createActor ( "default" , "test-runner" ) ;
13+ const actorResponse = await createActor ( RIVET_NAMESPACE , "test-runner" ) ;
1214 console . log ( "Actor created:" , actorResponse . actor ) ;
1315
16+ actorId = actorResponse . actor . actor_id ;
17+
1418 // Make a request to the actor
1519 console . log ( "Making request to actor..." ) ;
1620 const actorPingResponse = await fetch ( `${ RIVET_ENDPOINT } /ping` , {
1721 method : "GET" ,
1822 headers : {
23+ "X-Rivet-Token" : RIVET_TOKEN ,
1924 "X-Rivet-Target" : "actor" ,
2025 "X-Rivet-Actor" : actorResponse . actor . actor_id ,
2126 } ,
@@ -32,17 +37,13 @@ async function main() {
3237 console . log ( "Actor ping response:" , pingResult ) ;
3338
3439 await testWebSocket ( actorResponse . actor . actor_id ) ;
35-
36- console . log ( "Destroying actor..." ) ;
37- await destroyActor ( "default" , actorResponse . actor . actor_id ) ;
38-
39- console . log ( "E2E test completed successfully!" ) ;
40-
41- // HACK: This script does not exit by itself for some reason
42- process . exit ( 0 ) ;
4340 } catch ( error ) {
44- console . error ( "E2E test failed:" , error ) ;
45- process . exit ( 1 ) ;
41+ console . error ( `Actor ${ i } test failed:` , error ) ;
42+ } finally {
43+ if ( actorId ) {
44+ console . log ( `Destroying actor ${ i } ...` ) ;
45+ await destroyActor ( RIVET_NAMESPACE , actorId ) ;
46+ }
4647 }
4748}
4849
0 commit comments