Skip to content

Commit b658989

Browse files
committed
test: convert socket stream compat to TypeScript
1 parent d3f16a3 commit b658989

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

test/unit/compat/socket-stream-test.js renamed to test/unit/compat/socket-stream-test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
if (process.env.INCLUDE_COMPAT_TESTS) {
2-
const zmq = require("./load")
3-
const {assert} = require("chai")
4-
const {testProtos, uniqAddress} = require("../helpers")
5-
const http = require("http")
1+
import * as zmq from "../../../v5-compat"
2+
import {assert} from "chai"
3+
import {uniqAddress} from "../helpers"
4+
import http from "http"
65

6+
if (process.env.INCLUDE_COMPAT_TESTS) {
77
describe("compat socket stream", function () {
8-
it("should support a stream socket type", function (done) {
8+
it("should support a stream socket type", async function (done) {
99
const stream = zmq.socket("stream")
10-
const address = uniqAddress("tcp")
10+
const address = await uniqAddress("tcp")
1111

12-
stream.on("message", function (id, msg) {
12+
stream.on("message", function (id: string, msg: string) {
1313
assert.instanceOf(msg, Buffer)
1414
if (msg.length == 0) {
1515
return
@@ -37,7 +37,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
3737
stream.send([id, httpProtocolString])
3838
})
3939

40-
stream.bind(address, err => {
40+
stream.bind(address, (err: Error | undefined) => {
4141
if (err) {
4242
throw err
4343
}
@@ -46,9 +46,10 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
4646
http.get(
4747
`${address.replace("tcp:", "http:")}/aRandomRequestPath`,
4848
function (httpMsg) {
49+
// @ts-expect-error
4950
assert.equal(httpMsg.socket._readableState.reading, false)
5051

51-
httpMsg.on("data", function (msg) {
52+
httpMsg.on("data", function (msg: string) {
5253
assert.instanceOf(msg, Buffer)
5354
assert.equal(
5455
msg.toString(),

0 commit comments

Comments
 (0)