summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_jsterm_await_dynamic_import.js
blob: fae858c8bb8601361668dca48dfaa6f04287f7df (plain)
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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Test that top-level await with dynamic import works as expected.

"use strict";

const TEST_URI =
  "http://example.com/browser/devtools/client/webconsole/test/browser/test-dynamic-import.html";

add_task(async function () {
  // Enable dynamic import
  await pushPref("javascript.options.dynamicImport", true);
  // Enable await mapping.
  await pushPref("devtools.debugger.features.map-await-expression", true);

  const hud = await openNewTabAndConsole(TEST_URI);

  info("Evaluate an expression with a dynamic import");
  let importAwaitExpression = `
    var {sum} = await import("./test-dynamic-import.mjs");
    sum(1, 2, 3);
  `;
  await executeAndWaitForResultMessage(
    hud,
    importAwaitExpression,
    `1 + 2 + 3 = 6`
  );
  ok(true, "The `sum` module was imported and used successfully");

  info("Import the same module a second time");
  // This used to make the content page crash (See Bug 1523897).
  importAwaitExpression = `
    var {sum} = await import("./test-dynamic-import.mjs");
    sum(2, 3, 4);
  `;
  await executeAndWaitForResultMessage(
    hud,
    importAwaitExpression,
    `2 + 3 + 4 = 9`
  );
  ok(true, "The `sum` module was imported and used successfully a second time");
});