Skip to content

Commit

Permalink
Test: Convert reporter-html/unhandled-rejection.js to main/ test
Browse files Browse the repository at this point in the history
  • Loading branch information
Krinkle committed Jul 11, 2024
1 parent 97f0631 commit 51bc981
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 34 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ module.exports = function (grunt) {
'test/main/assert-step.js',
'test/main/assert-timeout.js',
'test/main/async.js',
'test/main/browser-runner.js',
'test/main/deepEqual.js',
'test/main/diff.js',
'test/main/dump.js',
Expand Down
1 change: 1 addition & 0 deletions test/index-es5.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<script src="main/assert-step.js"></script>
<script src="main/assert-timeout.js"></script>
<script src="main/async.js"></script>
<script src="main/browser-runner.js"></script>
<script src="main/deepEqual.js"></script>
<script src="main/diff.js"></script>
<script src="main/dump.js"></script>
Expand Down
3 changes: 1 addition & 2 deletions test/index-xhtml.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<script src="main/assert-step.js"></script>
<script src="main/assert-timeout.js"></script>
<script src="main/async.js"></script>
<script src="main/browser-runner.js"></script>
<script src="main/deepEqual.js"></script>
<script src="main/diff.js"></script>
<script src="main/dump.js"></script>
Expand All @@ -43,8 +44,6 @@
<script src="main/TapReporter.js"></script>
<script src="main/test.js"></script>
<script src="main/utilities.js"></script>

<script src="reporter-html/unhandled-rejection.js"></script>
</head>
<body>
<div id="qunit"></div>
Expand Down
3 changes: 1 addition & 2 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<script src="main/assert-step.js"></script>
<script src="main/assert-timeout.js"></script>
<script src="main/async.js"></script>
<script src="main/browser-runner.js"></script>
<script src="main/deepEqual.js"></script>
<script src="main/diff.js"></script>
<script src="main/dump.js"></script>
Expand All @@ -31,8 +32,6 @@
<script src="main/TapReporter.js"></script>
<script src="main/test.js"></script>
<script src="main/utilities.js"></script>

<script src="reporter-html/unhandled-rejection.js"></script>
</head>
<body>
<div id="qunit"></div>
Expand Down
38 changes: 38 additions & 0 deletions test/main/browser-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
QUnit.module('browser-runner', function () {
/* global window, Promise, setTimeout */
var HAS_UNHANDLED_REJECTION_HANDLER = (typeof window !== 'undefined' && 'onunhandledrejection' in window && typeof Promise === 'function');

// Skip in non-browser and unsupporting browsers
QUnit.module.if('onunhandledrejection', HAS_UNHANDLED_REJECTION_HANDLER, function (hooks) {
// TODO: Once we run browser tests with QTap, remove this hack
// and instead write expected failures in .tap.txt snapshots.
hooks.beforeEach(function (assert) {
var test = this;
var original = assert.pushResult;
assert.pushResult = function (resultInfo) {
if (test.expectedFailure && test.expectedFailure === resultInfo.message) {
// Restore
assert.pushResult = original;
test.expectedFailure = null;
// Inverts the result of the (one) expected failure
resultInfo.result = !resultInfo.result;
}

return original.call(assert, resultInfo);
};
});

QUnit.test('example', function (assert) {
var done = assert.async();

this.expectedFailure = 'global failure: Error: Error thrown in non-returned promise!';

// eslint-disable-next-line compat/compat -- Checked
Promise.resolve().then(function () {
// prevent test from exiting before unhandled rejection fires
setTimeout(done, 20);
throw new Error('Error thrown in non-returned promise!');
});
});
});
});
1 change: 1 addition & 0 deletions test/mozjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ loadRelativeToScript('../test/main/assert-es6.js');
loadRelativeToScript('../test/main/assert-step.js');
// loadRelativeToScript( "../test/main/assert-timeout.js" ); // Requires setTimeout
// loadRelativeToScript( "../test/main/async.js" ); // Requires setTimeout
loadRelativeToScript('../test/main/browser-runner.js');
loadRelativeToScript('../test/main/deepEqual.js');
loadRelativeToScript('../test/main/diff.js');
loadRelativeToScript('../test/main/dump.js');
Expand Down
1 change: 1 addition & 0 deletions test/mozjs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import '../test/main/assert-es6.js';
import '../test/main/assert-step.js';
// import "../test/main/assert-timeout.js"; // Requires setTimeout
// import "../test/main/async.js"; // Requires setTimeout
import '../test/main/browser-runner.js';
import '../test/main/deepEqual.js';
import '../test/main/diff.js';
import '../test/main/dump.js';
Expand Down
30 changes: 0 additions & 30 deletions test/reporter-html/unhandled-rejection.js

This file was deleted.

1 change: 1 addition & 0 deletions test/webWorker-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ importScripts(
'main/assert-step.js',
'main/assert-timeout.js',
'main/async.js',
'main/browser-runner.js',
'main/deepEqual.js',
'main/diff.js',
'main/dump.js',
Expand Down

0 comments on commit 51bc981

Please sign in to comment.