Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure we fail tests when a javascript exception happens #9539

Merged
merged 1 commit into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/playground/exception.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html ng-csp>
<head>
<meta charset="utf-8">
<title>Javascript exceptions</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="../base1/patternfly.css" type="text/css" rel="stylesheet">
<script src="../base1/cockpit.js"></script>
</head>
<body hidden>
<div id="internal" class="container-fluid">
<h2>Exception</h2>

<p>Clicking this button should make a javascript exception happen.<p>

<button id="exception">Exception</button>
</div>
<script src="exception.js"></script>
</body>
</html>
13 changes: 13 additions & 0 deletions pkg/playground/exception.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* An unhandled javascript exception */
var button = document.getElementById("exception");
button.addEventListener("click", function() {
var obj = { };
window.setTimeout(function() {
obj[0].value = 1;
}, 0);
});

var cockpit = require("cockpit");
cockpit.transport.wait(function() {
document.body.removeAttribute("hidden");
});
3 changes: 3 additions & 0 deletions pkg/playground/manifest.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"translate": {
"label": "Translating"
},
"exception": {
"label": "Exceptions"
},
"pkgs": {
"label": "Packages"
}
Expand Down
3 changes: 3 additions & 0 deletions src/base1/test-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ QUnit.asyncTest("simple request", function() {
"cockpit": "122"
},
tools: {
'exception': {
'label': 'Exceptions'
},
'patterns': {
label: "Design Patterns",
path: "jquery-patterns.html"
Expand Down
3 changes: 3 additions & 0 deletions src/base1/test-stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ QUnit.asyncTest("http", function() {
cockpit: "122"
},
tools: {
'exception': {
label: 'Exceptions'
},
'patterns': {
label: "Design Patterns",
path: "jquery-patterns.html"
Expand Down
19 changes: 19 additions & 0 deletions test/verify/check-menu
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import parent
from testlib import *

import time

class TestMenu(MachineCase):
@enableAxe
def testBasic(self):
Expand Down Expand Up @@ -50,5 +52,22 @@ class TestMenu(MachineCase):
b.enter_page("/system")
b.wait_visible("#memory_status")

# Ensure that our tests pick up unhandled JS exceptions
b.switch_to_top()
b.click("a[href='/playground/exception']")
b.enter_page("/playground/exception")
b.wait_visible("button")
with self.assertRaisesRegex(RuntimeError, "TypeError:.*value.*undefined"):
b.click("button")
# Some round trips, one of which should update the deferred exception
for i in range(0, 5):
b.wait_visible("button")
time.sleep(2)

# UI should also show the crash
b.switch_to_top()
b.wait_present("#navbar-oops")
b.wait_visible("#navbar-oops")

if __name__ == '__main__':
test_main()
4 changes: 4 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ var info = {
"ovirt/ovirt.less",
],

"playground/exception": [
"playground/exception.js",
],
"playground/jquery-patterns": [
"playground/jquery-patterns.js",
],
Expand Down Expand Up @@ -223,6 +226,7 @@ var info = {

"packagekit/index.html",

"playground/exception.html",
"playground/hammer.gif",
"playground/jquery-patterns.html",
"playground/metrics.html",
Expand Down