fune/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/serve-json-then-js.py
Daniel Clark 74aac193b6 Bug 1692599 [wpt PR 27616] - Add tests for more interesting import assertion module map caching scenarios, a=testonly
Automatic update from web-platform-tests
Add tests for more interesting import assertion module map caching scenarios

Add tests for some scenarios where the module type being part of the
module map cache key (along with the specifier) affects the outcome.
For example, if an import of a given specifier uses the wrong module
type, a later import of the same specifier should succeed if it uses
the correct type assertion.

Add a wpt script for testing some of the stranger cases where repeated
fetches to the same specifier respond with different content types.

Also add basic tests for dynamic import() with the assertions
argument to the virtual/import-assertions suite.

Bug: 1132413
Change-Id: I3ff4cde5a402d3d8c502fdb2bac133323c028254
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2692491
Reviewed-by: Kouhei Ueno <kouhei@chromium.org>
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Dan Clark <daniec@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#857995}

--

wpt-commits: cb378b9bb94207f789d406c667d5b453aad47920
wpt-pr: 27616
2021-03-15 08:33:38 +00:00

21 lines
837 B
Python

# Respond with valid JSON to the first request with the given key,
# and with valid JavaScript to the second. Used for testing scenarios where
# the same request URL results in different responses on subsequent requests.
def main(request, response):
try:
stash_key = request.GET.first(b"key")
run_count = request.server.stash.take(stash_key)
if not run_count:
run_count = 0
if run_count == 0:
response.headers.set(b"Content-Type", b"text/json")
response.content = '{"hello": "world"}'
else:
response.headers.set(b"Content-Type", b"application/javascript")
response.content = "export default 'hello';"
request.server.stash.put(stash_key, run_count + 1)
except:
response.set_error(400, u"Not enough parameters")