Skip to content

Commit

Permalink
[Test] Fix async test (#1707)
Browse files Browse the repository at this point in the history
This commit fixes async tests and adds a related exception throwing.

ONE-vscode-DCO-1.0-Signed-off-by: Dayoung Lee <[email protected]>
  • Loading branch information
dayo09 authored Oct 12, 2023
1 parent b8ce2ea commit 9a5d82e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Tests/MPQEditor/MPQEditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 0 additions & 1 deletion src/Tests/Utils/Hash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ suite("Utils", function () {
const notExistingPath = testBuilder.getPath("non-existing");
generateHash(vscode.Uri.file(notExistingPath)).catch(() => {
pass();
assert.ok(true);
});
});
});
Expand Down
8 changes: 6 additions & 2 deletions src/Utils/Hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
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())
Expand Down

0 comments on commit 9a5d82e

Please sign in to comment.