Skip to content

Commit e473cd0

Browse files
committed
Include output from QUnit.on('error')
The two are not likely to overlap, but this could in theory report the same error twice. In practice, given the bridge kicks in fairly late, uncaught errors will happen before our QUnit listener is active, and late errors are likely exclusive to `QUnit.on('error')`. The "No tests" message is changing in QUnit 3.0 from a "fake" test, to an error event, hence this is in preparation for that. Note that the `runEnd` event, which is use to decide on the exit code, already reflects whether there were errors, so this doesn't effect the (default) build status, hence planning to release in a minor version.
1 parent 82f4dbc commit e473cd0

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

Gruntfile.js

+16
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ module.exports = function(grunt) {
9999
>> Expected: true`)) {
100100
cb(err !== null);
101101

102+
// qunit:failNoTests
103+
} else if (/test\/qunit_fail_notests\.html/.test(stdout) &&
104+
stdout.includes(`>> global failure
105+
>> Message: No tests were run.`)) {
106+
cb(err !== null);
107+
102108
// qunit:failPageTimeout
103109
} else if (/test\/qunit_page_timeout\.html/.test(stdout) &&
104110
/Chrome timed out/.test(stdout)) {
@@ -134,6 +140,9 @@ module.exports = function(grunt) {
134140
failAssert: {
135141
command: 'grunt qunit:failAssert --with-failing'
136142
},
143+
failNoTests: {
144+
command: 'grunt qunit:failNoTests --with-failing'
145+
},
137146
failCircularObject: {
138147
command: 'grunt qunit:failCircularObject --with-failing'
139148
},
@@ -156,6 +165,13 @@ module.exports = function(grunt) {
156165
]
157166
}
158167
});
168+
grunt.config.set('qunit.failNoTests', {
169+
options: {
170+
urls: [
171+
'http://localhost:9000/test/qunit_fail_notests.html'
172+
]
173+
}
174+
});
159175
grunt.config.set('qunit.failCircularObject', {
160176
options: {
161177
urls: [

chrome/bridge.js

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
// QUnit reporter events
4141
// https://qunitjs.com/api/callbacks/QUnit.on/
4242

43+
QUnit.on('error', function(error) {
44+
sendMessage('qunit.on.error', error);
45+
});
46+
4347
QUnit.on('testStart', function(obj) {
4448
sendMessage('qunit.on.testStart', obj);
4549
});

tasks/qunit.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,30 @@ module.exports = function(grunt) {
231231
combinedRunEnd.status = 'failed';
232232
});
233233

234-
eventBus.on('error.onError', function (msg) {
234+
eventBus.on('qunit.on.error', function (err) {
235235
// It is the responsibility of QUnit to ensure a run is marked as failure
236236
// if there are (unexpected) messages received from window.onerror.
237237
//
238238
// Prior to QUnit 2.17, details of global failures were printed by
239239
// creating a fake test with "testEnd" event. Now, it is our responsiblity
240-
// to print these, via browser-level pageerror or `QUnit.on('error')`.
240+
// to print via `QUnit.on('error')`.
241+
//
242+
// NOTE: Avoid relying solely on Puppeteer's "pageerror" event, as that only
243+
// catches the subset of execution errors that make their way to window.onerror.
244+
// It misses out on unhandled rejections from the browser, the "No tests were run"
245+
// internal QUnit error, and anything else reported to QUnit.onUncaughtException
246+
// by QUnit plugins.
247+
// https://qunitjs.com/api/extension/QUnit.onUncaughtException/
248+
grunt.log.writeln();
249+
grunt.log.error(err.stack || err);
250+
grunt.event.emit('qunit.error.onError', err);
251+
});
252+
253+
eventBus.on('error.onError', function (msg) {
254+
// This is important in addition to `QUnit.on('error')` to catch uncaught
255+
// errors that happen before the bridge is in effect (which in practice
256+
// will happen at DOMContentLoaded, after qunit.js and test files have done
257+
// their initial execution, but before QUnit.begin event and any actual tests).
241258
grunt.log.writeln();
242259
grunt.log.error(msg.stack || msg);
243260
grunt.event.emit('qunit.error.onError', msg);

test/qunit_fail_notests.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Test Suite</title>
6+
<link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css" media="screen">
7+
<script src="../node_modules/qunit/qunit/qunit.js"></script>
8+
</head>
9+
<body>
10+
<div id="qunit"></div>
11+
<!-- No tests -->
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)