From 65bba2b87e4bc2e1ba0e673caf43974a432acc25 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Thu, 23 Apr 2020 13:40:16 +0100 Subject: refactor(cli/js/testing): Rename disableOpSanitizer to sanitizeOps (#4854) * rename disableOpSanitizer to sanitizeOps * rename disableResourceSanitizer to sanitizeResources --- cli/js/lib.deno.ns.d.ts | 4 ++-- cli/js/testing.ts | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'cli/js') diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts index eb61f2331..9980790b3 100644 --- a/cli/js/lib.deno.ns.d.ts +++ b/cli/js/lib.deno.ns.d.ts @@ -16,8 +16,8 @@ declare namespace Deno { fn: () => void | Promise; name: string; ignore?: boolean; - disableOpSanitizer?: boolean; - disableResourceSanitizer?: boolean; + sanitizeOps?: boolean; + sanitizeResources?: boolean; } /** Register a test which will be run when `deno test` is used on the command diff --git a/cli/js/testing.ts b/cli/js/testing.ts index 542e1d065..6c56a2f71 100644 --- a/cli/js/testing.ts +++ b/cli/js/testing.ts @@ -80,8 +80,8 @@ export interface TestDefinition { fn: () => void | Promise; name: string; ignore?: boolean; - disableOpSanitizer?: boolean; - disableResourceSanitizer?: boolean; + sanitizeOps?: boolean; + sanitizeResources?: boolean; } const TEST_REGISTRY: TestDefinition[] = []; @@ -96,6 +96,11 @@ export function test( fn?: () => void | Promise ): void { let testDef: TestDefinition; + const defaults = { + ignore: false, + sanitizeOps: true, + sanitizeResources: true, + }; if (typeof t === "string") { if (!fn || typeof fn != "function") { @@ -104,12 +109,12 @@ export function test( if (!t) { throw new TypeError("The test name can't be empty"); } - testDef = { fn: fn as () => void | Promise, name: t, ignore: false }; + testDef = { fn: fn as () => void | Promise, name: t, ...defaults }; } else if (typeof t === "function") { if (!t.name) { throw new TypeError("The test function can't be anonymous"); } - testDef = { fn: t, name: t.name, ignore: false }; + testDef = { fn: t, name: t.name, ...defaults }; } else { if (!t.fn) { throw new TypeError("Missing test function"); @@ -117,14 +122,14 @@ export function test( if (!t.name) { throw new TypeError("The test name can't be empty"); } - testDef = { ...t, ignore: Boolean(t.ignore) }; + testDef = { ...defaults, ...t }; } - if (testDef.disableOpSanitizer !== true) { + if (testDef.sanitizeOps) { testDef.fn = assertOps(testDef.fn); } - if (testDef.disableResourceSanitizer !== true) { + if (testDef.sanitizeResources) { testDef.fn = assertResources(testDef.fn); } -- cgit v1.2.3