Skip to content

Commit

Permalink
Add test for invalid import assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Sep 30, 2022
1 parent 3f80923 commit 6382a5b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,7 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="module">

function ticker(max) {
let i = 0;
let stop = false;
Promise.resolve().then(function loop() {
if (stop || i >= max) return;
i++;
Promise.resolve().then(loop);
});
return () => {
stop = true;
return i;
};
}
import { ticker } from "./ticker.js";

promise_test(async t => {
const getCount = ticker(1000);
Expand All @@ -30,16 +17,16 @@
}, "import() should not drain the microtask queue if it fails during specifier resolution");

promise_test(async t => {
await import("./../imports-a.js");
await import("./../../imports-a.js");

const getCount = ticker(1000);
await import("./../imports-a.js");
await import("./../../imports-a.js");
assert_less_than(getCount(), 1000);
}, "import() should not drain the microtask queue when loading an already loaded module");

promise_test(async t => {
const getCount = ticker(1e7);
await import("./../imports-a.js?" + Date.now()); // Use Date.now() to ensure that the module is not in the module map
await import("./../../imports-a.js?" + Date.now()); // Use Date.now() to ensure that the module is not in the module map
assert_equals(getCount(), 1e7);
}, "import() should drain the microtask queue when fetching a new module");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function ticker(max) {
let i = 0;
let stop = false;
Promise.resolve().then(function loop() {
if (stop || i >= max) return;
i++;
Promise.resolve().then(loop);
});
return () => {
stop = true;
return i;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<title>Dynamic import interaction with microtask queue</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="module">
import { ticker } from "./ticker.js";

promise_test(async t => {
const getCount = ticker(1000);

try {
await import("./../../imports-a.js", { type: "<invalid>" });
assert_unreached('import() should reject');
} catch (_) {}

assert_less_than(getCount(), 1000);
}, "import() should not drain the microtask queue if it fails while validating the 'type' assertion");
</script>

0 comments on commit 6382a5b

Please sign in to comment.