Skip to content

Commit a0a1cb7

Browse files
committed
Add Stop button to Subtle test harness
- Auto-run tests on load so QUnit's native UI (and module picker) render - Inject a Stop button into QUnit's toolbar next to the native module picker - Stop aborts the in-progress run by clearing QUnit's task queue, leaving the native UI in place to select and run a specific module - Stop is enabled only while a run is in progress
1 parent 9afa965 commit a0a1cb7

1 file changed

Lines changed: 69 additions & 5 deletions

File tree

test/SubtleTests.html

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@
2828
<title>Subtle Tests</title>
2929
<link rel="stylesheet" href="vendor/qunit-1.23.1.css">
3030

31+
<style>
32+
#qunit-stop-button {
33+
margin-left: 0.5em;
34+
font: bold small Arial, Helvetica, sans-serif;
35+
color: #fff;
36+
background: #c0392b;
37+
border: none;
38+
border-radius: 3px;
39+
padding: 2px 10px;
40+
cursor: pointer;
41+
vertical-align: middle;
42+
}
43+
44+
#qunit-stop-button:hover {
45+
background: #a93226;
46+
}
47+
48+
#qunit-stop-button[disabled] {
49+
background: #b9b9b9;
50+
cursor: default;
51+
}
52+
</style>
53+
3154
</head>
3255

3356
<body style="background-color: gray">
@@ -36,10 +59,6 @@
3659
<div id="qunit-fixture"></div>
3760
<script src="vendor/qunit-1.23.1.js"></script>
3861

39-
<script>
40-
QUnit.config.autostart = false;
41-
</script>
42-
4362
<!-- load msrCrypto & ie11 wrapper by default -->
4463
<script id="msrCrypto" type="text/javascript" src="../dist/msrcrypto.js"></script>
4564

@@ -83,7 +102,52 @@
83102
<script src="Test.ConcatKdf.js"></script>
84103
<script src="Test.Errors.js"></script>
85104

86-
<input type="button" onclick="QUnit.start();"></input>
105+
<!-- test runner controls: stop the in-progress run -->
106+
<script>
107+
(function () {
108+
109+
var button;
110+
111+
function stopRun() {
112+
if (QUnit.config.queue) {
113+
QUnit.config.queue.length = 0;
114+
}
115+
button.disabled = true;
116+
}
117+
118+
// QUnit only builds its toolbar (and module picker) when a run
119+
// begins, so add the Stop button to the toolbar at that point,
120+
// next to QUnit's native module picker. This begin callback runs
121+
// after QUnit's own (which builds the toolbar) because it is
122+
// registered later.
123+
QUnit.begin(function () {
124+
var container = document.getElementById("qunit-modulefilter-container") ||
125+
document.getElementById("qunit-testrunner-toolbar");
126+
if (container && !button) {
127+
button = document.createElement("button");
128+
button.id = "qunit-stop-button";
129+
button.type = "button";
130+
button.innerHTML = "Stop";
131+
// Abort the in-progress run by clearing QUnit's task queue.
132+
// QUnit's process loop halts once the queue is empty,
133+
// leaving the native UI (including its module picker) on
134+
// screen so a specific module can be selected and run next.
135+
button.onclick = stopRun;
136+
container.appendChild(button);
137+
}
138+
if (button) {
139+
button.disabled = false;
140+
}
141+
});
142+
143+
QUnit.done(function () {
144+
if (button) {
145+
button.disabled = true;
146+
}
147+
});
148+
149+
})();
150+
</script>
87151

88152
</body>
89153

0 commit comments

Comments
 (0)