Skip to content

Commit 76e1a02

Browse files
committed
test: improve the type of the weak refs
1 parent 51ded1f commit 76e1a02

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
22
"mochaExplorer.parallel": true,
3-
"mochaExplorer.globImplementation": "vscode"
3+
"mochaExplorer.globImplementation": "vscode",
4+
"mochaExplorer.nodeArgv": [
5+
"--expose-gc"
6+
]
47
}

test/unit/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,10 @@ export function getGcOrSkipTest(test: Mocha.Context) {
264264
test.skip()
265265
}
266266

267-
const gc = globalThis.gc as undefined | GCFunction
267+
const gc = global.gc as undefined | GCFunction
268268
if (typeof gc !== "function") {
269269
throw new Error(
270-
"Garbage collection is not exposed. It may be enabled by the node --expose-gc flag. To skip GC tests, set the environment variable `SKIP_GC_TESTS`",
270+
"Garbage collection is not exposed. It may be enabled by the node --expose-gc flag or v8-expose-gc flag in Mocha. To skip GC tests, set the environment variable `SKIP_GC_TESTS`",
271271
)
272272
}
273273
// https://github.com/nodejs/node/blob/v20.0.0/deps/v8/src/extensions/gc-extension.h

test/unit/socket-close-test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
100100
await promise
101101
assert.ok(false)
102102
} catch (err) {
103+
console.log(err)
103104
/* Ignore */
104105
}
105106
assert.equal(sock.closed, true)
@@ -109,7 +110,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
109110
const gc = getGcOrSkipTest(this)
110111
this.slow(200)
111112

112-
let weakRef: undefined | WeakRef<any>
113+
let weakRef: undefined | WeakRef<zmq.Context>
113114

114115
const task = async () => {
115116
const context: zmq.Context | undefined = new zmq.Context()
@@ -125,7 +126,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
125126
await gc()
126127

127128
assert.isDefined(weakRef)
128-
assert.isUndefined(weakRef!.deref())
129+
assert.isUndefined(weakRef.deref())
129130
})
130131
})
131132

@@ -137,7 +138,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
137138
}
138139
this.slow(200)
139140

140-
let weakRef: undefined | WeakRef<any>
141+
let weakRef: undefined | WeakRef<zmq.Context>
141142
const task = async () => {
142143
const context: zmq.Context | undefined = new zmq.Context()
143144
const _dealer = new zmq.Dealer({context, linger: 0})
@@ -148,7 +149,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
148149
await gc()
149150

150151
assert.isDefined(weakRef)
151-
assert.isUndefined(weakRef!.deref())
152+
assert.isUndefined(weakRef.deref())
152153
})
153154
})
154155
})

test/unit/socket-send-receive-test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
9191

9292
it("should copy and release small buffers", async function () {
9393
const gc = getGcOrSkipTest(this)
94-
let weakRef: undefined | WeakRef<any>
94+
let weakRef: undefined | WeakRef<Buffer>
9595
sockA.connect(await uniqAddress(proto))
9696
const send = async (size: number) => {
9797
const msg = Buffer.alloc(size)
@@ -107,7 +107,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
107107

108108
it("should retain large buffers", async function () {
109109
const gc = getGcOrSkipTest(this)
110-
let weakRef: undefined | WeakRef<any>
110+
let weakRef: undefined | WeakRef<Buffer>
111111

112112
sockA.connect(await uniqAddress(proto))
113113
const send = async (size: number) => {
@@ -232,6 +232,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
232232
it("should deliver messages coercible to string", async function () {
233233
const messages = [
234234
null,
235+
// eslint-disable-next-line no-empty-function
235236
function () {},
236237
16.19,
237238
true,

0 commit comments

Comments
 (0)