@@ -6,89 +6,53 @@ import { NatsContainer } from "./nats-container";
66const IMAGE = getImage ( __dirname ) ;
77
88describe ( "NatsContainer" , { timeout : 180_000 } , ( ) => {
9- // connect {
10- it ( "should start, connect and close" , async ( ) => {
11- await using container = await new NatsContainer ( IMAGE ) . start ( ) ;
12-
13- // establish connection
14- const nc = await connect ( container . getConnectionOptions ( ) ) ;
15- // close the connection
16- await nc . close ( ) ;
17- // check if the close was OK
18- const err = await nc . closed ( ) ;
19- expect ( err ) . toBe ( undefined ) ;
20- } ) ;
21- // }
22-
23- it ( "should start, connect and close using scratch image" , async ( ) => {
24- await using container = await new NatsContainer ( "nats:2.11" ) . start ( ) ;
25-
26- // establish connection
27- const nc = await connect ( container . getConnectionOptions ( ) ) ;
28- // close the connection
29- await nc . close ( ) ;
30- // check if the close was OK
31- const err = await nc . closed ( ) ;
32- expect ( err ) . toBe ( undefined ) ;
33- } ) ;
34-
35- // pubsub {
369 it ( "should subscribe and receive one published message" , async ( ) => {
10+ // natsPubsub {
3711 const SUBJECT = "HELLO" ;
3812 const PAYLOAD = "WORLD" ;
13+ const TE = new TextEncoder ( ) ;
14+ const TD = new TextDecoder ( ) ;
3915
4016 await using container = await new NatsContainer ( IMAGE ) . start ( ) ;
4117 const nc = await connect ( container . getConnectionOptions ( ) ) ;
42- const TE = new TextEncoder ( ) ;
43- const TD = new TextDecoder ( ) ;
4418
45- //----------------
4619 const sub = nc . subscribe ( SUBJECT ) ;
20+
4721 ( async ( ) => {
4822 for await ( const m of sub ) {
4923 const actual = TD . decode ( m . data ) ;
5024 expect ( actual ) . toEqual ( PAYLOAD ) ;
5125 }
5226 } ) ( ) . then ( ) ;
5327
54- //----------------
5528 nc . publish ( SUBJECT , TE . encode ( PAYLOAD ) ) ;
5629
57- //----------------
5830 await nc . drain ( ) ;
5931 await nc . close ( ) ;
60- const err = await nc . closed ( ) ;
61- expect ( err ) . toBe ( undefined ) ;
32+ // }
6233 } ) ;
63- // }
6434
65- // credentials {
6635 it ( "should start with alternative username and password " , async ( ) => {
67- // set username and password like this
68- await using container = await new NatsContainer ( IMAGE ) . withPass ( "1234" ) . withUsername ( "George" ) . start ( ) ;
36+ // natsCredentials {
37+ await using container = await new NatsContainer ( IMAGE ) . withUsername ( "George" ) . withPass ( "1234" ) . start ( ) ;
38+ // }
6939
7040 const nc = await connect ( container . getConnectionOptions ( ) ) ;
71- // close the connection
41+
7242 await nc . close ( ) ;
73- // check if the close was OK
7443 const err = await nc . closed ( ) ;
7544 expect ( err ) . toBe ( undefined ) ;
7645 } ) ;
77- // }
7846
79- // jetstream {
8047 it ( "should start with JetStream " , async ( ) => {
81- // enable JetStream
48+ // natsJetstream {
8249 await using container = await new NatsContainer ( IMAGE ) . withJetStream ( ) . start ( ) ;
50+ // }
8351
8452 const nc = await connect ( container . getConnectionOptions ( ) ) ;
85-
86- // ensure JetStream is enabled, otherwise this will throw an error
8753 await jetstreamManager ( nc ) ;
8854
89- // close the connection
9055 await nc . close ( ) ;
91- // check if the close was OK
9256 const err = await nc . closed ( ) ;
9357 expect ( err ) . toBe ( undefined ) ;
9458 } ) ;
0 commit comments