diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.any.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.any.js')
-rw-r--r-- | testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.any.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.any.js b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.any.js new file mode 100644 index 0000000000..722251b84d --- /dev/null +++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module/repeated-imports.any.js @@ -0,0 +1,65 @@ +// META: global=window,dedicatedworker,sharedworker +// META: script=/common/utils.js + +promise_test(async test => { + await promise_rejects_js(test, TypeError, + import("./module.json"), + "Dynamic import of a JSON module without a type attribute should fail"); + + // This time the import should succeed because we're using the correct + // import even though the previous attempt with the same specifier failed. + const result = await import("./module.json", { with: { type: "json" } }); + assert_true(result.default.test); +}, "Importing a specifier that previously failed due to an incorrect type attribute can succeed if the correct attribute is later given"); + +promise_test(async test => { + // Append a URL fragment to the specifier so that this is independent + // from the previous test. + const result = await import("./module.json#2", { with: { type: "json" } }); + assert_true(result.default.test); + + await promise_rejects_js(test, TypeError, + import("./module.json#2"), + "Dynamic import should fail with the type attribute missing even if the same specifier previously succeeded"); +}, "Importing a specifier that previously succeeded with the correct type attribute should fail if the incorrect attribute is later given"); + +promise_test(async test => { + const uuid_token = token(); + // serve-json-then-js.py gives us JSON the first time + const result_json = await import(`../serve-json-then-js.py?key=${uuid_token}`, { with: { type: "json" } }); + assert_equals(result_json.default.hello, "world"); + + // Import using the same specifier again; this time we get JS, which + // should succeed since we're not asserting a non-JS type this time. + const result_js = await import(`../serve-json-then-js.py?key=${uuid_token}`); + assert_equals(result_js.default, "hello"); +}, "Two modules of different type with the same specifier can load if the server changes its responses"); + +promise_test(async test => { + const uuid_token = token(); + // serve-json-then-js.py gives us JSON the first time + await promise_rejects_js(test, TypeError, + import(`../serve-json-then-js.py?key=${uuid_token}`), + "Dynamic import of JS with a JSON type attribute should fail"); + + // Import using the same specifier/module type pair again; this time we get JS, + // but the import should still fail because the module map entry for this + // specifier/module type pair already contains a failure. + await promise_rejects_js(test, TypeError, + import(`../serve-json-then-js.py?key=${uuid_token}`), + "import should always fail if the same specifier/type attribute pair failed previously"); +}, "An import should always fail if the same specifier/type attribute pair failed previously"); + +promise_test(async test => { + const uuid_token = token(); + // serve-json-then-js.py gives us JSON the first time + const result_json = await import(`../serve-json-then-js.py?key=${uuid_token}`, { with: { type: "json" } }); + assert_equals(result_json.default.hello, "world"); + + // If this were to do another fetch, the import would fail because + // serve-json-then-js.py would give us JS this time. But, the module map + // entry for this specifier/module type pair already exists, so we + // successfully reuse the entry instead of fetching again. + const result_json_2 = await import(`../serve-json-then-js.py?key=${uuid_token}`, { with: { type: "json" } }); + assert_equals(result_json_2.default.hello, "world"); +}, "If an import previously succeeded for a given specifier/type attribute pair, future uses of that pair should yield the same result"); |