Skip to content

Commit 4eb7dc7

Browse files
committed
Adapt tests to not using singleton
1 parent bdfb8c5 commit 4eb7dc7

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

packages/transport-node-serial/src/transport.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ class FakeSerialPort extends Duplex {
5353
}
5454

5555
function stubCoreTransforms() {
56-
const toDevice = new TransformStream<Uint8Array, Uint8Array>({
57-
transform(chunk, controller) {
58-
controller.enqueue(chunk);
59-
},
60-
});
56+
const toDevice = () =>
57+
new TransformStream<Uint8Array, Uint8Array>({
58+
transform(chunk, controller) {
59+
controller.enqueue(chunk);
60+
},
61+
});
6162

6263
const fromDeviceFactory = () =>
6364
new TransformStream<Uint8Array, Types.DeviceOutput>({
@@ -67,7 +68,7 @@ function stubCoreTransforms() {
6768
});
6869

6970
// Utils.toDeviceStream is a getter
70-
const transform = Utils.toDeviceStream();
71+
const transform = Utils.toDeviceStream;
7172
vi.spyOn(Utils, "toDeviceStream", "get").mockReturnValue(
7273
toDevice as unknown as typeof transform,
7374
);

packages/transport-node/src/transport.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ class FakeSocket extends Duplex {
5454
}
5555

5656
function stubCoreTransforms() {
57-
const toDevice = new TransformStream<Uint8Array, Uint8Array>({
58-
transform(chunk, controller) {
59-
controller.enqueue(chunk);
60-
},
61-
});
57+
const toDevice = () =>
58+
new TransformStream<Uint8Array, Uint8Array>({
59+
transform(chunk, controller) {
60+
controller.enqueue(chunk);
61+
},
62+
});
6263

6364
const fromDeviceFactory = () =>
6465
new TransformStream<Uint8Array, Types.DeviceOutput>({
@@ -67,7 +68,7 @@ function stubCoreTransforms() {
6768
},
6869
});
6970

70-
const transform = Utils.toDeviceStream();
71+
const transform = Utils.toDeviceStream;
7172
vi.spyOn(Utils, "toDeviceStream", "get").mockReturnValue(
7273
toDevice as unknown as typeof transform,
7374
);

packages/transport-web-serial/src/transport.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { runTransportContract } from "../../../tests/utils/transportContract.ts"
44
import { TransportWebSerial } from "./transport.ts";
55

66
function stubCoreTransforms() {
7-
const toDevice = new TransformStream<Uint8Array, Uint8Array>({
8-
transform(chunk, controller) {
9-
controller.enqueue(chunk);
10-
},
11-
});
7+
const toDevice = () =>
8+
new TransformStream<Uint8Array, Uint8Array>({
9+
transform(chunk, controller) {
10+
controller.enqueue(chunk);
11+
},
12+
});
1213

1314
// maps raw bytes -> DeviceOutput.packet
1415
const fromDeviceFactory = () =>
@@ -18,7 +19,7 @@ function stubCoreTransforms() {
1819
},
1920
});
2021

21-
const transform = Utils.toDeviceStream();
22+
const transform = Utils.toDeviceStream;
2223
const restoreTo = vi
2324
.spyOn(Utils, "toDeviceStream", "get")
2425
.mockReturnValue(toDevice as unknown as typeof transform);

0 commit comments

Comments
 (0)