browser_jsterm_await_concurrent.js (1441B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // Test that multiple concurrent top-level await expressions work as expected. 5 6 "use strict"; 7 8 const TEST_URI = 9 "data:text/html;charset=utf-8,<!DOCTYPE html>Web Console test top-level await"; 10 11 add_task(async function () { 12 // Enable await mapping. 13 await pushPref("devtools.debugger.features.map-await-expression", true); 14 const hud = await openNewTabAndConsole(TEST_URI); 15 16 await clearOutput(hud); 17 const delays = [3000, 500, 9000, 6000]; 18 const inputs = delays.map( 19 delay => `await new Promise( 20 r => setTimeout(() => r("await-concurrent-" + ${delay}), ${delay}))` 21 ); 22 23 // Let's wait for the message that sould be displayed last. 24 const onMessage = waitForMessageByType( 25 hud, 26 "await-concurrent-9000", 27 ".result" 28 ); 29 for (const input of inputs) { 30 execute(hud, input); 31 } 32 await onMessage; 33 34 const messages = hud.ui.outputNode.querySelectorAll(".message .message-body"); 35 const messagesText = Array.from(messages).map(n => n.textContent); 36 const expectedMessages = [ 37 ...inputs, 38 `"await-concurrent-500"`, 39 `"await-concurrent-3000"`, 40 `"await-concurrent-6000"`, 41 `"await-concurrent-9000"`, 42 ]; 43 is( 44 JSON.stringify(messagesText, null, 2), 45 JSON.stringify(expectedMessages, null, 2), 46 "The output contains the the expected messages, in the expected order" 47 ); 48 });