From 4322de61b5246b1c26c430c05636cdf3bd140d11 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Thu, 18 Feb 2016 23:31:34 +0600 Subject: [PATCH] [tests] add basic unhandled rejection tracking tests --- tests/es.js | 40 ++++++++++++++++++++++++++++++++++++ tests/library.js | 40 ++++++++++++++++++++++++++++++++++++ tests/library/es6.promise.ls | 32 +++++++++++++++++++++++++++++ tests/tests.js | 40 ++++++++++++++++++++++++++++++++++++ tests/tests/es6.promise.ls | 32 +++++++++++++++++++++++++++++ 5 files changed, 184 insertions(+) diff --git a/tests/es.js b/tests/es.js index 46ba5f369ee3..282b29e0cad5 100644 --- a/tests/es.js +++ b/tests/es.js @@ -4002,6 +4002,46 @@ }); }); } + test('Unhandled rejection tracking', function(assert){ + var done, start, $promise, onunhandledrejection, onrejectionhandled; + done = false; + start = assert.async(); + Promise.reject(43)['catch'](function(){}); + $promise = Promise.reject(42); + if (typeof process != 'undefined' && process !== null) { + assert.expect(3); + process.on('unhandledRejection', onunhandledrejection = function(reason, promise){ + assert.same(promise, $promise, 'unhandledRejection, promise'); + assert.same(reason, 42, 'unhandledRejection, reason'); + $promise['catch'](function(){}); + process.removeListener('unhandledRejection', onunhandledrejection); + }); + process.on('rejectionHandled', onrejectionhandled = function(promise){ + assert.same(promise, $promise, 'rejectionHandled, promise'); + process.removeListener('rejectionHandled', onrejectionhandled); + done || start(); + done = true; + }); + } else { + assert.expect(4); + global.onunhandledrejection = function(it){ + assert.same(it.promise, $promise, 'onunhandledrejection, promise'); + assert.same(it.reason, 42, 'onunhandledrejection, reason'); + global.onunhandledrejection = null; + $promise['catch'](function(){}); + }; + global.onrejectionhandled = function(it){ + assert.same(it.promise, $promise, 'onrejectionhandled, promise'); + assert.same(it.reason, 42, 'onrejectionhandled, reason'); + global.onrejectionhandled = null; + done || start(); + done = true; + }; + } + setTimeout(function(){ + done || start(); + }, 1e3); + }); }).call(this); // Generated by LiveScript 1.4.0 diff --git a/tests/library.js b/tests/library.js index 32442af3f7ea..d756be87844e 100644 --- a/tests/library.js +++ b/tests/library.js @@ -3821,6 +3821,46 @@ }); }); } + test('Unhandled rejection tracking', function(assert){ + var done, start, $promise, onunhandledrejection, onrejectionhandled; + done = false; + start = assert.async(); + Promise.reject(43)['catch'](function(){}); + $promise = Promise.reject(42); + if (typeof process != 'undefined' && process !== null) { + assert.expect(3); + process.on('unhandledRejection', onunhandledrejection = function(reason, promise){ + assert.same(promise, $promise, 'unhandledRejection, promise'); + assert.same(reason, 42, 'unhandledRejection, reason'); + $promise['catch'](function(){}); + process.removeListener('unhandledRejection', onunhandledrejection); + }); + process.on('rejectionHandled', onrejectionhandled = function(promise){ + assert.same(promise, $promise, 'rejectionHandled, promise'); + process.removeListener('rejectionHandled', onrejectionhandled); + done || start(); + done = true; + }); + } else { + assert.expect(4); + global.onunhandledrejection = function(it){ + assert.same(it.promise, $promise, 'onunhandledrejection, promise'); + assert.same(it.reason, 42, 'onunhandledrejection, reason'); + global.onunhandledrejection = null; + $promise['catch'](function(){}); + }; + global.onrejectionhandled = function(it){ + assert.same(it.promise, $promise, 'onrejectionhandled, promise'); + assert.same(it.reason, 42, 'onrejectionhandled, reason'); + global.onrejectionhandled = null; + done || start(); + done = true; + }; + } + setTimeout(function(){ + done || start(); + }, 1e3); + }); }).call(this); // Generated by LiveScript 1.4.0 diff --git a/tests/library/es6.promise.ls b/tests/library/es6.promise.ls index 41c38e7e2833..1fcb272786c4 100644 --- a/tests/library/es6.promise.ls +++ b/tests/library/es6.promise.ls @@ -122,3 +122,35 @@ if PROTO assert.ok p3 instanceof SubPromise # check the async values p3.then assert.async!, -> assert.ok it, no + +test 'Unhandled rejection tracking' (assert)!-> + done = no + start = assert.async! + Promise.reject(43).catch !-> + $promise = Promise.reject 42 + if process? + assert.expect 3 + process.on \unhandledRejection, onunhandledrejection = (reason, promise)!-> + assert.same promise, $promise, 'unhandledRejection, promise' + assert.same reason, 42, 'unhandledRejection, reason' + $promise.catch !-> + process.removeListener \unhandledRejection, onunhandledrejection + process.on \rejectionHandled, onrejectionhandled = (promise)!-> + assert.same promise, $promise, 'rejectionHandled, promise' + process.removeListener \rejectionHandled, onrejectionhandled + done or start! + done := on + else + assert.expect 4 + global.onunhandledrejection = !-> + assert.same it.promise, $promise, 'onunhandledrejection, promise' + assert.same it.reason, 42, 'onunhandledrejection, reason' + global.onunhandledrejection = null + $promise.catch !-> + global.onrejectionhandled = !-> + assert.same it.promise, $promise, 'onrejectionhandled, promise' + assert.same it.reason, 42, 'onrejectionhandled, reason' + global.onrejectionhandled = null + done or start! + done := on + setTimeout (!-> done or start!), 1e3 \ No newline at end of file diff --git a/tests/tests.js b/tests/tests.js index 9cf67a9c9255..c16b261aedd5 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -4813,6 +4813,46 @@ }); }); } + test('Unhandled rejection tracking', function(assert){ + var done, start, $promise, onunhandledrejection, onrejectionhandled; + done = false; + start = assert.async(); + Promise.reject(43)['catch'](function(){}); + $promise = Promise.reject(42); + if (typeof process != 'undefined' && process !== null) { + assert.expect(3); + process.on('unhandledRejection', onunhandledrejection = function(reason, promise){ + assert.same(promise, $promise, 'unhandledRejection, promise'); + assert.same(reason, 42, 'unhandledRejection, reason'); + $promise['catch'](function(){}); + process.removeListener('unhandledRejection', onunhandledrejection); + }); + process.on('rejectionHandled', onrejectionhandled = function(promise){ + assert.same(promise, $promise, 'rejectionHandled, promise'); + process.removeListener('rejectionHandled', onrejectionhandled); + done || start(); + done = true; + }); + } else { + assert.expect(4); + global.onunhandledrejection = function(it){ + assert.same(it.promise, $promise, 'onunhandledrejection, promise'); + assert.same(it.reason, 42, 'onunhandledrejection, reason'); + global.onunhandledrejection = null; + $promise['catch'](function(){}); + }; + global.onrejectionhandled = function(it){ + assert.same(it.promise, $promise, 'onrejectionhandled, promise'); + assert.same(it.reason, 42, 'onrejectionhandled, reason'); + global.onrejectionhandled = null; + done || start(); + done = true; + }; + } + setTimeout(function(){ + done || start(); + }, 1e3); + }); }).call(this); // Generated by LiveScript 1.4.0 diff --git a/tests/tests/es6.promise.ls b/tests/tests/es6.promise.ls index 59910a5b259f..45a4aad6f966 100644 --- a/tests/tests/es6.promise.ls +++ b/tests/tests/es6.promise.ls @@ -143,3 +143,35 @@ if PROTO assert.ok p3 instanceof SubPromise # check the async values p3.then assert.async!, -> assert.ok it, no + +test 'Unhandled rejection tracking' (assert)!-> + done = no + start = assert.async! + Promise.reject(43).catch !-> + $promise = Promise.reject 42 + if process? + assert.expect 3 + process.on \unhandledRejection, onunhandledrejection = (reason, promise)!-> + assert.same promise, $promise, 'unhandledRejection, promise' + assert.same reason, 42, 'unhandledRejection, reason' + $promise.catch !-> + process.removeListener \unhandledRejection, onunhandledrejection + process.on \rejectionHandled, onrejectionhandled = (promise)!-> + assert.same promise, $promise, 'rejectionHandled, promise' + process.removeListener \rejectionHandled, onrejectionhandled + done or start! + done := on + else + assert.expect 4 + global.onunhandledrejection = !-> + assert.same it.promise, $promise, 'onunhandledrejection, promise' + assert.same it.reason, 42, 'onunhandledrejection, reason' + global.onunhandledrejection = null + $promise.catch !-> + global.onrejectionhandled = !-> + assert.same it.promise, $promise, 'onrejectionhandled, promise' + assert.same it.reason, 42, 'onrejectionhandled, reason' + global.onrejectionhandled = null + done or start! + done := on + setTimeout (!-> done or start!), 1e3 \ No newline at end of file