Skip to content

Commit

Permalink
test: migrate tests to use node:test module for better test structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Mert Can Altin committed Nov 27, 2024
1 parent 585f7bc commit 91952ae
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions test/parallel/test-eventtarget-once-twice.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
'use strict';
const common = require('../common');
const { once } = require('events');
const { once } = require('node:events');
const { test } = require('node:test');

const et = new EventTarget();
(async function() {
await once(et, 'foo');
await once(et, 'foo');
})().then(common.mustCall());
test('EventTarget test', async () => {
const et = new EventTarget();

et.dispatchEvent(new Event('foo'));
setImmediate(() => {
// Use `once` to listen for the 'foo' event twice
const promise1 = once(et, 'foo');
const promise2 = once(et, 'foo');

// Dispatch the first event
et.dispatchEvent(new Event('foo'));
});

// Dispatch the second event in the next tick to ensure it's awaited properly
setImmediate(() => {
et.dispatchEvent(new Event('foo'));
});

// Await both promises to ensure both 'foo' events are captured
await promise1;
await promise2;

// Test automatically completes after all asynchronous operations finish
}).then(common.mustCall());

0 comments on commit 91952ae

Please sign in to comment.