How to use onUnhandledSucceed method in wpt

Best JavaScript code snippet using wpt

unhandled_rejections.js

Source:unhandled_rejections.js Github

copy

Full Screen

...28 Promise.onPossiblyUnhandledRejection(null);29 assert.fail("Reporting handled rejection as unhandled");30 });31}32function onUnhandledSucceed( done, testAgainst ) {33 Promise.onPossiblyUnhandledRejection(function(e){34 if( testAgainst !== void 0 ) {35 try {36 if( typeof testAgainst === "function" ) {37 assert(testAgainst(e));38 }39 else {40 assert.equal(testAgainst, e );41 }42 }43 catch(e) {44 Promise.onPossiblyUnhandledRejection(null);45 if( typeof testAgainst === "function" ) {46 console.log("assertion failed: " + testAgainst);47 }48 else {49 console.log("assertion failed: " + testAgainst + "!== " + e);50 }51 return;52 }53 }54 setTimeout(function() {55 clearUnhandledHandler(done)();56 }, 50);57 });58}59function async(fn) {60 return function() {61 setTimeout(function(){fn()}, 13);62 };63}64function clearUnhandledHandler(done) {65 return function() {66 Promise.onPossiblyUnhandledRejection(null);67 done();68 };69};70function e() {71 var ret = new Error();72 ret.propagationTest = true;73 return ret;74}75function notE() {76 var rets = [{}, []];77 return rets[Math.random()*rets.length|0];78}79if( adapter.hasLongStackTraces() ) {80 describe("Will report rejections that are not handled in time", function() {81 specify("Immediately rejected not handled at all", function testFunction(done) {82 onUnhandledSucceed(done);83 var promise = pending();84 promise.reject(e());85 });86 specify("Eventually rejected not handled at all", function testFunction(done) {87 onUnhandledSucceed(done);88 var promise = pending();89 setTimeout(function(){90 promise.reject(e());91 }, 50);92 });93 specify("Immediately rejected handled too late", function testFunction(done) {94 onUnhandledSucceed(done);95 var promise = pending();96 promise.reject(e());97 setTimeout( function() {98 promise.promise.caught(function(){});99 }, 120 );100 });101 specify("Eventually rejected handled too late", function testFunction(done) {102 onUnhandledSucceed(done);103 var promise = pending();104 setTimeout(function(){105 promise.reject(e());106 }, 20);107 setTimeout( function() {108 promise.promise.caught(function(){});109 }, 160 );110 });111 });112 describe("Will report rejections that are code errors", function() {113 specify("Immediately fulfilled handled with erroneous code", function testFunction(done) {114 onUnhandledSucceed(done);115 var deferred = pending();116 var promise = deferred.promise;117 deferred.fulfill(null);118 promise.then(function(itsNull){119 itsNull.will.fail.four.sure();120 });121 });122 specify("Eventually fulfilled handled with erroneous code", function testFunction(done) {123 onUnhandledSucceed(done);124 var deferred = pending();125 var promise = deferred.promise;126 setTimeout(function(){127 deferred.fulfill(null);128 }, 40);129 promise.then(function(itsNull){130 itsNull.will.fail.four.sure();131 });132 });133 specify("Already fulfilled handled with erroneous code but then recovered and failed again", function testFunction(done) {134 var err = e();135 onUnhandledSucceed(done, err);136 var promise = fulfilled(null);137 promise.then(function(itsNull){138 itsNull.will.fail.four.sure();139 }).caught(function(e){140 assert.ok( e instanceof Promise.TypeError )141 }).then(function(){142 //then failing again143 //this error should be reported144 throw err;145 });146 });147 specify("Immediately fulfilled handled with erroneous code but then recovered and failed again", function testFunction(done) {148 var err = e();149 onUnhandledSucceed(done, err);150 var deferred = pending();151 var promise = deferred.promise;152 deferred.fulfill(null);153 promise.then(function(itsNull){154 itsNull.will.fail.four.sure();155 }).caught(function(e){156 assert.ok( e instanceof Promise.TypeError )157 //Handling the type error here158 }).then(function(){159 //then failing again160 //this error should be reported161 throw err;162 });163 });164 specify("Eventually fulfilled handled with erroneous code but then recovered and failed again", function testFunction(done) {165 var err = e();166 onUnhandledSucceed(done, err);167 var deferred = pending();168 var promise = deferred.promise;169 promise.then(function(itsNull){170 itsNull.will.fail.four.sure();171 }).caught(function(e){172 assert.ok( e instanceof Promise.TypeError )173 //Handling the type error here174 }).then(function(){175 //then failing again176 //this error should be reported177 throw err;178 });179 setTimeout(function(){180 deferred.fulfill(null);181 }, 40 );182 });183 specify("Already fulfilled handled with erroneous code but then recovered in a parallel handler and failed again", function testFunction(done) {184 var err = e();185 onUnhandledSucceed(done, err);186 var promise = fulfilled(null);187 promise.then(function(itsNull){188 itsNull.will.fail.four.sure();189 }).caught(function(e){190 assert.ok( e instanceof Promise.TypeError )191 });192 promise.caught(function(e) {193 assert.ok( e instanceof Promise.TypeError )194 //Handling the type error here195 }).then(function(){196 //then failing again197 //this error should be reported198 throw err;199 });200 });201 });202}203describe("Will report rejections that are not instanceof Error", function() {204 specify("Immediately rejected with non instanceof Error", function testFunction(done) {205 onUnhandledSucceed(done);206 var failed = pending();207 failed.reject(notE());208 });209 specify("Eventually rejected with non instanceof Error", function testFunction(done) {210 onUnhandledSucceed(done);211 var failed = pending();212 setTimeout(function(){213 failed.reject(notE());214 }, 80 );215 });216});217describe("Will handle hostile rejection reasons like frozen objects", function() {218 specify("Immediately rejected with non instanceof Error", function testFunction(done) {219 onUnhandledSucceed(done, function(e) {220 return true;221 });222 var failed = pending();223 failed.reject(Object.freeze({}));224 });225 specify("Eventually rejected with non instanceof Error", function testFunction(done) {226 onUnhandledSucceed(done, function(e) {227 return e instanceof Error;228 });229 var failed = pending();230 setTimeout(function(){231 failed.reject(Object.freeze({}));232 }, 80 );233 });234});235describe("Will not report rejections that are handled in time", function() {236 specify("Already rejected handled", function testFunction(done) {237 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);238 var failed = rejected(e()).caught(async(clearUnhandledHandler(done)));239 });240 specify("Immediately rejected handled", function testFunction(done) {241 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);242 var failed = pending();243 failed.promise.caught(async(clearUnhandledHandler(done)));244 failed.reject(e());245 });246 specify("Eventually rejected handled", function testFunction(done) {247 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);248 var failed = pending();249 async(function() {250 failed.reject(e());251 })();252 failed.promise.caught(async(clearUnhandledHandler(done)));253 });254 specify("Already rejected handled in a deep sequence", function testFunction(done) {255 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);256 var failed = rejected(e());257 failed258 .then(function(){})259 .then(function(){}, null, function(){})260 .then()261 .then(function(){})262 .caught(async(clearUnhandledHandler(done)));263 });264 specify("Immediately rejected handled in a deep sequence", function testFunction(done) {265 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);266 var failed = pending();267 failed.promise.then(function(){})268 .then(function(){}, null, function(){})269 .then()270 .then(function(){})271 .caught(async(clearUnhandledHandler(done)));272 failed.reject(e());273 });274 specify("Eventually handled in a deep sequence", function testFunction(done) {275 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);276 var failed = pending();277 async(function(){278 failed.reject(e());279 })();280 failed.promise.then(function(){})281 .then(function(){}, null, function(){})282 .then()283 .then(function(){})284 .caught(async(clearUnhandledHandler(done)));285 });286 specify("Already rejected handled in a middle parallel deep sequence", function testFunction(done) {287 var totalReported = 0;288 Promise.onPossiblyUnhandledRejection(function () {289 totalReported++;290 if (totalReported === 2) {291 setTimeout(function(){292 assert.equal(totalReported, 2);293 Promise.onPossiblyUnhandledRejection(null);294 done();295 }, 13);296 }297 });298 var failed = rejected(e());299 failed300 .then(function(){})301 .then(function(){}, null, function(){})302 .then()303 .then(function(){});304 failed305 .then(function(){})306 .then(function(){}, null, function(){})307 .caught(function(){308 });309 failed310 .then(function(){})311 .then(function(){}, null, function(){})312 .then()313 .then(function(){});314 });315 specify("Immediately rejected handled in a middle parallel deep sequence", function testFunction(done) {316 var totalReported = 0;317 Promise.onPossiblyUnhandledRejection(function () {318 totalReported++;319 if (totalReported === 2) {320 setTimeout(function(){321 assert.equal(totalReported, 2);322 Promise.onPossiblyUnhandledRejection(null);323 done();324 }, 13);325 }326 });327 var failed = pending();328 failed.promise329 .then(function(){})330 .then(function(){}, null, function(){})331 .then()332 .then(function(){});333 failed.promise334 .then(function(){})335 .then(function(){}, null, function(){})336 .caught(function(){337 });338 failed.promise339 .then(function(){})340 .then(function(){}, null, function(){})341 .then()342 .then(function(){});343 failed.reject(e());344 });345 specify("Eventually handled in a middle parallel deep sequence", function testFunction(done) {346 var totalReported = 0;347 Promise.onPossiblyUnhandledRejection(function () {348 totalReported++;349 if (totalReported === 2) {350 setTimeout(function(){351 assert.equal(totalReported, 2);352 Promise.onPossiblyUnhandledRejection(null);353 done();354 }, 13);355 }356 });357 var failed = pending();358 failed.promise359 .then(function(){})360 .then(function(){}, null, function(){})361 .then()362 .then(function(){});363 failed.promise364 .then(function(){})365 .then(function(){}, null, function(){})366 .caught(function(){367 });368 failed.promise369 .then(function(){})370 .then(function(){}, null, function(){})371 .then()372 .then(function(){});373 setTimeout(function(){374 failed.reject(e());375 }, 13 );376 });377});378describe("immediate failures without .then", function testFunction(done) {379 var err = new Error('');380 specify("Promise.reject", function testFunction(done) {381 onUnhandledSucceed(done, function(e) {382 return e === err;383 });384 Promise.reject(err);385 });386 specify("new Promise throw", function testFunction(done) {387 onUnhandledSucceed(done, function(e) {388 return e === err;389 });390 new Promise(function() {391 throw err;392 });393 });394 specify("new Promise reject", function testFunction(done) {395 onUnhandledSucceed(done, function(e) {396 return e === err;397 });398 new Promise(function(_, r) {399 r(err);400 });401 });402 specify("Promise.method", function testFunction(done) {403 onUnhandledSucceed(done, function(e) {404 return e === err;405 });406 Promise.method(function() {407 throw err;408 })();409 });410 specify("Promise.all", function testFunction(done) {411 onUnhandledSucceed(done, function(e) {412 return e === err;413 });414 Promise.all([Promise.reject(err)]);415 });416});417describe("immediate failures with .then", function testFunction(done) {418 var err = new Error('');419 specify("Promise.reject", function testFunction(done) {420 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);421 Promise.reject(err).caught(async(clearUnhandledHandler(done)));422 });423 specify("new Promise throw", function testFunction(done) {424 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);425 new Promise(function() {426 throw err;427 }).caught(async(clearUnhandledHandler(done)));428 });429 specify("new Promise reject", function testFunction(done) {430 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);431 new Promise(function(_, r) {432 r(err);433 }).caught(async(clearUnhandledHandler(done)));434 });435 specify("Promise.method", function testFunction(done) {436 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);437 Promise.method(function() {438 throw err;439 })().caught(clearUnhandledHandler(async(done)));440 });441 specify("Promise.all", function testFunction(done) {442 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);443 Promise.all([Promise.reject("err")])444 .caught(clearUnhandledHandler(async(done)));445 });446 specify("Promise.all many", function testFunction(done) {447 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);448 Promise.all([Promise.reject("err"), Promise.reject("err2")])449 .caught(clearUnhandledHandler(async(done)));450 });451 specify("Promise.all many pending", function testFunction(done) {452 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);453 var a = new Promise(function(v, w){454 setTimeout(function(){w("err");}, 4);455 });456 var b = new Promise(function(v, w){457 setTimeout(function(){w("err2");}, 4);458 });459 Promise.all([a, b])460 .caught(clearUnhandledHandler(async(done)));461 });462 specify("Already rejected promise for a collection", function testFunction(done){463 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);464 Promise.settle(Promise.reject(err))465 .caught(clearUnhandledHandler(async(done)));466 });467});468describe("gh-118", function() {469 specify("eventually rejected promise", function testFunction(done) {470 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);471 Promise.resolve().then(function() {472 return new Promise(function(_, reject) {473 setTimeout(function() {474 reject(13);475 }, 13);476 });477 }).caught(async(clearUnhandledHandler(done)));478 });479 specify("already rejected promise", function testFunction(done) {480 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);481 Promise.resolve().then(function() {482 return Promise.reject(13);483 }).caught(async(clearUnhandledHandler(done)));484 });485 specify("immediately rejected promise", function testFunction(done) {486 onUnhandledFail(isStrictModeSupported ? testFunction : arguments.callee);487 Promise.resolve().then(function() {488 return new Promise(function(_, reject) {489 reject(13);490 });491 }).caught(async(clearUnhandledHandler(done)));492 });493});494describe("Promise.onUnhandledRejectionHandled", function() {495 specify("should be called when unhandled promise is later handled", function(done) {496 var unhandledPromises = [];497 Promise.onPossiblyUnhandledRejection(function(reason, promise) {498 unhandledPromises.push({499 reason: reason,500 promise: promise501 });502 });503 Promise.onUnhandledRejectionHandled(function(promise) {504 assert.equal(unhandledPromises.length, 1);505 assert(unhandledPromises[0].promise === promise);506 assert(promise === a);507 assert(unhandledPromises[0].reason === reason);508 Promise.onUnhandledRejectionHandled(null);509 Promise.onPossiblyUnhandledRejection(null);510 done();511 });512 var reason = new Error("error");513 var a = new Promise(function(){514 throw reason;515 });516 setTimeout(function(){517 a.caught(function(){518 });519 }, 25);520 });521});522if (Promise.hasLongStackTraces()) {523 describe("Gives long stack traces for non-errors", function() {524 specify("string", function testFunction(done) {525 onUnhandledSucceed(done, function(e) {526 return (e.stack.length > 100);527 });528 new Promise(function(){529 throw "hello";530 });531 });532 specify("null", function testFunction(done) {533 onUnhandledSucceed(done, function(e) {534 return (e.stack.length > 100);535 });536 new Promise(function(resolve, reject){537 reject(null);538 });539 });540 specify("boolean", function testFunction(done) {541 onUnhandledSucceed(done, function(e) {542 return (e.stack.length > 100);543 });544 var d = Promise.defer();545 d.reject(true);546 });547 specify("undefined", function testFunction(done) {548 onUnhandledSucceed(done, function(e) {549 return (e.stack.length > 100);550 });551 Promise.cast().then(function() {552 throw void 0;553 });554 });555 specify("number", function testFunction(done) {556 onUnhandledSucceed(done, function(e) {557 return (e.stack.length > 100);558 });559 Promise.cast().then(function() {560 throw void 0;561 }).caught(function(e){return e === void 0}, function() {562 throw 3;563 });564 });565 specify("function", function testFunction(done) {566 onUnhandledSucceed(done, function(e) {567 return (e.stack.length > 100);568 });569 Promise.cast().then(function() {570 return Promise.reject(function(){});571 });572 });573 specify("pojo", function testFunction(done) {574 var OldPromise = require("./helpers/bluebird0_7_0.js");575 onUnhandledSucceed(done, function(e) {576 return (e.stack.length > 100);577 });578 Promise.cast().then(function() {579 return OldPromise.rejected({});580 });581 });582 specify("Date", function testFunction(done) {583 var OldPromise = require("./helpers/bluebird0_7_0.js");584 onUnhandledSucceed(done, function(e) {585 return (e.stack.length > 100);586 });587 Promise.cast().then(function() {588 return OldPromise.cast().then(function(){589 throw new Date();590 });591 });592 });593 specify("Q", function testFunction(done) {594 onUnhandledSucceed(done, function(e) {595 return (e.stack.length > 100);596 });597 Promise.resolve(5).then(function(val){598 return "Hello";599 }).delay(5).then(function(val){600 return require("q")().then(function(){throw "Error"});601 });602 });603 });604}605describe("clear unhandled handler", function() {606 Promise.onPossiblyUnhandledRejection(null);...

Full Screen

Full Screen

test-promises-unhandled-rejections.js

Source:test-promises-unhandled-rejections.js Github

copy

Full Screen

...71function clean() {72 process.removeAllListeners('unhandledRejection');73 process.removeAllListeners('rejectionHandled');74}75function onUnhandledSucceed(done, predicate) {76 clean();77 process.on('unhandledRejection', function(reason, promise) {78 try {79 predicate(reason, promise);80 } catch (e) {81 return done(e);82 }83 done();84 });85}86function onUnhandledFail(done) {87 clean();88 process.on('unhandledRejection', function(reason, promise) {89 done(new Error('unhandledRejection not supposed to be triggered'));90 });91 process.on('rejectionHandled', function() {92 done(new Error('rejectionHandled not supposed to be triggered'));93 });94 setTimeout(function() {95 done();96 }, 10);97}98asyncTest('synchronously rejected promise should trigger' +99 ' unhandledRejection', function(done) {100 const e = new Error();101 onUnhandledSucceed(done, function(reason, promise) {102 assert.strictEqual(reason, e);103 });104 Promise.reject(e);105});106asyncTest('synchronously rejected promise should trigger' +107 ' unhandledRejection', function(done) {108 const e = new Error();109 onUnhandledSucceed(done, function(reason, promise) {110 assert.strictEqual(reason, e);111 });112 new Promise(function(_, reject) {113 reject(e);114 });115});116asyncTest('Promise rejected after setImmediate should trigger' +117 ' unhandledRejection', function(done) {118 const e = new Error();119 onUnhandledSucceed(done, function(reason, promise) {120 assert.strictEqual(reason, e);121 });122 new Promise(function(_, reject) {123 setImmediate(function() {124 reject(e);125 });126 });127});128asyncTest('Promise rejected after setTimeout(,1) should trigger' +129 ' unhandled rejection', function(done) {130 const e = new Error();131 onUnhandledSucceed(done, function(reason, promise) {132 assert.strictEqual(reason, e);133 });134 new Promise(function(_, reject) {135 setTimeout(function() {136 reject(e);137 }, 1);138 });139});140asyncTest('Catching a promise rejection after setImmediate is not' +141 ' soon enough to stop unhandledRejection', function(done) {142 const e = new Error();143 onUnhandledSucceed(done, function(reason, promise) {144 assert.strictEqual(reason, e);145 });146 let _reject;147 const promise = new Promise(function(_, reject) {148 _reject = reject;149 });150 _reject(e);151 setImmediate(function() {152 promise.then(assert.fail, function() {});153 });154});155asyncTest('When re-throwing new errors in a promise catch, only the' +156 ' re-thrown error should hit unhandledRejection', function(done) {157 const e = new Error();158 const e2 = new Error();159 onUnhandledSucceed(done, function(reason, promise) {160 assert.strictEqual(reason, e2);161 assert.strictEqual(promise, promise2);162 });163 const promise2 = Promise.reject(e).then(assert.fail, function(reason) {164 assert.strictEqual(reason, e);165 throw e2;166 });167});168asyncTest('Test params of unhandledRejection for a synchronously-rejected ' +169 'promise', function(done) {170 const e = new Error();171 onUnhandledSucceed(done, function(reason, promise) {172 assert.strictEqual(reason, e);173 assert.strictEqual(promise, promise);174 });175 Promise.reject(e);176});177asyncTest('When re-throwing new errors in a promise catch, only the ' +178 're-thrown error should hit unhandledRejection: original promise' +179 ' rejected async with setTimeout(,1)', function(done) {180 const e = new Error();181 const e2 = new Error();182 onUnhandledSucceed(done, function(reason, promise) {183 assert.strictEqual(reason, e2);184 assert.strictEqual(promise, promise2);185 });186 const promise2 = new Promise(function(_, reject) {187 setTimeout(function() {188 reject(e);189 }, 1);190 }).then(assert.fail, function(reason) {191 assert.strictEqual(reason, e);192 throw e2;193 });194});195asyncTest('When re-throwing new errors in a promise catch, only the re-thrown' +196 ' error should hit unhandledRejection: promise catch attached a' +197 ' process.nextTick after rejection', function(done) {198 const e = new Error();199 const e2 = new Error();200 onUnhandledSucceed(done, function(reason, promise) {201 assert.strictEqual(reason, e2);202 assert.strictEqual(promise, promise2);203 });204 const promise = new Promise(function(_, reject) {205 setTimeout(function() {206 reject(e);207 process.nextTick(function() {208 promise2 = promise.then(assert.fail, function(reason) {209 assert.strictEqual(reason, e);210 throw e2;211 });212 });213 }, 1);214 });215 let promise2;216});217asyncTest(218 'unhandledRejection should not be triggered if a promise catch is' +219 ' attached synchronously upon the promise\'s creation',220 function(done) {221 const e = new Error();222 onUnhandledFail(done);223 Promise.reject(e).then(assert.fail, function() {});224 }225);226asyncTest(227 'unhandledRejection should not be triggered if a promise catch is' +228 ' attached synchronously upon the promise\'s creation',229 function(done) {230 const e = new Error();231 onUnhandledFail(done);232 new Promise(function(_, reject) {233 reject(e);234 }).then(assert.fail, function() {});235 }236);237asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' +238 ' prevent unhandledRejection', function(done) {239 const e = new Error();240 onUnhandledFail(done);241 const promise = Promise.reject(e);242 process.nextTick(function() {243 promise.then(assert.fail, function() {});244 });245});246asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' +247 ' prevent unhandledRejection', function(done) {248 const e = new Error();249 onUnhandledFail(done);250 const promise = new Promise(function(_, reject) {251 reject(e);252 });253 process.nextTick(function() {254 promise.then(assert.fail, function() {});255 });256});257asyncTest('While inside setImmediate, catching a rejected promise derived ' +258 'from returning a rejected promise in a fulfillment handler ' +259 'prevents unhandledRejection', function(done) {260 onUnhandledFail(done);261 setImmediate(function() {262 // Reproduces on first tick and inside of setImmediate263 Promise264 .resolve('resolve')265 .then(function() {266 return Promise.reject('reject');267 }).catch(function(e) {});268 });269});270// State adaptation tests271asyncTest('catching a promise which is asynchronously rejected (via ' +272 'resolution to an asynchronously-rejected promise) prevents' +273 ' unhandledRejection', function(done) {274 const e = new Error();275 onUnhandledFail(done);276 Promise.resolve().then(function() {277 return new Promise(function(_, reject) {278 setTimeout(function() {279 reject(e);280 }, 1);281 });282 }).then(assert.fail, function(reason) {283 assert.strictEqual(reason, e);284 });285});286asyncTest('Catching a rejected promise derived from throwing in a' +287 ' fulfillment handler prevents unhandledRejection', function(done) {288 const e = new Error();289 onUnhandledFail(done);290 Promise.resolve().then(function() {291 throw e;292 }).then(assert.fail, function(reason) {293 assert.strictEqual(reason, e);294 });295});296asyncTest('Catching a rejected promise derived from returning a' +297 ' synchronously-rejected promise in a fulfillment handler' +298 ' prevents unhandledRejection', function(done) {299 const e = new Error();300 onUnhandledFail(done);301 Promise.resolve().then(function() {302 return Promise.reject(e);303 }).then(assert.fail, function(reason) {304 assert.strictEqual(reason, e);305 });306});307asyncTest('A rejected promise derived from returning an' +308 ' asynchronously-rejected promise in a fulfillment handler' +309 ' does trigger unhandledRejection', function(done) {310 const e = new Error();311 onUnhandledSucceed(done, function(reason, promise) {312 assert.strictEqual(reason, e);313 assert.strictEqual(promise, _promise);314 });315 const _promise = Promise.resolve().then(function() {316 return new Promise(function(_, reject) {317 setTimeout(function() {318 reject(e);319 }, 1);320 });321 });322});323asyncTest('A rejected promise derived from throwing in a fulfillment handler' +324 ' does trigger unhandledRejection', function(done) {325 const e = new Error();326 onUnhandledSucceed(done, function(reason, promise) {327 assert.strictEqual(reason, e);328 assert.strictEqual(promise, _promise);329 });330 const _promise = Promise.resolve().then(function() {331 throw e;332 });333});334asyncTest(335 'A rejected promise derived from returning a synchronously-rejected' +336 ' promise in a fulfillment handler does trigger unhandledRejection',337 function(done) {338 const e = new Error();339 onUnhandledSucceed(done, function(reason, promise) {340 assert.strictEqual(reason, e);341 assert.strictEqual(promise, _promise);342 });343 const _promise = Promise.resolve().then(function() {344 return Promise.reject(e);345 });346 }347);348// Combinations with Promise.all349asyncTest('Catching the Promise.all() of a collection that includes a ' +350 'rejected promise prevents unhandledRejection', function(done) {351 const e = new Error();352 onUnhandledFail(done);353 Promise.all([Promise.reject(e)]).then(assert.fail, function() {});354});355asyncTest(356 'Catching the Promise.all() of a collection that includes a ' +357 'nextTick-async rejected promise prevents unhandledRejection',358 function(done) {359 const e = new Error();360 onUnhandledFail(done);361 let p = new Promise(function(_, reject) {362 process.nextTick(function() {363 reject(e);364 });365 });366 p = Promise.all([p]);367 process.nextTick(function() {368 p.then(assert.fail, function() {});369 });370 }371);372asyncTest('Failing to catch the Promise.all() of a collection that includes' +373 ' a rejected promise triggers unhandledRejection for the returned' +374 ' promise, not the passed promise', function(done) {375 const e = new Error();376 onUnhandledSucceed(done, function(reason, promise) {377 assert.strictEqual(reason, e);378 assert.strictEqual(promise, p);379 });380 const p = Promise.all([Promise.reject(e)]);381});382asyncTest('Waiting setTimeout(, 10) to catch a promise causes an' +383 ' unhandledRejection + rejectionHandled pair', function(done) {384 clean();385 const unhandledPromises = [];386 const e = new Error();387 process.on('unhandledRejection', function(reason, promise) {388 assert.strictEqual(reason, e);389 unhandledPromises.push(promise);390 });391 process.on('rejectionHandled', function(promise) {392 assert.strictEqual(unhandledPromises.length, 1);393 assert.strictEqual(unhandledPromises[0], promise);394 assert.strictEqual(promise, thePromise);395 done();396 });397 const thePromise = new Promise(function() {398 throw e;399 });400 setTimeout(function() {401 thePromise.then(assert.fail, function(reason) {402 assert.strictEqual(reason, e);403 });404 }, 10);405});406asyncTest('Waiting for some combination of process.nextTick + promise' +407 ' microtasks to attach a catch handler is still soon enough to' +408 ' prevent unhandledRejection', function(done) {409 const e = new Error();410 onUnhandledFail(done);411 const a = Promise.reject(e);412 process.nextTick(function() {413 Promise.resolve().then(function() {414 process.nextTick(function() {415 Promise.resolve().then(function() {416 a.catch(function() {});417 });418 });419 });420 });421});422asyncTest('Waiting for some combination of process.nextTick + promise' +423 ' microtasks to attach a catch handler is still soon enough to ' +424 'prevent unhandledRejection: inside setImmediate', function(done) {425 const e = new Error();426 onUnhandledFail(done);427 setImmediate(function() {428 const a = Promise.reject(e);429 process.nextTick(function() {430 Promise.resolve().then(function() {431 process.nextTick(function() {432 Promise.resolve().then(function() {433 a.catch(function() {});434 });435 });436 });437 });438 });439});440asyncTest('Waiting for some combination of process.nextTick + promise ' +441 'microtasks to attach a catch handler is still soon enough to ' +442 'prevent unhandledRejection: inside setTimeout', function(done) {443 const e = new Error();444 onUnhandledFail(done);445 setTimeout(function() {446 const a = Promise.reject(e);447 process.nextTick(function() {448 Promise.resolve().then(function() {449 process.nextTick(function() {450 Promise.resolve().then(function() {451 a.catch(function() {});452 });453 });454 });455 });456 }, 0);457});458asyncTest('Waiting for some combination of promise microtasks + ' +459 'process.nextTick to attach a catch handler is still soon enough' +460 ' to prevent unhandledRejection', function(done) {461 const e = new Error();462 onUnhandledFail(done);463 const a = Promise.reject(e);464 Promise.resolve().then(function() {465 process.nextTick(function() {466 Promise.resolve().then(function() {467 process.nextTick(function() {468 a.catch(function() {});469 });470 });471 });472 });473});474asyncTest(475 'Waiting for some combination of promise microtasks +' +476 ' process.nextTick to attach a catch handler is still soon enough' +477 ' to prevent unhandledRejection: inside setImmediate',478 function(done) {479 const e = new Error();480 onUnhandledFail(done);481 setImmediate(function() {482 const a = Promise.reject(e);483 Promise.resolve().then(function() {484 process.nextTick(function() {485 Promise.resolve().then(function() {486 process.nextTick(function() {487 a.catch(function() {});488 });489 });490 });491 });492 });493 }494);495asyncTest('Waiting for some combination of promise microtasks +' +496 ' process.nextTick to attach a catch handler is still soon enough' +497 ' to prevent unhandledRejection: inside setTimeout', function(done) {498 const e = new Error();499 onUnhandledFail(done);500 setTimeout(function() {501 const a = Promise.reject(e);502 Promise.resolve().then(function() {503 process.nextTick(function() {504 Promise.resolve().then(function() {505 process.nextTick(function() {506 a.catch(function() {});507 });508 });509 });510 });511 }, 0);512});513asyncTest('setImmediate + promise microtasks is too late to attach a catch' +514 ' handler; unhandledRejection will be triggered in that case.' +515 ' (setImmediate before promise creation/rejection)', function(done) {516 const e = new Error();517 onUnhandledSucceed(done, function(reason, promise) {518 assert.strictEqual(reason, e);519 assert.strictEqual(promise, p);520 });521 const p = Promise.reject(e);522 setImmediate(function() {523 Promise.resolve().then(function() {524 p.catch(function() {});525 });526 });527});528asyncTest('setImmediate + promise microtasks is too late to attach a catch' +529 ' handler; unhandledRejection will be triggered in that case' +530 ' (setImmediate before promise creation/rejection)', function(done) {531 onUnhandledSucceed(done, function(reason, promise) {532 assert.strictEqual(reason, undefined);533 assert.strictEqual(promise, p);534 });535 setImmediate(function() {536 Promise.resolve().then(function() {537 Promise.resolve().then(function() {538 Promise.resolve().then(function() {539 Promise.resolve().then(function() {540 p.catch(function() {});541 });542 });543 });544 });545 });546 const p = Promise.reject();547});548asyncTest('setImmediate + promise microtasks is too late to attach a catch' +549 ' handler; unhandledRejection will be triggered in that case' +550 ' (setImmediate after promise creation/rejection)', function(done) {551 onUnhandledSucceed(done, function(reason, promise) {552 assert.strictEqual(reason, undefined);553 assert.strictEqual(promise, p);554 });555 const p = Promise.reject();556 setImmediate(function() {557 Promise.resolve().then(function() {558 Promise.resolve().then(function() {559 Promise.resolve().then(function() {560 Promise.resolve().then(function() {561 p.catch(function() {});562 });563 });564 });565 });566 });567});568asyncTest(569 'Promise unhandledRejection handler does not interfere with domain' +570 ' error handlers being given exceptions thrown from nextTick.',571 function(done) {572 const d = domain.create();573 let domainReceivedError;574 d.on('error', function(e) {575 domainReceivedError = e;576 });577 d.run(function() {578 const e = new Error('error');579 const domainError = new Error('domain error');580 onUnhandledSucceed(done, function(reason, promise) {581 assert.strictEqual(reason, e);582 assert.strictEqual(domainReceivedError, domainError);583 });584 Promise.reject(e);585 process.nextTick(function() {586 throw domainError;587 });588 });589 }590);591asyncTest('nextTick is immediately scheduled when called inside an event' +592 ' handler', function(done) {593 clean();594 const e = new Error('error');595 process.on('unhandledRejection', function(reason, promise) {596 const order = [];597 process.nextTick(function() {598 order.push(1);599 });600 setTimeout(function() {601 order.push(2);602 assert.deepStrictEqual([1, 2], order);603 done();604 }, 1);605 });606 Promise.reject(e);607});608asyncTest('Throwing an error inside a rejectionHandled handler goes to' +609 ' unhandledException, and does not cause .catch() to throw an ' +610 'exception', function(done) {611 clean();612 const e = new Error();613 const e2 = new Error();614 const tearDownException = setupException(function(err) {615 assert.strictEqual(err, e2);616 tearDownException();617 done();618 });619 process.on('rejectionHandled', function() {620 throw e2;621 });622 const p = Promise.reject(e);623 setTimeout(function() {624 try {625 p.catch(function() {});626 } catch {627 done(new Error('fail'));628 }629 }, 1);630});631asyncTest('Rejected promise inside unhandledRejection allows nextTick loop' +632 ' to proceed first', function(done) {633 clean();634 Promise.reject(0);635 let didCall = false;636 process.on('unhandledRejection', () => {637 assert(!didCall);638 didCall = true;639 const promise = Promise.reject(0);640 process.nextTick(() => promise.catch(() => done()));641 });642});643asyncTest(644 'Unhandled promise rejection emits a warning immediately',645 function(done) {646 clean();647 Promise.reject(0);648 const { emitWarning } = process;649 process.emitWarning = common.mustCall((...args) => {650 if (timer) {651 clearTimeout(timer);652 timer = null;653 done();654 }655 emitWarning(...args);656 }, 2);657 let timer = setTimeout(common.mustNotCall(), 10000);658 },659);660// https://github.com/nodejs/node/issues/30953661asyncTest(662 'Catching a promise should not take effect on previous promises',663 function(done) {664 onUnhandledSucceed(done, function(reason, promise) {665 assert.strictEqual(reason, '1');666 });667 Promise.reject('1');668 Promise.reject('2').catch(function() {});669 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.runTest('www.google.com', { runs: 3, location: 'Dulles:Chrome' }, function(err, data) {4 if (err) return console.error(err);5 console.log('Test submitted to WebPagetest for %s, waiting for results', data.testUrl);6 wpt.getTestResults(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 console.log('Got results for %s', data.data.testUrl);9 wpt.getTestStatus(data.data.testId, function(err, data) {10 if (err) return console.error(err);11 console.log('Got status for %s', data.data.testUrl);12 });13 });14});15var wpt = require('webpagetest');16var wpt = new WebPageTest('www.webpagetest.org');17wpt.runTest('www.google.com', { runs: 3, location: 'Dulles:Chrome' }, function(err, data) {18 if (err) return console.error(err);19 console.log('Test submitted to WebPagetest for %s, waiting for results', data.testUrl);20 wpt.getTestResults(data.data.testId, function(err, data) {21 if (err) return console.error(err);22 console.log('Got results for %s', data.data.testUrl);23 wpt.getTestStatus(data.data.testId, function(err, data) {24 if (err) return console.error(err);25 console.log('Got status for %s', data.data.testUrl);26 });27 });28});29var wpt = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org');31wpt.runTest('www.google.com', { runs: 3, location: 'Dulles:Chrome' }, function(err, data) {32 if (err) return console.error(err);33 console.log('Test submitted to WebPagetest for %s, waiting for results', data.testUrl);34 wpt.getTestResults(data.data.testId, function(err, data) {35 if (

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.onUnhandledSucceed = function (result) {2 console.log(result);3};4wpt.onUnhandledFail = function (result) {5 console.log(result);6};7wpt.onUnhandledError = function (result) {8 console.log(result);9};10wpt.onUnhandledTimeout = function (result) {11 console.log(result);12};13wpt.onUnhandledComplete = function (result) {14 console.log(result);15};16wpt.onUnhandledData = function (result) {17 console.log(result);18};19wpt.onUnhandledEnd = function (result) {20 console.log(result);21};22wpt.onUnhandledClose = function (result) {23 console.log(result);24};25wpt.onUnhandledMessage = function (result) {26 console.log(result);27};28wpt.onUnhandledOther = function (result) {29 console.log(result);30};31wpt.onUnhandled = function (result) {32 console.log(result);33};34wpt.onUnhandledStart = function (result) {35 console.log(result);36};37wpt.onUnhandledConnect = function (result) {38 console.log(result);39};40wpt.onUnhandledRequest = function (result) {

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.onUnhandledSucceed = function() {2 console.log("Unhandled succeed");3 return true;4};5wpt.onUnhandledFail = function() {6 console.log("Unhandled fail");7 return true;8};9wpt.onUnhandledError = function() {10 console.log("Unhandled error");11 return true;12};13wpt.onSucceed = function() {14 console.log("Succeed");15 return true;16};17wpt.onFail = function() {18 console.log("Fail");19 return true;20};21wpt.onError = function() {22 console.log("Error");23 return true;24};

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptDriver = require('wptdriver');2wptDriver.onUnhandledSucceed(function(error) {3 console.log(error);4});5var wptDriver = require('wptdriver');6wptDriver.onUnhandledFailed(function(error) {7 console.log(error);8});9var wptDriver = require('wptdriver');10wptDriver.onTestSucceed(function(error) {11 console.log(error);12});13var wptDriver = require('wptdriver');14wptDriver.onTestFailed(function(error) {15 console.log(error);16});17var wptDriver = require('wptdriver');18wptDriver.onTestComplete(function(error) {19 console.log(error);20});21var wptDriver = require('wptdriver');22wptDriver.onTestStepSucceed(function(error) {23 console.log(error);24});25var wptDriver = require('wptdriver');26wptDriver.onTestStepFailed(function(error) {27 console.log(error);28});29var wptDriver = require('wptdriver');30wptDriver.onTestStepComplete(function(error) {31 console.log(error);32});33var wptDriver = require('wptdriver');34wptDriver.onTestStepStart(function(error) {35 console.log(error);36});37var wptDriver = require('wptdriver');38wptDriver.onTestStart(function(error) {39 console.log(error);40});41var wptDriver = require('wptdriver');42wptDriver.onTestEnd(function(error) {

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.onUnhandledSucceed = function() {2 console.log("Test has been completed successfully");3}4wpt.onUnhandledFailed = function() {5 console.log("Test has been completed unsuccessfully");6}7wpt.onUnhandledError = function() {8 console.log("Test has been completed with an error");9}10wpt.onUnhandledTimeout = function() {11 console.log("Test has been timed out");12}13wpt.onUnhandledAbort = function() {14 console.log("Test has been aborted");15}16wpt.onUnhandledCustom = function() {17 console.log("Test has been completed with a custom status");18}19wpt.onUnhandledUnknown = function() {20 console.log("Test has been completed with an unknown status");21}22wpt.onUnhandled = function() {23 console.log("Test has been completed with any status");24}25wpt.onUnhandled = function() {26 console.log("Test has been completed with any status");27}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful