summaryrefslogtreecommitdiff
path: root/cli/js/tests/test_util.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js/tests/test_util.ts')
-rw-r--r--cli/js/tests/test_util.ts50
1 files changed, 26 insertions, 24 deletions
diff --git a/cli/js/tests/test_util.ts b/cli/js/tests/test_util.ts
index 980d32bac..da2e917f8 100644
--- a/cli/js/tests/test_util.ts
+++ b/cli/js/tests/test_util.ts
@@ -10,7 +10,7 @@ export {
assertStrictEq,
assertStrContains,
unreachable,
- fail
+ fail,
} from "../../../std/testing/asserts.ts";
export { readLines } from "../../../std/io/bufio.ts";
export { parse as parseArgs } from "../../../std/flags/mod.ts";
@@ -28,7 +28,7 @@ export interface Permissions {
export function fmtPerms(perms: Permissions): string {
const p = Object.keys(perms)
.filter((e): boolean => perms[e as keyof Permissions] === true)
- .map(key => `--allow-${key}`);
+ .map((key) => `--allow-${key}`);
if (p.length) {
return p.join(" ");
@@ -48,7 +48,7 @@ export async function getProcessPermissions(): Promise<Permissions> {
net: await isGranted("net"),
env: await isGranted("env"),
plugin: await isGranted("plugin"),
- hrtime: await isGranted("hrtime")
+ hrtime: await isGranted("hrtime"),
};
}
@@ -108,7 +108,7 @@ function normalizeTestPermissions(perms: UnitTestPermissions): Permissions {
run: !!perms.run,
env: !!perms.env,
plugin: !!perms.plugin,
- hrtime: !!perms.hrtime
+ hrtime: !!perms.hrtime,
};
}
@@ -170,7 +170,7 @@ export function unitTest(
name,
fn,
ignore: !!options.ignore,
- perms: normalizedPerms
+ perms: normalizedPerms,
};
REGISTERED_UNIT_TESTS.push(unitTestDefinition);
@@ -194,17 +194,19 @@ export function createResolvable<T>(): Resolvable<T> {
return Object.assign(promise, methods!) as Resolvable<T>;
}
+const encoder = new TextEncoder();
+
export class SocketReporter implements Deno.TestReporter {
- private encoder: TextEncoder;
+ #conn: Deno.Conn;
- constructor(private conn: Deno.Conn) {
- this.encoder = new TextEncoder();
+ constructor(conn: Deno.Conn) {
+ this.#conn = conn;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async write(msg: any): Promise<void> {
- const encodedMsg = this.encoder.encode(JSON.stringify(msg) + "\n");
- await Deno.writeAll(this.conn, encodedMsg);
+ const encodedMsg = encoder.encode(JSON.stringify(msg) + "\n");
+ await Deno.writeAll(this.#conn, encodedMsg);
}
async start(msg: Deno.TestEventStart): Promise<void> {
@@ -229,9 +231,9 @@ export class SocketReporter implements Deno.TestReporter {
}
async end(msg: Deno.TestEventEnd): Promise<void> {
- const encodedMsg = this.encoder.encode(JSON.stringify(msg));
- await Deno.writeAll(this.conn, encodedMsg);
- this.conn.closeWrite();
+ const encodedMsg = encoder.encode(JSON.stringify(msg));
+ await Deno.writeAll(this.#conn, encodedMsg);
+ this.#conn.closeWrite();
}
}
@@ -245,7 +247,7 @@ unitTest(function permissionsMatches(): void {
env: false,
run: false,
plugin: false,
- hrtime: false
+ hrtime: false,
},
normalizeTestPermissions({ read: true })
)
@@ -260,7 +262,7 @@ unitTest(function permissionsMatches(): void {
env: false,
run: false,
plugin: false,
- hrtime: false
+ hrtime: false,
},
normalizeTestPermissions({})
)
@@ -275,7 +277,7 @@ unitTest(function permissionsMatches(): void {
env: true,
run: true,
plugin: true,
- hrtime: true
+ hrtime: true,
},
normalizeTestPermissions({ read: true })
),
@@ -291,7 +293,7 @@ unitTest(function permissionsMatches(): void {
env: false,
run: false,
plugin: false,
- hrtime: false
+ hrtime: false,
},
normalizeTestPermissions({ read: true })
),
@@ -307,7 +309,7 @@ unitTest(function permissionsMatches(): void {
env: true,
run: true,
plugin: true,
- hrtime: true
+ hrtime: true,
},
{
read: true,
@@ -316,7 +318,7 @@ unitTest(function permissionsMatches(): void {
env: true,
run: true,
plugin: true,
- hrtime: true
+ hrtime: true,
}
)
);
@@ -330,9 +332,9 @@ unitTest(
{ perms: { read: true } },
function assertAllUnitTestFilesImported(): void {
const directoryTestFiles = Deno.readdirSync("./cli/js/tests/")
- .map(k => k.name)
+ .map((k) => k.name)
.filter(
- file =>
+ (file) =>
file!.endsWith(".ts") &&
!file!.endsWith("unit_tests.ts") &&
!file!.endsWith("test_util.ts") &&
@@ -344,12 +346,12 @@ unitTest(
const importLines = new TextDecoder("utf-8")
.decode(unitTestsFile)
.split("\n")
- .filter(line => line.startsWith("import"));
+ .filter((line) => line.startsWith("import"));
const importedTestFiles = importLines.map(
- relativeFilePath => relativeFilePath.match(/\/([^\/]+)";/)![1]
+ (relativeFilePath) => relativeFilePath.match(/\/([^\/]+)";/)![1]
);
- directoryTestFiles.forEach(dirFile => {
+ directoryTestFiles.forEach((dirFile) => {
if (!importedTestFiles.includes(dirFile!)) {
throw new Error(
"cil/js/tests/unit_tests.ts is missing import of test file: cli/js/" +