From bc885f4612886ee89954aeffe49f1910ef16c00d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 22 Jun 2021 22:07:26 +0200 Subject: [PATCH] Unit test fix --- .vscode/settings.json | 7 ------- remote.ts | 6 +++++- server.ts | 7 +++---- testing.ts | 2 +- 4 files changed, 9 insertions(+), 13 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 19f1d80..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "typescript.tsdk": "node_modules/typescript/lib", - "deno.enable": true, - "deno.suggest.imports.hosts": { - "https://deno.land": false - } -} diff --git a/remote.ts b/remote.ts index 8b3229c..720c133 100644 --- a/remote.ts +++ b/remote.ts @@ -49,10 +49,14 @@ export class RestRemoteStorage implements KeyValueStorage { [HEADER_REQUESTER]: this.appname, }, }); + // the body is consumed here to not leak resource, but it would + // be better to consume it only when needed, once + // https://github.com/denoland/deno/issues/4735 is fixed + const text = await response.text(); if (response.headers.get(HEADER_REPLYIER) != "ok") { throw new Error("storage not compatible with tk-storage"); } else if (response.status == 200) { - return await response.text(); + return text; } else if (response.status == 404) { return null; } else { diff --git a/server.ts b/server.ts index 6c14d36..6fadaa6 100755 --- a/server.ts +++ b/server.ts @@ -56,10 +56,9 @@ export function startRestServer( return new Promise((resolve) => { const server = app.listen(port, () => { resolve({ - close: () => - new Promise((resolve, reject) => { - server.close(); - }), + close: async () => { + server.close(); + }, }); }); }); diff --git a/testing.ts b/testing.ts index ac3ab75..82066e7 100644 --- a/testing.ts +++ b/testing.ts @@ -31,7 +31,7 @@ export async function disableLocalStorage( const removed = ns["localStorage"]; delete ns["localStorage"]; try { - await body; + await body(); } finally { ns["localStorage"] = removed; }