diff --git a/README.md b/README.md index f32daa4..31f153e 100644 --- a/README.md +++ b/README.md @@ -239,21 +239,14 @@ grunt.initConfig({ When using AMD to load QUnit and your tests, make sure to have a path for the `qunit` module defined. #### Events and reporting -[QUnit callback](http://api.qunitjs.com/category/callbacks/) methods and arguments are also emitted through grunt's event system so that you may build custom reporting tools. Please refer to to the QUnit documentation for more information. - -The events, with arguments, are as follows: +QUnit events are forwarded to Grunt's event system, enabling you to build custom reporting tools. Please refer to the QUnit API documentation on [QUnit events](https://qunitjs.com/api/callbacks/QUnit.on/) and [QUnit callbacks](https://qunitjs.com/api/callbacks/) for when and what data is exposed from these events. * `qunit.on.testStart` `(obj)` * `qunit.on.testEnd` `(obj)` * `qunit.on.runEnd` `(obj)` * `qunit.begin` -* `qunit.moduleStart` `(name)` -* `qunit.testStart` `(name)` -* `qunit.log` `(result, actual, expected, message, source)` -* `qunit.testDone` `(name, failed, passed, total, duration)` -* `qunit.moduleDone` `(name, failed, passed, total)` -* `qunit.done` `(failed, passed, total, runtime)` +* `qunit.done` In addition to forwarding QUnit's events, the following events are also emitted by the Grunt plugin: @@ -268,6 +261,14 @@ You may listen for these events like so: grunt.event.on('qunit.spawn', function (url) { grunt.log.ok('Running test: ' + url); }); +grunt.event.on('qunit.on.testEnd', function (test) { + var name = test.fullName.join(' > '); + if (test.status === 'failed') { + grunt.log.error(name); + } else { + grunt.log.ok(name + ' # ' + test.status); + } +}); ``` diff --git a/chrome/bridge.js b/chrome/bridge.js index 101c842..bea5821 100644 --- a/chrome/bridge.js +++ b/chrome/bridge.js @@ -43,7 +43,7 @@ } // QUnit reporter events - // https://api.qunitjs.com/callbacks/QUnit.on/ + // https://qunitjs.com/api/callbacks/QUnit.on/ QUnit.on('testStart', function(obj) { sendMessage('qunit.on.testStart', obj); @@ -52,7 +52,8 @@ QUnit.on('testEnd', function(obj) { // Re-create object to strip out 'assertions' field - // expected and actual may contain circular objects, which would fail in puppeteer as it uses JSON.stringify to serialize its messages + // expected and actual may contain circular objects, + // which would fail in puppeteer as it uses JSON.stringify to serialize its messages // In that case, replace actual and expected var errors = obj.errors; if (!canBeJSONStringified(errors)) { @@ -99,55 +100,14 @@ }); }); - // QUnit plugin callbacks (for back-compat) + // QUnit plugin callbacks // https://api.qunitjs.com/callbacks/ - // - // TODO: Remove the below in a future major version of grunt-contrib-qunit, - // after updating docs for grunt.event.on() and announcing their deprecation, - // to give developers time to migrate any event consumers to their - // newer equivalents. - - QUnit.log(function(obj) { - // What is this I don’t even - if (obj.message === '[object Object], undefined:undefined') { - return; - } - - // Parse some stuff before sending it. - var actual; - var expected; - - if (!obj.result) { - // Dumping large objects can be very slow, and the dump isn't used for - // passing tests, so only dump if the test failed. - actual = QUnit.dump.parse(obj.actual); - expected = QUnit.dump.parse(obj.expected); - } - // Send it. - sendMessage('qunit.log', obj.result, actual, expected, obj.message, obj.source, obj.todo); - }); - - QUnit.testStart(function(obj) { - sendMessage('qunit.testStart', obj.name); - }); - - QUnit.testDone(function(obj) { - sendMessage('qunit.testDone', obj.name, obj.failed, obj.passed, obj.total, obj.runtime, obj.skipped, obj.todo); - }); - - QUnit.moduleStart(function(obj) { - sendMessage('qunit.moduleStart', obj.name); - }); - - QUnit.moduleDone(function(obj) { - sendMessage('qunit.moduleDone', obj.name, obj.failed, obj.passed, obj.total); - }); QUnit.begin(function() { sendMessage('qunit.begin'); }); - QUnit.done(function(obj) { - sendMessage('qunit.done', obj.failed, obj.passed, obj.total, obj.runtime); + QUnit.done(function() { + sendMessage('qunit.done'); }); })); diff --git a/docs/qunit-examples.md b/docs/qunit-examples.md index 7cab379..fd1bc6d 100644 --- a/docs/qunit-examples.md +++ b/docs/qunit-examples.md @@ -98,21 +98,14 @@ grunt.initConfig({ When using AMD to load QUnit and your tests, make sure to have a path for the `qunit` module defined. ## Events and reporting -[QUnit callback](http://api.qunitjs.com/category/callbacks/) methods and arguments are also emitted through grunt's event system so that you may build custom reporting tools. Please refer to to the QUnit documentation for more information. - -The events, with arguments, are as follows: +QUnit events are forwarded to Grunt's event system, enabling you to build custom reporting tools. Please refer to the QUnit API documentation on [QUnit events](https://qunitjs.com/api/callbacks/QUnit.on/) and [QUnit callbacks](https://qunitjs.com/api/callbacks/) for when and what data is exposed from these events. * `qunit.on.testStart` `(obj)` * `qunit.on.testEnd` `(obj)` * `qunit.on.runEnd` `(obj)` * `qunit.begin` -* `qunit.moduleStart` `(name)` -* `qunit.testStart` `(name)` -* `qunit.log` `(result, actual, expected, message, source)` -* `qunit.testDone` `(name, failed, passed, total, duration)` -* `qunit.moduleDone` `(name, failed, passed, total)` -* `qunit.done` `(failed, passed, total, runtime)` +* `qunit.done` In addition to forwarding QUnit's events, the following events are also emitted by the Grunt plugin: @@ -127,4 +120,12 @@ You may listen for these events like so: grunt.event.on('qunit.spawn', function (url) { grunt.log.ok('Running test: ' + url); }); +grunt.event.on('qunit.on.testEnd', function (test) { + var name = test.fullName.join(' > '); + if (test.status === 'failed') { + grunt.log.error(name); + } else { + grunt.log.ok(name + ' # ' + test.status); + } +}); ``` diff --git a/tasks/qunit.js b/tasks/qunit.js index ca1818c..9353d8e 100644 --- a/tasks/qunit.js +++ b/tasks/qunit.js @@ -147,8 +147,7 @@ module.exports = function(grunt) { return failure; } - - // QUnit hooks. + // QUnit events. eventBus.on('qunit.on.testStart', function(testStart) { var name = testStart.fullName.join(' > '); grunt.verbose.write(name + '...');