Skip to content

Commit

Permalink
WIP: fix denops#plugin#wait() tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Milly committed Jul 10, 2024
1 parent 34f63aa commit 0a4eab1
Showing 1 changed file with 83 additions and 37 deletions.
120 changes: 83 additions & 37 deletions tests/denops/runtime/functions/plugin_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
assertArrayIncludes,
assertEquals,
assertGreater,
assertLess,
assertMatch,
assertRejects,
} from "jsr:@std/[email protected]";
Expand All @@ -9,7 +11,6 @@ import { join } from "jsr:@std/[email protected]/join";
import { AsyncDisposableStack } from "jsr:@nick/[email protected]/async-disposable-stack";
import { testHost } from "/denops-testutil/host.ts";
import { wait } from "/denops-testutil/wait.ts";
import { promiseState } from "jsr:@lambdalisue/[email protected]";

const MESSAGE_DELAY = 200;

Expand Down Expand Up @@ -1733,25 +1734,35 @@ testHost({
// FIXME: This test will run infinitely on Mac.
await t.step({
name: "denops#plugin#wait()",
ignore: Deno.build.os === "darwin",
ignore: false, // Deno.build.os === "darwin",
fn: async (t) => {
console.log("NOTE: Testing 'wait()' may stop, so workaround delay...");
await delay(1000);

await t.step("if the plugin is loading", async (t) => {
await host.call("execute", [
"let g:__test_denops_events = []",
`call denops#plugin#load('dummyWaitLoading', '${scriptValidWait}')`,
], "");

const resultPromise = host.call(
"denops#plugin#wait",
"dummyWaitLoading",
);
"let g:__test_denops_wait_start = reltime()",
"let g:__test_denops_wait_result = denops#plugin#wait('dummyWaitLoading', {'timeout': 5000})",
"let g:__test_denops_wait_elapsed = g:__test_denops_wait_start->reltime()->reltimefloat()",
]);

await t.step("waits the plugin is loaded", async () => {
assertEquals(await promiseState(resultPromise), "pending");
const elapsed_sec = await host.call(
"eval",
"g:__test_denops_wait_elapsed",
) as number;
assertGreater(elapsed_sec, 1.0);
assertLess(elapsed_sec, 5.0);
});

await t.step("returns 0", async () => {
assertEquals(await resultPromise, 0);
const actual = await host.call(
"eval",
"g:__test_denops_wait_result",
);
assertEquals(actual, 0);
});

await t.step("the plugin is loaded after returns", async () => {
Expand All @@ -1773,17 +1784,26 @@ testHost({
.includes("DenopsPluginPost:dummyWaitLoaded")
);

const resultPromise = host.call(
"denops#plugin#wait",
"dummyWaitLoaded",
);
await host.call("execute", [
"let g:__test_denops_wait_start = reltime()",
"let g:__test_denops_wait_result = denops#plugin#wait('dummyWaitLoaded', {'timeout': 5000})",
"let g:__test_denops_wait_elapsed = g:__test_denops_wait_start->reltime()->reltimefloat()",
]);

await t.step("returns immediately", async () => {
await deadline(resultPromise, 100);
const elapsed_sec = await host.call(
"eval",
"g:__test_denops_wait_elapsed",
) as number;
assertLess(elapsed_sec, 0.1);
});

await t.step("returns 0", async () => {
assertEquals(await resultPromise, 0);
const actual = await host.call(
"eval",
"g:__test_denops_wait_result",
);
assertEquals(actual, 0);
});
});

Expand All @@ -1797,23 +1817,30 @@ testHost({
(await host.call("eval", "g:__test_denops_events") as string[])
.includes("DenopsPluginPost:dummyWaitReloading")
);
// Reload plugin.

await host.call("execute", [
"let g:__test_denops_events = []",
`call denops#plugin#reload('dummyWaitReloading')`,
], "");

const resultPromise = host.call(
"denops#plugin#wait",
"dummyWaitReloading",
);
"let g:__test_denops_wait_start = reltime()",
"let g:__test_denops_wait_result = denops#plugin#wait('dummyWaitReloading', {'timeout': 5000})",
"let g:__test_denops_wait_elapsed = g:__test_denops_wait_start->reltime()->reltimefloat()",
]);

await t.step("waits the plugin is loaded", async () => {
assertEquals(await promiseState(resultPromise), "pending");
const elapsed_sec = await host.call(
"eval",
"g:__test_denops_wait_elapsed",
) as number;
assertGreater(elapsed_sec, 1.0);
assertLess(elapsed_sec, 5.0);
});

await t.step("returns 0", async () => {
assertEquals(await resultPromise, 0);
const actual = await host.call(
"eval",
"g:__test_denops_wait_result",
);
assertEquals(actual, 0);
});

await t.step("the plugin is loaded after returns", async () => {
Expand Down Expand Up @@ -1844,17 +1871,26 @@ testHost({
.includes("DenopsPluginPost:dummyWaitReloaded")
);

const resultPromise = host.call(
"denops#plugin#wait",
"dummyWaitReloaded",
);
await host.call("execute", [
"let g:__test_denops_wait_start = reltime()",
"let g:__test_denops_wait_result = denops#plugin#wait('dummyWaitReloaded', {'timeout': 5000})",
"let g:__test_denops_wait_elapsed = g:__test_denops_wait_start->reltime()->reltimefloat()",
]);

await t.step("returns immediately", async () => {
await deadline(resultPromise, 100);
const elapsed_sec = await host.call(
"eval",
"g:__test_denops_wait_elapsed",
) as number;
assertLess(elapsed_sec, 0.1);
});

await t.step("returns 0", async () => {
assertEquals(await resultPromise, 0);
const actual = await host.call(
"eval",
"g:__test_denops_wait_result",
);
assertEquals(actual, 0);
});
});

Expand All @@ -1864,17 +1900,27 @@ testHost({
`call denops#plugin#load('dummyWaitInvalid', '${scriptInvalidWait}')`,
], "");

const resultPromise = host.call(
"denops#plugin#wait",
"dummyWaitInvalid",
);
await host.call("execute", [
"let g:__test_denops_wait_start = reltime()",
"let g:__test_denops_wait_result = denops#plugin#wait('dummyWaitInvalid', {'timeout': 5000})",
"let g:__test_denops_wait_elapsed = g:__test_denops_wait_start->reltime()->reltimefloat()",
]);

await t.step("waits the plugin is failed", async () => {
assertEquals(await promiseState(resultPromise), "pending");
const elapsed_sec = await host.call(
"eval",
"g:__test_denops_wait_elapsed",
) as number;
assertGreater(elapsed_sec, 1.0);
assertLess(elapsed_sec, 5.0);
});

await t.step("returns -3", async () => {
assertEquals(await resultPromise, -3);
const actual = await host.call(
"eval",
"g:__test_denops_wait_result",
);
assertEquals(actual, -3);
});

await t.step("the plugin is failed after returns", async () => {
Expand Down

0 comments on commit 0a4eab1

Please sign in to comment.