Skip to content

Commit 5496caf

Browse files
committed
fix: improve coverage
1 parent 586ef40 commit 5496caf

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/RequestManager.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,25 @@ describe("client-js", () => {
171171
});
172172
});
173173

174+
it("onData throws if the ID is not found", async () => {
175+
const emitter = new EventEmitter();
176+
const transport = new EventEmitterTransport(emitter, "from1", "to1");
177+
const serverTransport = new EventEmitterTransport(emitter, "to1", "from1");
178+
const c = new RequestManager([transport]);
179+
await c.connect();
180+
expect(() => serverTransport.sendData(JSON.stringify({
181+
jsonrpc: "2.0",
182+
id: 10,
183+
error: {
184+
code: 0,
185+
message: "out of order",
186+
data: {
187+
foo: "bar",
188+
},
189+
},
190+
}))).toThrow();
191+
});
192+
174193
describe("stopBatch", () => {
175194
it("does nothing if the batch is empty", () => {
176195
const emitter = new EventEmitter();
@@ -182,4 +201,19 @@ describe("client-js", () => {
182201
expect(transport.sendData).not.toHaveBeenCalled();
183202
});
184203
});
204+
205+
describe("startBatch", () => {
206+
it("it does nothing if a batch is already started", async () => {
207+
const emitter = new EventEmitter();
208+
const transport = new EventEmitterTransport(emitter, "from1", "to1");
209+
const c = new RequestManager([transport]);
210+
await c.connect();
211+
c.startBatch();
212+
c.request("foo", []);
213+
expect(c.batch.length).toBe(1);
214+
c.startBatch();
215+
c.request("foo", []);
216+
expect(c.batch.length).toBe(2);
217+
});
218+
});
185219
});

src/RequestManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ interface IJSONRPCNotification {
3333
class RequestManager {
3434
public transports: ITransport[];
3535
public connectPromise: Promise<any>;
36+
public batch: IJSONRPCRequest[] = [];
3637
private requests: any;
3738
private batchStarted: boolean = false;
38-
private batch: IJSONRPCRequest[] = [];
3939
private lastId: number = -1;
4040

4141
constructor(transports: ITransport[]) {

0 commit comments

Comments
 (0)