From 9aeb87a1482d6510881e2b582696f997f0b5abef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20=E2=80=9Cweej=E2=80=9D=20Jones?= Date: Wed, 6 Nov 2024 16:02:43 +0000 Subject: [PATCH 1/5] test: use test runner in eventtarget-once-twice test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexander “weej” Jones --- test/parallel/test-eventtarget-once-twice.js | 34 +++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/test/parallel/test-eventtarget-once-twice.js b/test/parallel/test-eventtarget-once-twice.js index 3358bab90e7569..c555941eb55236 100644 --- a/test/parallel/test-eventtarget-once-twice.js +++ b/test/parallel/test-eventtarget-once-twice.js @@ -1,14 +1,24 @@ 'use strict'; const common = require('../common'); -const { once } = require('events'); - -const et = new EventTarget(); -(async function() { - await once(et, 'foo'); - await once(et, 'foo'); -})().then(common.mustCall()); - -et.dispatchEvent(new Event('foo')); -setImmediate(() => { - et.dispatchEvent(new Event('foo')); -}); +const assert = require('node:assert/strict'); +const { once } = require('node:events'); +const { test } = require('node:test'); +const { setImmediate } = require('node:timers/promises'); + +test('should resolve `once` twice', (t, done) => { + + const et = new EventTarget(); + + (async () => { + await once(et, 'foo'); + await once(et, 'foo'); + done(); + })(); + + (async () => { + et.dispatchEvent(new Event('foo')); + await setImmediate(); + et.dispatchEvent(new Event('foo')); + })(); + +}); \ No newline at end of file From edd18e73c2a65dd06ed56d64c6f49b90ea8557d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20=E2=80=9Cweej=E2=80=9D=20Jones?= Date: Wed, 6 Nov 2024 16:40:36 +0000 Subject: [PATCH 2/5] Add somewhat redundant `mustCall`s. Open to suggestions on how to appease the linter... --- test/parallel/test-eventtarget-once-twice.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-eventtarget-once-twice.js b/test/parallel/test-eventtarget-once-twice.js index c555941eb55236..e6b2f6e1215eb2 100644 --- a/test/parallel/test-eventtarget-once-twice.js +++ b/test/parallel/test-eventtarget-once-twice.js @@ -13,12 +13,12 @@ test('should resolve `once` twice', (t, done) => { await once(et, 'foo'); await once(et, 'foo'); done(); - })(); + })(common.mustCall()); (async () => { et.dispatchEvent(new Event('foo')); await setImmediate(); et.dispatchEvent(new Event('foo')); - })(); + })(common.mustCall()); -}); \ No newline at end of file +}); From 04726fa46ccb4178506ffa23b342514818fc5c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20=E2=80=9Cweej=E2=80=9D=20Jones?= Date: Thu, 7 Nov 2024 09:21:31 +0000 Subject: [PATCH 3/5] Async (again) --- test/parallel/test-eventtarget-once-twice.js | 23 ++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/parallel/test-eventtarget-once-twice.js b/test/parallel/test-eventtarget-once-twice.js index e6b2f6e1215eb2..c8ea7db46db566 100644 --- a/test/parallel/test-eventtarget-once-twice.js +++ b/test/parallel/test-eventtarget-once-twice.js @@ -5,20 +5,21 @@ const { once } = require('node:events'); const { test } = require('node:test'); const { setImmediate } = require('node:timers/promises'); -test('should resolve `once` twice', (t, done) => { +test('should resolve `once` twice', async () => { const et = new EventTarget(); - (async () => { - await once(et, 'foo'); - await once(et, 'foo'); - done(); - })(common.mustCall()); + await Promise.all([ + (async () => { + await once(et, 'foo'); + await once(et, 'foo'); + })(), - (async () => { - et.dispatchEvent(new Event('foo')); - await setImmediate(); - et.dispatchEvent(new Event('foo')); - })(common.mustCall()); + (async () => { + et.dispatchEvent(new Event('foo')); + await setImmediate(); + et.dispatchEvent(new Event('foo')); + })() + ]); }); From e1654b956e8ec9fa66c909294f6d2f9f5909ccd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20=E2=80=9Cweej=E2=80=9D=20Jones?= Date: Thu, 7 Nov 2024 12:11:48 +0000 Subject: [PATCH 4/5] Tidy up imports --- test/parallel/test-eventtarget-once-twice.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/parallel/test-eventtarget-once-twice.js b/test/parallel/test-eventtarget-once-twice.js index c8ea7db46db566..3672de47eded1b 100644 --- a/test/parallel/test-eventtarget-once-twice.js +++ b/test/parallel/test-eventtarget-once-twice.js @@ -1,6 +1,5 @@ 'use strict'; -const common = require('../common'); -const assert = require('node:assert/strict'); +require('../common'); const { once } = require('node:events'); const { test } = require('node:test'); const { setImmediate } = require('node:timers/promises'); From e70ec63cc8f3322f5853e81e062449e76ef00e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20=E2=80=9Cweej=E2=80=9D=20Jones?= Date: Mon, 11 Nov 2024 15:52:14 +0000 Subject: [PATCH 5/5] comma --- test/parallel/test-eventtarget-once-twice.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-eventtarget-once-twice.js b/test/parallel/test-eventtarget-once-twice.js index 3672de47eded1b..f7fbc30ea17ec9 100644 --- a/test/parallel/test-eventtarget-once-twice.js +++ b/test/parallel/test-eventtarget-once-twice.js @@ -18,7 +18,7 @@ test('should resolve `once` twice', async () => { et.dispatchEvent(new Event('foo')); await setImmediate(); et.dispatchEvent(new Event('foo')); - })() + })(), ]); });