Skip to content

Commit

Permalink
test: use sleep inside the mock for lsp process
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed May 13, 2021
1 parent 9599d7d commit 6f03b0b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(resolveValue: T, ms: number) {
return new Promise<T>((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")
}
Expand Down

0 comments on commit 6f03b0b

Please sign in to comment.