Skip to content

Commit b33050b

Browse files
Upgrade NATS library used for tests (#1009)
1 parent b373362 commit b33050b

File tree

3 files changed

+73
-35
lines changed

3 files changed

+73
-35
lines changed

package-lock.json

Lines changed: 63 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/modules/nats/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
"prepack": "shx cp ../../../README.md . && shx cp ../../../LICENSE .",
2929
"build": "tsc --project tsconfig.build.json"
3030
},
31-
"devDependencies": {
32-
"nats": "^2.28.0"
33-
},
3431
"dependencies": {
3532
"testcontainers": "^10.27.0"
33+
},
34+
"devDependencies": {
35+
"@nats-io/jetstream": "^3.0.2",
36+
"@nats-io/transport-node": "^3.0.2"
3637
}
3738
}

packages/modules/nats/src/nats-container.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { connect, StringCodec } from "nats";
1+
import { jetstreamManager } from "@nats-io/jetstream";
2+
import { connect } from "@nats-io/transport-node";
23
import { NatsContainer } from "./nats-container";
34

45
describe("NatsContainer", { timeout: 180_000 }, () => {
@@ -25,19 +26,18 @@ describe("NatsContainer", { timeout: 180_000 }, () => {
2526

2627
const container = await new NatsContainer().start();
2728
const nc = await connect(container.getConnectionOptions());
28-
const sc = StringCodec();
2929

3030
//----------------
3131
const sub = nc.subscribe(SUBJECT);
3232
(async () => {
3333
for await (const m of sub) {
34-
const actual: string = sc.decode(m.data);
34+
const actual: string = m.string();
3535
expect(actual).toEqual(PAYLOAD);
3636
}
3737
})().then();
3838

3939
//----------------
40-
nc.publish(SUBJECT, sc.encode(PAYLOAD));
40+
nc.publish(SUBJECT, PAYLOAD);
4141

4242
//----------------
4343
await nc.drain();
@@ -73,7 +73,7 @@ describe("NatsContainer", { timeout: 180_000 }, () => {
7373
const nc = await connect(container.getConnectionOptions());
7474

7575
// ensure JetStream is enabled, otherwise this will throw an error
76-
await nc.jetstream().jetstreamManager();
76+
await jetstreamManager(nc);
7777

7878
// close the connection
7979
await nc.close();
@@ -90,7 +90,7 @@ describe("NatsContainer", { timeout: 180_000 }, () => {
9090
const nc = await connect(container.getConnectionOptions());
9191

9292
// ensure JetStream is not enabled, as this will throw an error
93-
await expect(nc.jetstream().jetstreamManager()).rejects.toThrow("503");
93+
await expect(jetstreamManager(nc)).rejects.toThrow("jetstream is not enabled");
9494

9595
// close the connection
9696
await nc.close();

0 commit comments

Comments
 (0)