Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: migrate tests to use node:test module for better test structure for eventtarget once twice #56035

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Loading