diff --git a/denops/@denops-private/cli_test.ts b/denops/@denops-private/cli_test.ts index 8f394ed3..18310d68 100644 --- a/denops/@denops-private/cli_test.ts +++ b/denops/@denops-private/cli_test.ts @@ -19,7 +19,7 @@ import { } from "jsr:@std/testing@^1.0.0/mock"; import { FakeTime } from "jsr:@std/testing@^1.0.0/time"; import { delay } from "jsr:@std/async@^1.0.1/delay"; -import { promiseState } from "jsr:@lambdalisue/async@^2.1.1"; +import { flushPromises, peekPromiseState } from "jsr:@core/asyncutil@^1.1.1"; import { createFakeTcpConn, createFakeTcpListener, @@ -263,7 +263,7 @@ Deno.test("main()", async (t) => { }); await t.step("pendings main() Promise", async () => { - assertEquals(await promiseState(p), "pending"); + assertEquals(await peekPromiseState(p), "pending"); }); }); @@ -276,7 +276,7 @@ Deno.test("main()", async (t) => { }); await t.step("pendings main() Promise", async () => { - assertEquals(await promiseState(p), "pending"); + assertEquals(await peekPromiseState(p), "pending"); }); await t.step( @@ -296,7 +296,7 @@ Deno.test("main()", async (t) => { }); await t.step("resolves main() Promise", async () => { - assertEquals(await promiseState(p), "fulfilled"); + assertEquals(await peekPromiseState(p), "fulfilled"); }); }); @@ -384,14 +384,15 @@ Deno.test("main()", async (t) => { }); await t.step("pendings main() Promise", async () => { - assertEquals(await promiseState(p), "pending"); + assertEquals(await peekPromiseState(p), "pending"); }); await t.step("and the listner is closed", async (t) => { fakeTcpListener.close(); + await flushPromises(); await t.step("resolves main() Promise", async () => { - assertEquals(await promiseState(p), "fulfilled"); + assertEquals(await peekPromiseState(p), "fulfilled"); }); }); }); @@ -460,7 +461,7 @@ Deno.test("main()", async (t) => { }); await t.step("resolves main() Promise", async () => { - assertEquals(await promiseState(p), "fulfilled"); + assertEquals(await peekPromiseState(p), "fulfilled"); }); await t.step("does not outputs error logs", () => { @@ -604,7 +605,7 @@ Deno.test("main()", async (t) => { }); await t.step("resolves main() Promise", async () => { - assertEquals(await promiseState(mainPromise), "fulfilled"); + assertEquals(await peekPromiseState(mainPromise), "fulfilled"); }); }); }); diff --git a/denops/@denops-private/denops_test.ts b/denops/@denops-private/denops_test.ts index a4fee2b3..115cddb8 100644 --- a/denops/@denops-private/denops_test.ts +++ b/denops/@denops-private/denops_test.ts @@ -12,7 +12,7 @@ import { resolvesNext, stub, } from "jsr:@std/testing@^1.0.0/mock"; -import { promiseState } from "jsr:@lambdalisue/async@^2.1.1"; +import { flushPromises, peekPromiseState } from "jsr:@core/asyncutil@^1.1.1"; import { DenopsImpl, type Host, type Service } from "./denops.ts"; type BatchReturn = [results: unknown[], errmsg: string]; @@ -360,11 +360,14 @@ Deno.test("DenopsImpl", async (t) => { const dispatchPromise = denops.dispatch("dummy", "fn", "args"); - assertEquals(await promiseState(dispatchPromise), "pending"); + assertEquals(await peekPromiseState(dispatchPromise), "pending"); assertSpyCalls(service_waitLoaded, 1); assertSpyCalls(service_dispatch, 0); + waiter.resolve(); - assertEquals(await promiseState(dispatchPromise), "fulfilled"); + await flushPromises(); + + assertEquals(await peekPromiseState(dispatchPromise), "fulfilled"); assertSpyCalls(service_waitLoaded, 1); assertSpyCalls(service_dispatch, 1); }); diff --git a/denops/@denops-private/host/nvim_test.ts b/denops/@denops-private/host/nvim_test.ts index e1b3204f..031f1fda 100644 --- a/denops/@denops-private/host/nvim_test.ts +++ b/denops/@denops-private/host/nvim_test.ts @@ -11,7 +11,7 @@ import { stub, } from "jsr:@std/testing@^1.0.0/mock"; import { delay } from "jsr:@std/async@^1.0.1/delay"; -import { promiseState } from "jsr:@lambdalisue/async@^2.1.1"; +import { peekPromiseState } from "jsr:@core/asyncutil@^1.1.1"; import { unimplemented } from "jsr:@lambdalisue/errorutil@^1.1.0"; import { Client } from "jsr:@lambdalisue/messagepack-rpc@^2.4.0"; import { withNeovim } from "/denops-testutil/with.ts"; @@ -400,14 +400,14 @@ Deno.test("Neovim", async (t) => { const waitClosedPromise = host.waitClosed(); await t.step("pendings before the session closes", async () => { - assertEquals(await promiseState(waitClosedPromise), "pending"); + assertEquals(await peekPromiseState(waitClosedPromise), "pending"); }); // NOTE: Close the session of the host. await host[Symbol.asyncDispose](); await t.step("fulfilled when the session closes", async () => { - assertEquals(await promiseState(waitClosedPromise), "fulfilled"); + assertEquals(await peekPromiseState(waitClosedPromise), "fulfilled"); }); }); }, diff --git a/denops/@denops-private/host/vim_test.ts b/denops/@denops-private/host/vim_test.ts index 4500e0d0..d7caa792 100644 --- a/denops/@denops-private/host/vim_test.ts +++ b/denops/@denops-private/host/vim_test.ts @@ -10,7 +10,7 @@ import { stub, } from "jsr:@std/testing@^1.0.0/mock"; import { delay } from "jsr:@std/async@^1.0.1/delay"; -import { promiseState } from "jsr:@lambdalisue/async@^2.1.1"; +import { peekPromiseState } from "jsr:@core/asyncutil@^1.1.1"; import { unimplemented } from "jsr:@lambdalisue/errorutil@^1.1.0"; import { Client, Session } from "jsr:@denops/vim-channel-command@^4.0.2"; import { withVim } from "/denops-testutil/with.ts"; @@ -378,14 +378,14 @@ Deno.test("Vim", async (t) => { const waitClosedPromise = host.waitClosed(); await t.step("pendings before the session closes", async () => { - assertEquals(await promiseState(waitClosedPromise), "pending"); + assertEquals(await peekPromiseState(waitClosedPromise), "pending"); }); // NOTE: Close the session of the host. await host[Symbol.asyncDispose](); await t.step("fulfilled when the session closes", async () => { - assertEquals(await promiseState(waitClosedPromise), "fulfilled"); + assertEquals(await peekPromiseState(waitClosedPromise), "fulfilled"); }); }); }, diff --git a/denops/@denops-private/service_test.ts b/denops/@denops-private/service_test.ts index 4c3d684c..51c11701 100644 --- a/denops/@denops-private/service_test.ts +++ b/denops/@denops-private/service_test.ts @@ -21,7 +21,7 @@ import { } from "jsr:@std/testing@^1.0.0/mock"; import { toFileUrl } from "jsr:@std/path@^1.0.2/to-file-url"; import type { Meta } from "jsr:@denops/core@^7.0.0"; -import { promiseState } from "jsr:@lambdalisue/async@^2.1.1"; +import { flushPromises, peekPromiseState } from "jsr:@core/asyncutil@^1.1.1"; import { unimplemented } from "jsr:@lambdalisue/errorutil@^1.1.0"; import { INVALID_PLUGIN_NAMES } from "/denops-testdata/invalid_plugin_names.ts"; import { resolveTestDataURL } from "/denops-testdata/resolve.ts"; @@ -644,7 +644,7 @@ Deno.test("Service", async (t) => { }); await t.step("previous `load()` was resolved", async () => { - assertEquals(await promiseState(prevLoadPromise), "fulfilled"); + assertEquals(await peekPromiseState(prevLoadPromise), "fulfilled"); }); await t.step("emits `load()` and `unload()` events", () => { @@ -691,7 +691,7 @@ Deno.test("Service", async (t) => { }); await t.step("previous `load()` was resolved", async () => { - assertEquals(await promiseState(prevLoadPromise), "fulfilled"); + assertEquals(await peekPromiseState(prevLoadPromise), "fulfilled"); }); await t.step("outputs an error message", () => { @@ -735,7 +735,7 @@ Deno.test("Service", async (t) => { }); await t.step("previous `unload()` was resolved", async () => { - assertEquals(await promiseState(prevUnloadPromise), "fulfilled"); + assertEquals(await peekPromiseState(prevUnloadPromise), "fulfilled"); }); await t.step("emits `unload()` events", () => { @@ -930,7 +930,7 @@ Deno.test("Service", async (t) => { }); await t.step("previous `load()` was resolved", async () => { - assertEquals(await promiseState(prevLoadPromise), "fulfilled"); + assertEquals(await peekPromiseState(prevLoadPromise), "fulfilled"); }); await t.step("emits `load()` and `reload()` events", () => { @@ -993,7 +993,7 @@ Deno.test("Service", async (t) => { }); await t.step("previous `unload()` was resolved", async () => { - assertEquals(await promiseState(prevUnloadPromise), "fulfilled"); + assertEquals(await peekPromiseState(prevUnloadPromise), "fulfilled"); }); await t.step("emits `reload()` events", () => { @@ -1132,7 +1132,7 @@ Deno.test("Service", async (t) => { const actual = service.waitLoaded("dummy"); - assertEquals(await promiseState(actual), "pending"); + assertEquals(await peekPromiseState(actual), "pending"); }); await t.step("pendings if the plugin is already unloaded", async () => { @@ -1144,7 +1144,7 @@ Deno.test("Service", async (t) => { const actual = service.waitLoaded("dummy"); - assertEquals(await promiseState(actual), "pending"); + assertEquals(await peekPromiseState(actual), "pending"); }); await t.step("resolves if the plugin is already loaded", async () => { @@ -1155,7 +1155,7 @@ Deno.test("Service", async (t) => { const actual = service.waitLoaded("dummy"); - assertEquals(await promiseState(actual), "fulfilled"); + assertEquals(await peekPromiseState(actual), "fulfilled"); }); await t.step("resolves when the plugin is loaded", async () => { @@ -1166,7 +1166,7 @@ Deno.test("Service", async (t) => { const actual = service.waitLoaded("dummy"); await service.load("dummy", scriptValid); - assertEquals(await promiseState(actual), "fulfilled"); + assertEquals(await peekPromiseState(actual), "fulfilled"); }); await t.step( @@ -1181,7 +1181,7 @@ Deno.test("Service", async (t) => { const unloadPromise = service.unload("dummy"); await Promise.all([loadPromise, unloadPromise]); - assertEquals(await promiseState(actual), "fulfilled"); + assertEquals(await peekPromiseState(actual), "fulfilled"); }, ); @@ -1194,7 +1194,7 @@ Deno.test("Service", async (t) => { const actual = service.waitLoaded("dummy"); actual.catch(NOOP); - assertEquals(await promiseState(actual), "rejected"); + assertEquals(await peekPromiseState(actual), "rejected"); await assertRejects( () => actual, Error, @@ -1211,7 +1211,7 @@ Deno.test("Service", async (t) => { actual.catch(NOOP); await service.close(); - assertEquals(await promiseState(actual), "rejected"); + assertEquals(await peekPromiseState(actual), "rejected"); await assertRejects( () => actual, Error, @@ -1714,7 +1714,7 @@ Deno.test("Service", async (t) => { const actual = service.waitClosed(); - assertEquals(await promiseState(actual), "pending"); + assertEquals(await peekPromiseState(actual), "pending"); }); await t.step("resolves if the service is already closed", async () => { @@ -1722,10 +1722,11 @@ Deno.test("Service", async (t) => { const service = new Service(meta); service.bind(host); service.close(); + await flushPromises(); const actual = service.waitClosed(); - assertEquals(await promiseState(actual), "fulfilled"); + assertEquals(await peekPromiseState(actual), "fulfilled"); }); await t.step("resolves when the service is closed", async () => { @@ -1735,8 +1736,9 @@ Deno.test("Service", async (t) => { const actual = service.waitClosed(); service.close(); + await flushPromises(); - assertEquals(await promiseState(actual), "fulfilled"); + assertEquals(await peekPromiseState(actual), "fulfilled"); }); }); diff --git a/tests/denops/testutil/mock_test.ts b/tests/denops/testutil/mock_test.ts index 9fc11cd5..35915c80 100644 --- a/tests/denops/testutil/mock_test.ts +++ b/tests/denops/testutil/mock_test.ts @@ -4,7 +4,7 @@ import { assertInstanceOf, assertRejects, } from "jsr:@std/assert@^1.0.1"; -import { promiseState } from "jsr:@lambdalisue/async@^2.1.1"; +import { flushPromises, peekPromiseState } from "jsr:@core/asyncutil@^1.1.1"; import { createFakeTcpConn, createFakeTcpListener, @@ -38,7 +38,7 @@ Deno.test("pendingPromise()", async (t) => { const actual = pendingPromise(); assertInstanceOf(actual, Promise); - assertEquals(await promiseState(actual), "pending"); + assertEquals(await peekPromiseState(actual), "pending"); }); }); @@ -93,7 +93,7 @@ Deno.test("createFakeTcpListener()", async (t) => { const promise = listener.accept(); assertInstanceOf(promise, Promise); - assertEquals(await promiseState(promise), "pending"); + assertEquals(await peekPromiseState(promise), "pending"); }); }); @@ -102,11 +102,12 @@ Deno.test("createFakeTcpListener()", async (t) => { const resultPromise = iterator.next(); await t.step("closes the conn iterator", async () => { - assertEquals(await promiseState(resultPromise), "pending"); + assertEquals(await peekPromiseState(resultPromise), "pending"); listener.close(); + await flushPromises(); - assertEquals(await promiseState(resultPromise), "fulfilled"); + assertEquals(await peekPromiseState(resultPromise), "fulfilled"); assertEquals(await resultPromise, { done: true, value: undefined, @@ -142,11 +143,12 @@ Deno.test("createFakeTcpListener()", async (t) => { const resultPromise = iterator.next(); assertSpyCalls(listener_accept, 1); - assertEquals(await promiseState(resultPromise), "pending"); + assertEquals(await peekPromiseState(resultPromise), "pending"); firstAcceptWaiter.resolve("fake-tcp-conn"); + await flushPromises(); - assertEquals(await promiseState(resultPromise), "fulfilled"); + assertEquals(await peekPromiseState(resultPromise), "fulfilled"); assertEquals(await resultPromise, { done: false, // deno-lint-ignore no-explicit-any