summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/dts/lib.deno.ns.d.ts19
-rw-r--r--cli/tests/unit/testing_test.ts32
2 files changed, 50 insertions, 1 deletions
diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts
index d55ac231e..485b3d490 100644
--- a/cli/dts/lib.deno.ns.d.ts
+++ b/cli/dts/lib.deno.ns.d.ts
@@ -250,6 +250,19 @@ declare namespace Deno {
}
export interface TestContext {
+ /**
+ * The current test name.
+ */
+ name: string;
+ /**
+ * File Uri of the current test code.
+ */
+ origin: string;
+ /**
+ * Parent test context.
+ */
+ parent?: TestContext;
+
/** Run a sub step of the parent test or step. Returns a promise
* that resolves to a boolean signifying if the step completed successfully.
* The returned promise never rejects unless the arguments are invalid.
@@ -270,6 +283,9 @@ declare namespace Deno {
export interface TestStepDefinition {
fn: (t: TestContext) => void | Promise<void>;
+ /**
+ * The current test name.
+ */
name: string;
ignore?: boolean;
/** Check that the number of async completed ops after the test step is the same
@@ -287,6 +303,9 @@ declare namespace Deno {
export interface TestDefinition {
fn: (t: TestContext) => void | Promise<void>;
+ /**
+ * The current test name.
+ */
name: string;
ignore?: boolean;
/** If at least one test has `only` set to true, only run tests that have
diff --git a/cli/tests/unit/testing_test.ts b/cli/tests/unit/testing_test.ts
index 87b862a7d..90575aeb2 100644
--- a/cli/tests/unit/testing_test.ts
+++ b/cli/tests/unit/testing_test.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
-import { assertRejects, assertThrows } from "./test_util.ts";
+import { assertEquals, assertRejects, assertThrows } from "./test_util.ts";
Deno.test(function testWrongOverloads() {
assertThrows(
@@ -117,3 +117,33 @@ Deno.test(async function invalidStepArguments(t) {
"Expected a test definition or name and function.",
);
});
+
+Deno.test(async function nameOnTextContext(t1) {
+ await assertEquals(t1.name, "nameOnTextContext");
+ await t1.step("step", async (t2) => {
+ await assertEquals(t2.name, "step");
+ await t2.step("nested step", async (t3) => {
+ await assertEquals(t3.name, "nested step");
+ });
+ });
+});
+
+Deno.test(async function originOnTextContext(t1) {
+ await assertEquals(t1.origin, Deno.mainModule);
+ await t1.step("step", async (t2) => {
+ await assertEquals(t2.origin, Deno.mainModule);
+ await t2.step("nested step", async (t3) => {
+ await assertEquals(t3.origin, Deno.mainModule);
+ });
+ });
+});
+
+Deno.test(async function parentOnTextContext(t1) {
+ await assertEquals(t1.parent, undefined);
+ await t1.step("step", async (t2) => {
+ await assertEquals(t1, t2.parent);
+ await t2.step("nested step", async (t3) => {
+ await assertEquals(t2, t3.parent);
+ });
+ });
+});