File: repeated-imports.any.js

package info (click to toggle)
firefox-esr 128.14.0esr-1~deb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,230,204 kB
  • sloc: cpp: 7,104,278; javascript: 6,088,450; ansic: 3,654,017; python: 1,212,326; xml: 594,604; asm: 420,652; java: 182,969; sh: 71,124; makefile: 20,747; perl: 13,449; objc: 12,399; yacc: 4,583; cs: 3,846; pascal: 2,973; lex: 1,720; ruby: 1,194; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (65 lines) | stat: -rw-r--r-- 3,650 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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 assertion 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", { assert: { type: "json" } });
    assert_true(result.default.test);
}, "Importing a specifier that previously failed due to an incorrect type assertion can succeed if the correct assertion 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", { assert: { type: "json" } });
    assert_true(result.default.test);

    await promise_rejects_js(test, TypeError,
      import("./module.json#2"),
      "Dynamic import should fail with the type assertion missing even if the same specifier previously succeeded");
}, "Importing a specifier that previously succeeded with the correct type assertion should fail if the incorrect assertion 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}`, { assert: { 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 assertion 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 assertion pair failed previously");
}, "An import should always fail if the same specifier/type assertion 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}`, { assert: { 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}`, { assert: { type: "json" } });
    assert_equals(result_json_2.default.hello, "world");
}, "If an import previously succeeded for a given specifier/type assertion pair, future uses of that pair should yield the same result");