Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Senryoku committed Apr 23, 2024
1 parent 7b5347c commit 2fc0f4e
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions ts-lib/test/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { randomBytes } from "crypto";

export const json_512kb = import("../../test/data/512KB.json");
export const json_1mb = import("../../test/data/1MB.json");
export const rw_medium = import("../../test/data/rw_medium.json");
Expand All @@ -14,20 +16,17 @@ export const TestData = [
{ name: "rw_large", input: JSON.stringify(await rw_large) },
];

function getCrypto() {
export function randomStr(len: number) {
try {
return window.crypto;
} catch {
return crypto;
var arr = new Uint8Array(len);
window.crypto.getRandomValues(arr);
return new TextDecoder().decode(arr);
} catch (e) {
const arr = randomBytes(len);
return new TextDecoder().decode(arr);
}
}

export function randomStr(len: number) {
var arr = new Uint8Array(len);
getCrypto().getRandomValues(arr);
return new TextDecoder().decode(arr);
}

for (let i = 0; i < 10; ++i) {
TestData.push({
name: `Random string #${i}`,
Expand Down

0 comments on commit 2fc0f4e

Please sign in to comment.