Skip to content

Commit

Permalink
Core: Remove deprecated QUnit.onError() and `QUnit.onUnhandledRejec…
Browse files Browse the repository at this point in the history
…tion()`

Deprecated since QUnit 2.17.0. Use `QUnit.onUncaughtException()` instead.

Ref #1638.
  • Loading branch information
Krinkle committed Jun 1, 2024
1 parent 5484aae commit 01b222e
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 134 deletions.
1 change: 0 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ module.exports = function (grunt) {
'test/main/dump.js',
'test/main/each.js',
'test/main/modules.js',
'test/main/onError.js',
'test/main/onUncaughtException.js',
'test/main/promise.js',
'test/main/setTimeout.js',
Expand Down
18 changes: 14 additions & 4 deletions docs/api/extension/QUnit.onUncaughtException.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: page-api
title: QUnit.onUncaughtException()
excerpt: Handle a global error.
excerpt: Report a global error.
groups:
- extension
version_added: "2.17.0"
Expand All @@ -12,12 +12,22 @@ redirect_from:

`QUnit.onUncaughtException( error )`

Handle a global error that should result in a failed test run.
Report a global error that should result in a failed test run.

| name | description |
|------|-------------|
| `error` (any) | Usually an `Error` object, but any other thrown or rejected value may be given as well. |


This method can be safely called at any time, including between or outside tests. It is designed for use by plugins and integration layers.

In general, you should not use this method and instead throw an error. QUnit automatically finds and reports uncaught errors. The following are handled by default and should not be connected to `QUnit.onUncaughtException()` a second time:

* HTML Runner: `window.onerror`
* HTML Runner: `window.addEventListener('unhandledrejection', …)`
* QUnit CLI: `process.on('unhandledRejection', …)`
* QUnit CLI: `process.on('uncaughtException', …)`

## Examples

```js
Expand All @@ -26,11 +36,11 @@ QUnit.onUncaughtException(error);
```

```js
process.on('uncaughtException', QUnit.onUncaughtException);
process.on('unhandledExample', QUnit.onUncaughtException);
```

```js
window.addEventListener('unhandledrejection', function (event) {
window.addEventListener('unhandledexample', function (event) {
QUnit.onUncaughtException(event.reason);
});
```
9 changes: 0 additions & 9 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import equiv from './equiv';
import dump from './dump';
import { runSuite, module } from './module';
import Assert from './assert';
import Logger from './logger';
import Test, { test, pushFailure } from './test';
import exportQUnit from './export';
import reporters from './reporters';
Expand All @@ -17,7 +16,6 @@ import { sourceFromStacktrace } from './core/stacktrace';
import ProcessingQueue from './core/processing-queue';

import { on, emit } from './events';
import onWindowError from './core/onerror';
import onUncaughtException from './core/on-uncaught-exception';
import diff from './core/diff';

Expand Down Expand Up @@ -50,7 +48,6 @@ extend(QUnit, {
is,
objectType,
on,
onError: onWindowError,
onUncaughtException,
pushFailure,

Expand Down Expand Up @@ -94,12 +91,6 @@ extend(QUnit, {
}
},

onUnhandledRejection: function (reason) {
Logger.warn('QUnit.onUnhandledRejection is deprecated and will be removed in QUnit 3.0.' +
' Please use QUnit.onUncaughtException instead.');
onUncaughtException(reason);
},

stack: function (offset) {
offset = (offset || 0) + 2;
return sourceFromStacktrace(offset);
Expand Down
38 changes: 0 additions & 38 deletions src/core/onerror.js

This file was deleted.

11 changes: 5 additions & 6 deletions src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ export default function Test (settings) {
}

// Queuing a late test after the run has ended is not allowed.
// This was once supported for internal use by QUnit.onError().
// This was once supported for internal use by QUnit.onUncaughtException(),
// to render a "global error" if the uncaught error happened outside a test
// and after the runEnd event. This was unstable and could be missed by CI.
// (Meaning the CI would pass despite the late-failing test).
// Ref https://github.com/qunitjs/qunit/issues/1377
if (config.pq.finished) {
// Using this for anything other than onError(), such as testing in QUnit.done(),
// is unstable and will likely result in the added tests being ignored by CI.
// (Meaning the CI passes irregardless of the added tests).
//
// TODO: Make this an error in QUnit 3.0
// throw new Error( "Unexpected test after runEnd" );
// throw new Error( 'Unexpected test after runEnd. To report errors, consider calling QUnit.onUncaughtException() instead.' );
Logger.warn('Unexpected test after runEnd. This is unstable and will fail in QUnit 3.0.');
return;
}
Expand Down
1 change: 0 additions & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<script src="main/dump.js"></script>
<script src="main/each.js"></script>
<script src="main/modules.js"></script>
<script src="main/onError.js"></script>
<script src="main/onUncaughtException.js"></script>
<script src="main/promise.js"></script>
<script src="main/setTimeout.js"></script>
Expand Down
73 changes: 0 additions & 73 deletions test/main/onError.js

This file was deleted.

1 change: 0 additions & 1 deletion test/mozjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ loadRelativeToScript('../test/main/deepEqual.js');
loadRelativeToScript('../test/main/dump.js');
loadRelativeToScript('../test/main/each.js');
// loadRelativeToScript( "../test/main/modules.js" ); // Requires setTimeout
loadRelativeToScript('../test/main/onError.js');
loadRelativeToScript('../test/main/onUncaughtException.js');
loadRelativeToScript('../test/main/promise.js');
loadRelativeToScript('../test/main/setTimeout.js');
Expand Down
1 change: 0 additions & 1 deletion test/webWorker-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ importScripts(
'main/dump.js',
'main/each.js',
'main/modules.js',
'main/onError.js',
'main/onUncaughtException.js',
'main/promise.js',
'main/setTimeout.js',
Expand Down

0 comments on commit 01b222e

Please sign in to comment.