test_stack-trace-source-maps.html (2963B)
1 <!-- This Source Code Form is subject to the terms of the Mozilla Public 2 - License, v. 2.0. If a copy of the MPL was not distributed with this 3 - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> 4 <!DOCTYPE HTML> 5 <html> 6 <!-- 7 Test the rendering of a stack trace with source maps 8 --> 9 <head> 10 <meta charset="utf-8"> 11 <title>StackTrace component test</title> 12 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 13 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 14 </head> 15 <body> 16 <script src="head.js"></script> 17 <script> 18 "use strict"; 19 20 window.onload = function () { 21 const ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom"); 22 const React = browserRequire("devtools/client/shared/vendor/react"); 23 const StackTrace = React.createFactory( 24 browserRequire("devtools/client/shared/components/StackTrace") 25 ); 26 ok(StackTrace, "Got the StackTrace factory"); 27 28 add_task(async function () { 29 const stacktrace = [ 30 { 31 filename: "https://bugzilla.mozilla.org/bundle.js", 32 lineNumber: 99, 33 columnNumber: 10 34 }, 35 { 36 functionName: "loadFunc", 37 filename: "https://bugzilla.mozilla.org/bundle.js", 38 lineNumber: 108, 39 } 40 ]; 41 42 const props = { 43 stacktrace, 44 onViewSourceInDebugger: () => {}, 45 // A mock source map service. 46 sourceMapURLService: { 47 subscribeByLocation ({ line, column }, callback) { 48 const newLine = line === 99 ? 1 : 7; 49 // Resolve immediately. 50 callback({ 51 url: "https://bugzilla.mozilla.org/original.js", 52 line: newLine, 53 column, 54 }); 55 56 return () => {} 57 }, 58 }, 59 }; 60 61 const trace = ReactDOM.render(StackTrace(props), window.document.body); 62 await forceRender(trace); 63 64 const traceEl = ReactDOM.findDOMNode(trace); 65 ok(traceEl, "Rendered StackTrace has an element"); 66 67 // Get the child nodes and filter out the text-only whitespace ones 68 const frameEls = Array.from(traceEl.childNodes) 69 .filter(n => n.className && n.className.includes("frame")); 70 ok(frameEls, "Rendered StackTrace has frames"); 71 is(frameEls.length, 2, "StackTrace has 2 frames"); 72 73 checkFrameString({ 74 el: frameEls[0], 75 functionName: "<anonymous>", 76 source: "https://bugzilla.mozilla.org/original.js", 77 file: "original.js", 78 line: 1, 79 column: 10, 80 shouldLink: true, 81 tooltip: "View source in Debugger → https://bugzilla.mozilla.org/original.js:1:10", 82 }); 83 84 checkFrameString({ 85 el: frameEls[1], 86 functionName: "loadFunc", 87 source: "https://bugzilla.mozilla.org/original.js", 88 file: "original.js", 89 line: 7, 90 column: null, 91 shouldLink: true, 92 tooltip: "View source in Debugger → https://bugzilla.mozilla.org/original.js:7", 93 }); 94 }); 95 }; 96 </script> 97 </body> 98 </html>