Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
<!DOCTYPE HTML>
<html>
<!--
Test the rendering of a stack trace
-->
<head>
<meta charset="utf-8">
<title>StackTrace component test</title>
</head>
<body>
<script src="head.js"></script>
<script>
"use strict";
window.onload = function() {
const ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom");
const React = browserRequire("devtools/client/shared/vendor/react");
const StackTrace = React.createFactory(
browserRequire("devtools/client/shared/components/StackTrace")
);
ok(StackTrace, "Got the StackTrace factory");
add_task(async function() {
const stacktrace = [
{
lineNumber: 55,
columnNumber: 10,
},
{
asyncCause: "because",
functionName: "loadFunc",
lineNumber: 10,
},
];
const props = {
stacktrace,
onViewSourceInDebugger: () => {},
};
const trace = ReactDOM.render(StackTrace(props), window.document.body);
await forceRender(trace);
const traceEl = ReactDOM.findDOMNode(trace);
ok(traceEl, "Rendered StackTrace has an element");
// Get the child nodes and filter out the text-only whitespace ones
const frameEls = Array.from(traceEl.childNodes)
.filter(n => n.className && n.className.includes("frame"));
ok(frameEls, "Rendered StackTrace has frames");
is(frameEls.length, 3, "StackTrace has 3 frames");
// Check the top frame, function name should be anonymous
checkFrameString({
el: frameEls[0],
functionName: "<anonymous>",
line: 55,
column: 10,
shouldLink: true,
});
// Check the async cause node
is(frameEls[1].className, "frame-link-async-cause",
"Async cause has the right class");
is(frameEls[1].textContent, "(Async: because)", "Async cause has the right label");
// Check the third frame, the source should be parsed into a valid source URL
checkFrameString({
el: frameEls[2],
functionName: "loadFunc",
line: 10,
column: null,
shouldLink: true,
});
// Check the tabs and newlines in the stack trace textContent
const traceText = traceEl.textContent;
const traceLines = traceText.split("\n");
ok(!!traceLines.length, "There are newlines in the stack trace text");
is(traceLines.pop(), "", "There is a newline at the end of the stack trace text");
is(traceLines.length, 3, "The stack trace text has 3 lines");
ok(traceLines.every(l => l[0] == "\t"), "Every stack trace line starts with tab");
});
};
</script>
</body>
</html>