Repository: denoland/deno
Pull request: fix: wpt assert expectation correctly even if the filter has a layer

<!--
Before submitting a PR, please read https://docs.deno.com/runtime/manual/references/contributing

1. Give the PR a descriptive title.

  Examples of good title:
    - fix(std/http): Fix race condition in server
    - docs(console): Update docstrings
    - feat(doc): Handle nested reexports

  Examples of bad title:
    - fix #7123
    - update docs
    - fix bugs

2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
7. Open as a draft PR if your work is still in progress. The CI won't run
   all steps, but you can add '[ci]' to a commit message to force it to.
8. If you would like to run the benchmarks on the CI, add the 'ci-bench' label.
-->

related: #30501

I fixed to assert properly even if the filter has a layer as follows:

```
./tests/wpt/wpt.ts run -- WebCryptoAPI/import_export
```

Changed files:
filename: tests/wpt/wpt.ts
patch: @@ -64,6 +64,24 @@ class TestFilter {
     }
     return false;
   }
+
+  shouldKeepWalking(path): boolean {
+    if (this.filter === undefined || this.filter.length == 0) {
+      return true;
+    }
+    for (const filter of this.filter) {
+      if (filter.startsWith("/")) {
+        if (filter.startsWith(path)) {
+          return true;
+        }
+      } else {
+        if (filter.startsWith(path.substring(1))) {
+          return true;
+        }
+      }
+    }
+    return false;
+  }
 }
 
 const command = Deno.args[0];
@@ -188,8 +206,8 @@ function getTestTimeout(test: TestToRun) {
 }
 
 async function run() {
-  const startTime = new Date().getTime();
   assert(Array.isArray(rest), "filter must be array");
+  const startTime = Date.now();
   const expectation = getExpectation();
   const filter = new TestFilter(rest);
   const tests = discoverTestsToRun(
@@ -233,7 +251,7 @@ async function run() {
 
     return results;
   });
-  const endTime = new Date().getTime();
+  const endTime = Date.now();
 
   if (json) {
     const minifiedResults = [];
@@ -342,7 +360,16 @@ function assertAllExpectationsHaveTests(
   function walk(parentExpectation: Expectation, parent: string) {
     for (const [key, expectation] of Object.entries(parentExpectation)) {
       const path = `${parent}/${key}`;
-      if (!filter.matches(path)) continue;
+      if (!filter.matches(path)) {
+        if (
+          filter.shouldKeepWalking(path) &&
+          (typeof expectation === "object" && !Array.isArray(expectation)) &&
+          key !== "ignore"
+        ) {
+          walk(expectation, path);
+        }
+        continue;
+      }
       if (
         (typeof expectation == "boolean" || Array.isArray(expectation)) &&
         key !== "ignore"
@@ -372,7 +399,7 @@ function assertAllExpectationsHaveTests(
 
 async function update() {
   assert(Array.isArray(rest), "filter must be array");
-  const startTime = new Date().getTime();
+  const startTime = Date.now();
   const filter = new TestFilter(rest);
   const tests = discoverTestsToRun(filter, true);
   console.log(`Going to run ${tests.length} test files.`);
@@ -395,7 +422,7 @@ async function update() {
 
     return results;
   });
-  const endTime = new Date().getTime();
+  const endTime = Date.now();
 
   if (json) {
     await Deno.writeTextFile(json, JSON.stringify(results) + "\n");