From 9a5d82ed88133ec5f4a6ca9748c2c392b67b0c9b Mon Sep 17 00:00:00 2001 From: Dayoung Lee Date: Thu, 12 Oct 2023 15:40:04 +0900 Subject: [PATCH] [Test] Fix async test (#1707) This commit fixes async tests and adds a related exception throwing. ONE-vscode-DCO-1.0-Signed-off-by: Dayoung Lee --- src/Tests/MPQEditor/MPQEditor.test.ts | 2 +- src/Tests/Utils/Hash.test.ts | 1 - src/Utils/Hash.ts | 8 ++++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Tests/MPQEditor/MPQEditor.test.ts b/src/Tests/MPQEditor/MPQEditor.test.ts index 76923ad19..27ade9f85 100644 --- a/src/Tests/MPQEditor/MPQEditor.test.ts +++ b/src/Tests/MPQEditor/MPQEditor.test.ts @@ -151,7 +151,7 @@ suite("MPQEditor", function () { await MPQEditorProvider.updateDocumentBy(document, newJson); - document.save(); + await document.save(); const newJsonText: string = document.getText(); const newCont = JSON.parse(newJsonText); assert.strictEqual(newCont["default_quantization_dtype"], "int16"); diff --git a/src/Tests/Utils/Hash.test.ts b/src/Tests/Utils/Hash.test.ts index 12e1b4f55..1f8bf934c 100644 --- a/src/Tests/Utils/Hash.test.ts +++ b/src/Tests/Utils/Hash.test.ts @@ -46,7 +46,6 @@ suite("Utils", function () { const notExistingPath = testBuilder.getPath("non-existing"); generateHash(vscode.Uri.file(notExistingPath)).catch(() => { pass(); - assert.ok(true); }); }); }); diff --git a/src/Utils/Hash.ts b/src/Utils/Hash.ts index d653953d6..349dbf947 100644 --- a/src/Utils/Hash.ts +++ b/src/Utils/Hash.ts @@ -15,10 +15,14 @@ */ import * as crypto from "crypto"; +import fs from "fs"; import vscode from "vscode"; -export async function generateHash(uri: vscode.Uri) { - // TODO: Error handling +export async function generateHash(uri: vscode.Uri): Promise { + if (!fs.existsSync(uri.fsPath)) { + throw new Error(`File does not exists at ${uri.fsPath}`); + } + return crypto .createHash("sha256") .update(Buffer.from(await vscode.workspace.fs.readFile(uri)).toString())