Skip to content

Commit

Permalink
Adds a test for PageError component (mozilla#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchevobbe authored and linclark committed Apr 15, 2016
1 parent 2d54eca commit c002432
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ support-files =
[test_evaluation-result.html]
[test_message-container.html]
[test_message-repeat.html]
[test_page-error.html]
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ testCommands.set("new Date()", {
commandType: "evaluationResult",
expectedText: "Date 1984-03-15T00:00:00.000Z"
});
testCommands.set("pageError", {
command: null,
commandType: "pageError",
expectedText: "ReferenceError: asdf is not defined"
});

function* getPacket(command, type = "evaluationResult") {
try {
Expand All @@ -61,6 +66,53 @@ function* getPacket(command, type = "evaluationResult") {
state.client.evaluateJS(command, resolve);
});
break;
case "pageError":
// @TODO: get packet with RDP
packet = {
"from": "server1.conn1.child1/consoleActor2",
"type": "pageError",
"pageError": {
"errorMessage": "ReferenceError: asdf is not defined",
"sourceName": "data:text/html,<script>asdf</script>",
"lineText": "",
"lineNumber": 1,
"columnNumber": 1,
"category": "content javascript",
"timeStamp": 1455735574091,
"warning": false,
"error": false,
"exception": true,
"strict": false,
"info": false,
"private": false,
"stacktrace": [{
"columnNumber": 68,
"filename": "test.html",
"functionName": "baz",
"language": 2,
"lineNumber": 1
}, {
"columnNumber": 43,
"filename": "test.html",
"functionName": "bar",
"language": 2,
"lineNumber": 2
}, {
"columnNumber": 18,
"filename": "test.html",
"functionName": "foo",
"language": 2,
"lineNumber": 3
}, {
"columnNumber": 150,
"filename": "test.html",
"functionName": "",
"language": 2,
"lineNumber": 4
}]
}
};
break;
}

closeDebugger(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
const { MessageContainer } = require("devtools/client/webconsole/new-console-output/components/message-container");
const { ConsoleApiCall } = require("devtools/client/webconsole/new-console-output/components/message-types/console-api-call");
const { EvaluationResult } = require("devtools/client/webconsole/new-console-output/components/message-types/evaluation-result");
const { PageError } = require("devtools/client/webconsole/new-console-output/components/message-types/page-error");

yield testFullRender();
yield testGetMessageComponent();
Expand Down Expand Up @@ -55,6 +56,10 @@
{
commandObj: testCommands.get("new Date()"),
expectedComponent: EvaluationResult
},
{
commandObj: testCommands.get("pageError"),
expectedComponent: PageError
}
];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf8">
<title>Test for PageError component</title>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript;version=1.8" src="head.js"></script>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
</head>
<body>
<p>Test for PageError component</p>

<script type="text/javascript;version=1.8">
window.onload = Task.async(function* () {
const { prepareMessage } = require("devtools/client/webconsole/new-console-output/utils/messages");
const { PageError } = require("devtools/client/webconsole/new-console-output/components/message-types/page-error");

const packet = yield getPacket(null, "pageError");
const message = prepareMessage(packet);
const rendered = renderComponent(PageError, {message});

const queryPath = "div.message.cm-s-mozilla span span.message-flex-body span.message-body.devtools-monospace";
const messageBody = rendered.querySelectorAll(queryPath);
is(messageBody.length, 1, "PageError outputs expected HTML structure");
is(messageBody[0].textContent, testCommands.get("pageError").expectedText, "PageError outputs expected text");

SimpleTest.finish()
});
</script>
</body>
</html>

0 comments on commit c002432

Please sign in to comment.