wpt icon indicating copy to clipboard operation
wpt copied to clipboard

Add tests for interaction between import() and microtask queue

Open nicolo-ribaudo opened this issue 3 years ago • 0 comments

The HTML algorithms for dynamic import (starting from HostImportModuleDynamically) only schedule a task a when actually fetching the corresponding files, and it never happens if the imported module (and all its dependencies) have already been loaded (when step 5 of fetch a single module script doesn't happen and step 6 returns early).

I didn't know how to test "it doesn't schedule a task", so the tests are written using a loop that schedules many microtasks and checking if all those microtasks are run or not before that the import() promise is resolved.


Browsers implement this inconsistently. This PR adds three new tests, and some of them fail:

Test Firefox & Chrome Safari
import() should not drain the microtask queue if it fails during specifier resolution :heavy_check_mark: :heavy_check_mark:
import() should not drain the microtask queue when loading an already loaded module :x: :heavy_check_mark:
import() should drain the microtask queue when fetching a new module :heavy_check_mark: :heavy_check_mark:

It's possible that the Firefox/Chrome behavior is because the HTML spec uses a rare "asynchronous completions" wording which isn't defined anywhere. However, "asynchronous completions" are used for all the test cases, so I would expect the 1st to always behave like the 2nd (since they both only involve asynchronous completions and no fetching). I also opened https://github.com/whatwg/html/pull/8264 to move away from that wording.

nicolo-ribaudo avatar Sep 19 '22 17:09 nicolo-ribaudo