Skip to content

Commit

Permalink
🌿 easier to understand test intent
Browse files Browse the repository at this point in the history
  • Loading branch information
Milly committed Sep 18, 2024
1 parent 8a54da8 commit 5a22b02
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 2 additions & 0 deletions tests/denops/runtime/functions/denops/interrupt_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ testHost({

await host.call("denops#interrupt");

// It should passed because of delay(MIMIC_ABORT_DELAY) in dummy_interrupt_plugin.ts
assertEquals(await host.call("eval", "g:__test_denops_events"), []);
});

Expand All @@ -70,6 +71,7 @@ testHost({
);
});

// Reset interrupt event handler.
await host.call("denops#request", "dummy", "reset", []);

await t.step("sends signal to the plugin with reason", async () => {
Expand Down
3 changes: 1 addition & 2 deletions tests/denops/runtime/functions/denops/notify_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { resolveTestDataPath } from "/denops-testdata/resolve.ts";
import { testHost } from "/denops-testutil/host.ts";
import { wait } from "/denops-testutil/wait.ts";

const ASYNC_DELAY = 100;
const MESSAGE_DELAY = 200;

const scriptDispatcher = resolveTestDataPath("dummy_dispatcher_plugin.ts");
Expand Down Expand Up @@ -58,7 +57,7 @@ testHost({
});

await t.step("calls dispatcher method", async () => {
await delay(100 + ASYNC_DELAY);
await wait(() => host.call("eval", "len(g:__test_denops_events)"));
assertEquals(await host.call("eval", "g:__test_denops_events"), [
'DummyDispatcherPlugin:TestCalled:["foo"]',
]);
Expand Down
5 changes: 1 addition & 4 deletions tests/denops/runtime/functions/denops/request_async_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import {
assertEquals,
assertObjectMatch,
} from "jsr:@std/assert@^1.0.1";
import { delay } from "jsr:@std/async@^1.0.1/delay";
import { INVALID_PLUGIN_NAMES } from "/denops-testdata/invalid_plugin_names.ts";
import { resolveTestDataPath } from "/denops-testdata/resolve.ts";
import { testHost } from "/denops-testutil/host.ts";
import { wait } from "/denops-testutil/wait.ts";

const ASYNC_DELAY = 100;

const scriptDispatcher = resolveTestDataPath("dummy_dispatcher_plugin.ts");

testHost({
Expand Down Expand Up @@ -99,7 +96,7 @@ testHost({
});

await t.step("calls dispatcher method", async () => {
await delay(100 + ASYNC_DELAY);
await wait(() => host.call("eval", "len(g:__test_denops_events)"));
assertArrayIncludes(
await host.call("eval", "g:__test_denops_events") as unknown[],
['DummyDispatcherPlugin:TestCalled:["foo"]'],
Expand Down
4 changes: 3 additions & 1 deletion tests/denops/testdata/dummy_dispatcher_plugin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { delay } from "jsr:@std/async@^1.0.1/delay";
import type { Entrypoint } from "jsr:@denops/core@^7.0.0";

const MIMIC_DISPATCHER_METHOD_DELAY = 100;

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
test: async (...args) => {
await delay(100);
await delay(MIMIC_DISPATCHER_METHOD_DELAY);
await denops.cmd(
`doautocmd <nomodeline> User DummyDispatcherPlugin:TestCalled:${
JSON.stringify(args).replaceAll(/[ \\"]/g, "\\$&")
Expand Down
5 changes: 4 additions & 1 deletion tests/denops/testdata/dummy_interrupt_plugin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import type { Entrypoint } from "jsr:@denops/core@^7.0.0";
import { delay } from "jsr:@std/async@^1.0.1/delay";

const MIMIC_ABORT_DELAY = 100;

export const main: Entrypoint = (denops) => {
/** Reset interrupt event handler. */
function reset(): void {
const signal = denops.interrupted;
signal?.addEventListener("abort", async () => {
await delay(100);
await delay(MIMIC_ABORT_DELAY);
await denops.cmd(
`doautocmd <nomodeline> User DummyInterruptPlugin:Interrupted:${
String(signal.reason).replaceAll(/[ \\"]/g, "\\$&")
Expand Down

0 comments on commit 5a22b02

Please sign in to comment.