diff options
-rw-r--r-- | cli/tests/unit/http_test.ts | 16 | ||||
-rw-r--r-- | cli/tests/unit/net_test.ts | 8 | ||||
-rw-r--r-- | cli/tests/unit/performance_test.ts | 4 | ||||
-rw-r--r-- | cli/tests/unit/timers_test.ts | 16 |
4 files changed, 22 insertions, 22 deletions
diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts index 201ca1269..680531876 100644 --- a/cli/tests/unit/http_test.ts +++ b/cli/tests/unit/http_test.ts @@ -803,8 +803,6 @@ unitTest( { perms: { net: true } }, async function httpServerIncompleteMessage() { const listener = Deno.listen({ port: 4501 }); - const def1 = deferred(); - const def2 = deferred(); const client = await Deno.connect({ port: 4501 }); await client.write(new TextEncoder().encode( @@ -830,23 +828,21 @@ unitTest( const errors: Error[] = []; - writeResponse() + const writePromise = writeResponse() .catch((error: Error) => { errors.push(error); - }) - .then(() => def1.resolve()); + }); const res = new Response(readable); - respondWith(res) - .catch((error: Error) => errors.push(error)) - .then(() => def2.resolve()); + const respondPromise = respondWith(res) + .catch((error: Error) => errors.push(error)); client.close(); await Promise.all([ - def1, - def2, + writePromise, + respondPromise, ]); listener.close(); diff --git a/cli/tests/unit/net_test.ts b/cli/tests/unit/net_test.ts index 65145edc2..bd949b02d 100644 --- a/cli/tests/unit/net_test.ts +++ b/cli/tests/unit/net_test.ts @@ -394,8 +394,6 @@ unitTest( unitTest( { perms: { net: true } }, async function netTcpListenIteratorBreakClosesResource() { - const promise = deferred(); - async function iterate(listener: Deno.Listener) { let i = 0; @@ -407,13 +405,11 @@ unitTest( break; } } - - promise.resolve(); } const addr = { hostname: "127.0.0.1", port: 8888 }; const listener = Deno.listen(addr); - iterate(listener); + const iteratePromise = iterate(listener); await delay(100); const conn1 = await Deno.connect(addr); @@ -421,7 +417,7 @@ unitTest( const conn2 = await Deno.connect(addr); conn2.close(); - await promise; + await iteratePromise; }, ); diff --git a/cli/tests/unit/performance_test.ts b/cli/tests/unit/performance_test.ts index 989d221d8..7ea1720a5 100644 --- a/cli/tests/unit/performance_test.ts +++ b/cli/tests/unit/performance_test.ts @@ -11,12 +11,14 @@ import { unitTest({ perms: { hrtime: false } }, async function performanceNow() { const resolvable = deferred(); const start = performance.now(); + let totalTime = 0; setTimeout(() => { const end = performance.now(); - assert(end - start >= 10); + totalTime = end - start; resolvable.resolve(); }, 10); await resolvable; + assert(totalTime >= 10); }); unitTest(function performanceMark() { diff --git a/cli/tests/unit/timers_test.ts b/cli/tests/unit/timers_test.ts index 4eb470ba9..2decddbd9 100644 --- a/cli/tests/unit/timers_test.ts +++ b/cli/tests/unit/timers_test.ts @@ -86,11 +86,10 @@ unitTest(async function timeoutEvalNoScopeLeak() { unitTest(async function timeoutArgs() { const promise = deferred(); const arg = 1; + let capturedArgs: unknown[] = []; setTimeout( - (a, b, c) => { - assertEquals(a, arg); - assertEquals(b, arg.toString()); - assertEquals(c, [arg]); + function () { + capturedArgs = [...arguments]; promise.resolve(); }, 10, @@ -99,6 +98,11 @@ unitTest(async function timeoutArgs() { [arg], ); await promise; + assertEquals(capturedArgs, [ + arg, + arg.toString(), + [arg], + ]); }); unitTest(async function timeoutCancelSuccess() { @@ -214,14 +218,16 @@ unitTest(async function fireCallbackImmediatelyWhenDelayOverMaxValue() { unitTest(async function timeoutCallbackThis() { const promise = deferred(); + let capturedThis: unknown; const obj = { foo() { - assertEquals(this, window); + capturedThis = this; promise.resolve(); }, }; setTimeout(obj.foo, 1); await promise; + assertEquals(capturedThis, window); }); unitTest(async function timeoutBindThis() { |