Skip to content

Commit cfc2a0d

Browse files
author
Mert Can Altin
committed
test: migrate tests to use node:test module for better test structure
1 parent 585f7bc commit cfc2a0d

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed
Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11
// Flags: --expose-internals
22
'use strict';
3-
const common = require('../common');
3+
require('../common');
4+
5+
const { test } = require('node:test');
6+
const { Worker } = require('node:worker_threads');
7+
const { once } = require('node:events');
48
const { recordState } = require('../common/heap');
5-
const { Worker } = require('worker_threads');
6-
const { once } = require('events');
79

8-
(async function() {
9-
const w = new Worker('setInterval(() => {}, 100)', { eval: true });
10+
test('Worker threads heap snapshot validation', async (t) => {
11+
await t.test('should validate heap snapshot structure for MessagePort', async () => {
12+
const w = new Worker('setInterval(() => {}, 100)', { eval: true });
13+
14+
// Wait for the Worker to be online
15+
await once(w, 'online');
1016

11-
await once(w, 'online');
12-
const stream = await w.getHeapSnapshot();
13-
const snapshot = recordState(stream);
14-
snapshot.validateSnapshot('Node / MessagePort', [
15-
{
16-
children: [
17-
{ node_name: 'Node / MessagePortData', edge_name: 'data' },
17+
// Generate heap snapshot
18+
const stream = await w.getHeapSnapshot();
19+
const snapshot = recordState(stream);
20+
21+
// Validate the snapshot
22+
snapshot.validateSnapshot(
23+
'Node / MessagePort',
24+
[
25+
{
26+
children: [
27+
{ node_name: 'Node / MessagePortData', edge_name: 'data' },
28+
],
29+
},
1830
],
19-
},
20-
], { loose: true });
21-
await w.terminate();
22-
})().then(common.mustCall());
31+
{ loose: true },
32+
);
33+
34+
// Terminate the Worker
35+
await w.terminate();
36+
});
37+
});

0 commit comments

Comments
 (0)