Skip to content

Commit 5a22b02

Browse files
committed
🌿 easier to understand test intent
1 parent 8a54da8 commit 5a22b02

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

tests/denops/runtime/functions/denops/interrupt_test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ testHost({
5151

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

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

@@ -70,6 +71,7 @@ testHost({
7071
);
7172
});
7273

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

7577
await t.step("sends signal to the plugin with reason", async () => {

tests/denops/runtime/functions/denops/notify_test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { resolveTestDataPath } from "/denops-testdata/resolve.ts";
55
import { testHost } from "/denops-testutil/host.ts";
66
import { wait } from "/denops-testutil/wait.ts";
77

8-
const ASYNC_DELAY = 100;
98
const MESSAGE_DELAY = 200;
109

1110
const scriptDispatcher = resolveTestDataPath("dummy_dispatcher_plugin.ts");
@@ -58,7 +57,7 @@ testHost({
5857
});
5958

6059
await t.step("calls dispatcher method", async () => {
61-
await delay(100 + ASYNC_DELAY);
60+
await wait(() => host.call("eval", "len(g:__test_denops_events)"));
6261
assertEquals(await host.call("eval", "g:__test_denops_events"), [
6362
'DummyDispatcherPlugin:TestCalled:["foo"]',
6463
]);

tests/denops/runtime/functions/denops/request_async_test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ import {
33
assertEquals,
44
assertObjectMatch,
55
} from "jsr:@std/assert@^1.0.1";
6-
import { delay } from "jsr:@std/async@^1.0.1/delay";
76
import { INVALID_PLUGIN_NAMES } from "/denops-testdata/invalid_plugin_names.ts";
87
import { resolveTestDataPath } from "/denops-testdata/resolve.ts";
98
import { testHost } from "/denops-testutil/host.ts";
109
import { wait } from "/denops-testutil/wait.ts";
1110

12-
const ASYNC_DELAY = 100;
13-
1411
const scriptDispatcher = resolveTestDataPath("dummy_dispatcher_plugin.ts");
1512

1613
testHost({
@@ -99,7 +96,7 @@ testHost({
9996
});
10097

10198
await t.step("calls dispatcher method", async () => {
102-
await delay(100 + ASYNC_DELAY);
99+
await wait(() => host.call("eval", "len(g:__test_denops_events)"));
103100
assertArrayIncludes(
104101
await host.call("eval", "g:__test_denops_events") as unknown[],
105102
['DummyDispatcherPlugin:TestCalled:["foo"]'],

tests/denops/testdata/dummy_dispatcher_plugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { delay } from "jsr:@std/async@^1.0.1/delay";
22
import type { Entrypoint } from "jsr:@denops/core@^7.0.0";
33

4+
const MIMIC_DISPATCHER_METHOD_DELAY = 100;
5+
46
export const main: Entrypoint = (denops) => {
57
denops.dispatcher = {
68
test: async (...args) => {
7-
await delay(100);
9+
await delay(MIMIC_DISPATCHER_METHOD_DELAY);
810
await denops.cmd(
911
`doautocmd <nomodeline> User DummyDispatcherPlugin:TestCalled:${
1012
JSON.stringify(args).replaceAll(/[ \\"]/g, "\\$&")

tests/denops/testdata/dummy_interrupt_plugin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import type { Entrypoint } from "jsr:@denops/core@^7.0.0";
22
import { delay } from "jsr:@std/async@^1.0.1/delay";
33

4+
const MIMIC_ABORT_DELAY = 100;
5+
46
export const main: Entrypoint = (denops) => {
7+
/** Reset interrupt event handler. */
58
function reset(): void {
69
const signal = denops.interrupted;
710
signal?.addEventListener("abort", async () => {
8-
await delay(100);
11+
await delay(MIMIC_ABORT_DELAY);
912
await denops.cmd(
1013
`doautocmd <nomodeline> User DummyInterruptPlugin:Interrupted:${
1114
String(signal.reason).replaceAll(/[ \\"]/g, "\\$&")

0 commit comments

Comments
 (0)