From 0df18542499d1220f1182496d3b7028eef243eb0 Mon Sep 17 00:00:00 2001 From: Yongwook Choi Date: Wed, 6 Apr 2022 23:51:38 +0900 Subject: feat(test): Add "name", "origin" and "parent" to "Deno.TestContext" (#14007) This commit adds following fields to "Deno.TestContext" interface: - name - origin - parent These are prerequisites for supporting snapshot functionality in "std/testing". --- runtime/js/40_testing.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'runtime/js/40_testing.js') diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js index abbef2ae4..0b75daa24 100644 --- a/runtime/js/40_testing.js +++ b/runtime/js/40_testing.js @@ -792,6 +792,7 @@ const step = new TestStep({ name: test.name, parent: undefined, + parentContext: undefined, rootTestDescription: description, sanitizeOps: test.sanitizeOps, sanitizeResources: test.sanitizeResources, @@ -1064,8 +1065,9 @@ * }} TestStepDefinition * * @typedef {{ - * name: string; + * name: string, * parent: TestStep | undefined, + * parentContext: TestContext | undefined, * rootTestDescription: { origin: string; name: string }; * sanitizeOps: boolean, * sanitizeResources: boolean, @@ -1099,6 +1101,10 @@ return this.#params.parent; } + get parentContext() { + return this.#params.parentContext; + } + get rootTestDescription() { return this.#params.rootTestDescription; } @@ -1268,6 +1274,18 @@ function createTestContext(parentStep) { return { [SymbolToStringTag]: "TestContext", + /** + * The current test name. + */ + name: parentStep.name, + /** + * Parent test context. + */ + parent: parentStep.parentContext ?? undefined, + /** + * File Uri of the test code. + */ + origin: parentStep.rootTestDescription.origin, /** * @param nameOrTestDefinition {string | TestStepDefinition} * @param fn {(t: TestContext) => void | Promise} @@ -1284,6 +1302,7 @@ const subStep = new TestStep({ name: definition.name, parent: parentStep, + parentContext: this, rootTestDescription: parentStep.rootTestDescription, sanitizeOps: getOrDefault( definition.sanitizeOps, -- cgit v1.2.3