summaryrefslogtreecommitdiff
path: root/runtime/js/40_testing.js
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2021-10-12 09:58:04 -0400
committerGitHub <noreply@github.com>2021-10-12 09:58:04 -0400
commit9b1f0c8ba3c8ca7a7207519889b6509bfc10370e (patch)
tree8660a11544f221e1a295c5e98c5907532523f351 /runtime/js/40_testing.js
parentb1e7452cd310ead7e6379f694d660e935641e596 (diff)
chore: upgrade crates based on deno ast 0.3 (#12403)
Diffstat (limited to 'runtime/js/40_testing.js')
-rw-r--r--runtime/js/40_testing.js36
1 files changed, 26 insertions, 10 deletions
diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js
index 1fec58196..b55e5cc2c 100644
--- a/runtime/js/40_testing.js
+++ b/runtime/js/40_testing.js
@@ -35,10 +35,11 @@
// ops. Note that "unref" ops are ignored since in nature that are
// optional.
function assertOps(fn) {
- return async function asyncOpSanitizer(...params) {
+ /** @param step {TestStep} */
+ return async function asyncOpSanitizer(step) {
const pre = metrics();
try {
- await fn(...params);
+ await fn(step);
} finally {
// Defer until next event loop turn - that way timeouts and intervals
// cleared can actually be removed from resource table, otherwise
@@ -46,6 +47,10 @@
await new Promise((resolve) => setTimeout(resolve, 0));
}
+ if (step.hasRunningChildren) {
+ return; // test step validation error thrown, don't check ops
+ }
+
const post = metrics();
// We're checking diff because one might spawn HTTP server in the background
@@ -101,9 +106,15 @@ finishing test case.`;
function assertResources(
fn,
) {
- return async function resourceSanitizer(...params) {
+ /** @param step {TestStep} */
+ return async function resourceSanitizer(step) {
const pre = core.resources();
- await fn(...params);
+ await fn(step);
+
+ if (step.hasRunningChildren) {
+ return; // test step validation error thrown, don't check resources
+ }
+
const post = core.resources();
const preStr = JSONStringify(pre, null, 2);
@@ -195,11 +206,7 @@ finishing test case.`;
function postValidation() {
// check for any running steps
- const hasRunningSteps = ArrayPrototypeSome(
- step.children,
- (r) => r.status === "pending",
- );
- if (hasRunningSteps) {
+ if (step.hasRunningChildren) {
throw new Error(
"There were still test steps running after the current scope finished execution. " +
"Ensure all steps are awaited (ex. `await t.step(...)`).",
@@ -411,7 +418,7 @@ finishing test case.`;
const only = ArrayPrototypeFilter(tests, (test) => test.only);
const filtered = ArrayPrototypeFilter(
- (only.length > 0 ? only : tests),
+ only.length > 0 ? only : tests,
createTestFilter(filter),
);
@@ -485,6 +492,7 @@ finishing test case.`;
#reportedResult = false;
finalized = false;
elapsed = 0;
+ /** @type "ok" | "ignored" | "pending" | "failed" */
status = "pending";
error = undefined;
/** @type {TestStep[]} */
@@ -521,6 +529,14 @@ finishing test case.`;
this.#params.sanitizeExit;
}
+ get hasRunningChildren() {
+ return ArrayPrototypeSome(
+ this.children,
+ /** @param step {TestStep} */
+ (step) => step.status === "pending",
+ );
+ }
+
failedChildStepsCount() {
return ArrayPrototypeFilter(
this.children,