From 6f03b0b17697f2bfdaa0f941d100420e10d74e1a Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 13 May 2021 06:19:26 -0500 Subject: [PATCH] test: use sleep inside the mock for lsp process --- test/helpers.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/helpers.ts b/test/helpers.ts index c42f68c1..aac53f0e 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -45,8 +45,17 @@ export function createFakeEditor(path?: string): TextEditor { return editor } +/** A function that sleeps for a preiod of `ms` and the resolves the given value */ +function sleep(resolveValue: T, ms: number) { + return new Promise((resolve) => { + setTimeout(() => resolve(resolveValue), ms) + }) +} + export function createFakeLanguageServerProcess(): LanguageServerProcess { - spawn("lsp").exit(0).stdout("hello from lsp") + spawn("lsp") + .exit(() => sleep(0, 1000)) + .stdout("hello from lsp") // eslint-disable-next-line @typescript-eslint/no-var-requires return require("child_process").spawn("lsp") }