summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-01-18 15:02:56 -0500
committerGitHub <noreply@github.com>2022-01-18 15:02:56 -0500
commit0f3a53e5d477ca2c422ed58a65bd368d1eb0a5b2 (patch)
tree43e8199a4b5831c01bfefd439b53a2098ee4805d
parentce52bfc59c6700e64dbe941485d078ceb9dd2158 (diff)
feat: stabilize test steps API (#13400)
-rw-r--r--cli/dts/lib.deno.ns.d.ts34
-rw-r--r--cli/dts/lib.deno.unstable.d.ts37
-rw-r--r--cli/tests/integration/test_tests.rs16
-rw-r--r--cli/tests/testdata/test/steps/no_unstable_flag.out13
-rw-r--r--cli/tests/testdata/test/steps/no_unstable_flag.ts4
-rw-r--r--runtime/js/40_testing.js12
-rw-r--r--runtime/js/99_main.js3
7 files changed, 38 insertions, 81 deletions
diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts
index e23f44d9a..46b4bda71 100644
--- a/cli/dts/lib.deno.ns.d.ts
+++ b/cli/dts/lib.deno.ns.d.ts
@@ -113,8 +113,40 @@ declare namespace Deno {
* See: https://no-color.org/ */
export const noColor: boolean;
- /** **UNSTABLE**: New option, yet to be vetted. */
export interface 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.
+ * If the test was ignored the promise returns `false`.
+ */
+ step(t: TestStepDefinition): Promise<boolean>;
+
+ /** 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.
+ * If the test was ignored the promise returns `false`.
+ */
+ step(
+ name: string,
+ fn: (t: TestContext) => void | Promise<void>,
+ ): Promise<boolean>;
+ }
+
+ export interface TestStepDefinition {
+ fn: (t: TestContext) => void | Promise<void>;
+ name: string;
+ ignore?: boolean;
+ /** Check that the number of async completed ops after the test step is the same
+ * as number of dispatched ops. Defaults to the parent test or step's value. */
+ sanitizeOps?: boolean;
+ /** Ensure the test step does not "leak" resources - ie. the resource table
+ * after the test has exactly the same contents as before the test. Defaults
+ * to the parent test or step's value. */
+ sanitizeResources?: boolean;
+ /** Ensure the test step does not prematurely cause the process to exit,
+ * for example via a call to `Deno.exit`. Defaults to the parent test or
+ * step's value. */
+ sanitizeExit?: boolean;
}
export interface TestDefinition {
diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts
index 82cb2cc8f..988f01c81 100644
--- a/cli/dts/lib.deno.unstable.d.ts
+++ b/cli/dts/lib.deno.unstable.d.ts
@@ -934,43 +934,6 @@ declare namespace Deno {
*/
export function sleepSync(millis: number): void;
- /** **UNSTABLE**: New option, yet to be vetted. */
- export interface TestContext {
- /** Run a sub step of the parent test with a given name. Returns a promise
- * that resolves to a boolean signifying if the step completed successfully.
- * The returned promise never rejects unless the arguments are invalid.
- * If the test was ignored, the promise returns `false`.
- */
- step(t: TestStepDefinition): Promise<boolean>;
-
- /** Run a sub step of the parent test with a given name. Returns a promise
- * that resolves to a boolean signifying if the step completed successfully.
- * The returned promise never rejects unless the arguments are invalid.
- * If the test was ignored, the promise returns `false`.
- */
- step(
- name: string,
- fn: (t: TestContext) => void | Promise<void>,
- ): Promise<boolean>;
- }
-
- /** **UNSTABLE**: New option, yet to be vetted. */
- export interface TestStepDefinition {
- fn: (t: TestContext) => void | Promise<void>;
- name: string;
- ignore?: boolean;
- /** Check that the number of async completed ops after the test is the same
- * as number of dispatched ops. Defaults to true. */
- sanitizeOps?: boolean;
- /** Ensure the test case does not "leak" resources - ie. the resource table
- * after the test has exactly the same contents as before the test. Defaults
- * to true. */
- sanitizeResources?: boolean;
- /** Ensure the test case does not prematurely cause the process to exit,
- * for example via a call to `Deno.exit`. Defaults to true. */
- sanitizeExit?: boolean;
- }
-
/** **UNSTABLE**: new API, yet to be vetted.
*
* A generic transport listener for message-oriented protocols. */
diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs
index 639b664c1..53dbb07d3 100644
--- a/cli/tests/integration/test_tests.rs
+++ b/cli/tests/integration/test_tests.rs
@@ -222,37 +222,31 @@ itest!(aggregate_error {
});
itest!(steps_passing_steps {
- args: "test --unstable test/steps/passing_steps.ts",
+ args: "test test/steps/passing_steps.ts",
exit_code: 0,
output: "test/steps/passing_steps.out",
});
itest!(steps_passing_steps_concurrent {
- args: "test --unstable --jobs=2 test/steps/passing_steps.ts",
+ args: "test --jobs=2 test/steps/passing_steps.ts",
exit_code: 0,
output: "test/steps/passing_steps.out",
});
itest!(steps_failing_steps {
- args: "test --unstable test/steps/failing_steps.ts",
+ args: "test test/steps/failing_steps.ts",
exit_code: 1,
output: "test/steps/failing_steps.out",
});
itest!(steps_ignored_steps {
- args: "test --unstable test/steps/ignored_steps.ts",
+ args: "test test/steps/ignored_steps.ts",
exit_code: 0,
output: "test/steps/ignored_steps.out",
});
itest!(steps_invalid_usage {
- args: "test --unstable test/steps/invalid_usage.ts",
+ args: "test test/steps/invalid_usage.ts",
exit_code: 1,
output: "test/steps/invalid_usage.out",
});
-
-itest!(steps_no_unstable_flag {
- args: "test test/steps/no_unstable_flag.ts",
- exit_code: 1,
- output: "test/steps/no_unstable_flag.out",
-});
diff --git a/cli/tests/testdata/test/steps/no_unstable_flag.out b/cli/tests/testdata/test/steps/no_unstable_flag.out
deleted file mode 100644
index 8fe6ba4f7..000000000
--- a/cli/tests/testdata/test/steps/no_unstable_flag.out
+++ /dev/null
@@ -1,13 +0,0 @@
-[WILDCARD]
-running 1 test from [WILDCARD]/no_unstable_flag.ts
-test description ... FAILED ([WILDCARD])
-
-failures:
-
-description
-Error: Test steps are unstable. The --unstable flag must be provided.
- at [WILDCARD]
-
-failures:
-
-[WILDCARD]
diff --git a/cli/tests/testdata/test/steps/no_unstable_flag.ts b/cli/tests/testdata/test/steps/no_unstable_flag.ts
deleted file mode 100644
index 737efba11..000000000
--- a/cli/tests/testdata/test/steps/no_unstable_flag.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-Deno.test("description", async (t) => {
- // deno-lint-ignore no-explicit-any
- await (t as any).step("step", () => {});
-});
diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js
index 118db5db1..92d7fe491 100644
--- a/runtime/js/40_testing.js
+++ b/runtime/js/40_testing.js
@@ -29,7 +29,6 @@
RegExpPrototypeTest,
SymbolToStringTag,
} = window.__bootstrap.primordials;
- let testStepsEnabled = false;
const opSanitizerDelayResolveQueue = [];
@@ -746,12 +745,6 @@ finishing test case.`;
* @param fn {(t: TestContext) => void | Promise<void>}
*/
async step(nameOrTestDefinition, fn) {
- if (!testStepsEnabled) {
- throw new Error(
- "Test steps are unstable. The --unstable flag must be provided.",
- );
- }
-
if (parentStep.finalized) {
throw new Error(
"Cannot run test step after parent scope has finished execution. " +
@@ -890,14 +883,9 @@ finishing test case.`;
return value == null ? defaultValue : value;
}
- function enableTestSteps() {
- testStepsEnabled = true;
- }
-
window.__bootstrap.internals = {
...window.__bootstrap.internals ?? {},
runTests,
- enableTestSteps,
};
window.__bootstrap.testing = {
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index 534a28733..0c5555dd0 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -214,9 +214,6 @@ delete Object.prototype.__proto__;
runtimeOptions.v8Version,
runtimeOptions.tsVersion,
);
- if (runtimeOptions.unstableFlag) {
- internals.enableTestSteps();
- }
build.setBuildInfo(runtimeOptions.target);
util.setLogDebug(runtimeOptions.debugFlag, source);
const prepareStackTrace = core.createPrepareStackTrace(