-
Notifications
You must be signed in to change notification settings - Fork 30.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: migrate tests to use node:test module for better test structure
- 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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |