Best JavaScript code snippet using cypress
Approve.js
Source:Approve.js
...22 it('emits an approval event', function () {23 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {24 bankeraTokenInstance = instance;25 contractOwner = accounts[0];26 return Promise.all([27 bankeraTokenInstance.approve(spender, amount, { from: contractOwner })28 ]).then(function(tx) {29 var logs = tx[0].logs;30 assert.equal(logs.length, 1);31 assert.equal(logs[0].event, 'Approval');32 assert.equal(logs[0].args._owner, contractOwner);33 assert.equal(logs[0].args._spender, spender);34 assert(logs[0].args._value.eq(amount));35 })36 });37 });38 describe('when there was no approved amount before', function () {39 it('approves the requested amount', function () {40 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {41 bankeraTokenInstance = instance;42 contractOwner = accounts[0];43 return Promise.all([44 bankeraTokenInstance.approve(spender, amount, { from: contractOwner })45 ]).then(function(values) {46 return Promise.all([47 bankeraTokenInstance.allowance(contractOwner, spender)48 ])49 }).then(function(allowance) {50 assert.equal(allowance, amount);51 })52 })53 });54 });55 describe('when the spender had an approved amount', function () {56 beforeEach(function () {57 return Promise.all([bankeraTokenInstance.approve(spender, 1, { from: contractOwner })]);58 });59 it('approves the requested amount and replaces the previous one', function () {60 return Promise.all([61 bankeraTokenInstance.approve(spender, amount, { from: contractOwner })62 ]).then(function(values) {63 return Promise.all([64 bankeraTokenInstance.allowance(contractOwner, spender)65 ])66 }).then(function(allowance) {67 assert.equal(allowance, amount);68 })69 });70 });71 });72 describe('when the sender does not have enough balance', function () {73 const amount = 101;74 it('emits an approval event', function () {75 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {76 bankeraTokenInstance = instance;77 contractOwner = accounts[0];78 return Promise.all([79 bankeraTokenInstance.approve(spender, amount, { from: contractOwner })80 ]).then(function(tx) {81 var logs = tx[0].logs;82 assert.equal(logs.length, 1);83 assert.equal(logs[0].event, 'Approval');84 assert.equal(logs[0].args._owner, contractOwner);85 assert.equal(logs[0].args._spender, spender);86 assert(logs[0].args._value.eq(amount));87 })88 });89 });90 describe('when there was no approved amount before', function () {91 it('approves the requested amount', function () {92 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {93 bankeraTokenInstance = instance;94 contractOwner = accounts[0];95 return Promise.all([96 bankeraTokenInstance.approve(spender, amount, { from: contractOwner })97 ]).then(function(values) {98 return Promise.all([99 bankeraTokenInstance.allowance(contractOwner, spender)100 ])101 }).then(function(allowance) {102 assert.equal(allowance, amount);103 })104 })105 });106 });107 describe('when the spender had an approved amount', function () {108 beforeEach(function () {109 return Promise.all([bankeraTokenInstance.approve(spender, 1, { from: contractOwner })]);110 });111 it('approves the requested amount and replaces the previous one', function () {112 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {113 bankeraTokenInstance = instance;114 contractOwner = accounts[0];115 return Promise.all([116 bankeraTokenInstance.approve(spender, amount, { from: contractOwner })117 ]).then(function(values) {118 return Promise.all([119 bankeraTokenInstance.allowance(contractOwner, spender)120 ])121 }).then(function(allowance) {122 assert.equal(allowance, amount);123 })124 })125 });126 });127 });128 });129 describe('when the spender is the zero address', function () {130 const amount = 100;131 const spender = ZERO_ADDRESS;132 it('approves the requested amount', function () {133 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {134 bankeraTokenInstance = instance;135 contractOwner = accounts[0];136 return Promise.all([137 bankeraTokenInstance.approve(spender, amount, { from: contractOwner })138 ]).then(function(values) {139 return Promise.all([140 bankeraTokenInstance.allowance(contractOwner, spender)141 ])142 }).then(function(allowance) {143 assert.equal(allowance, amount);144 })145 })146 });147 it('emits an approval event', function () {148 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {149 bankeraTokenInstance = instance;150 contractOwner = accounts[0];151 return Promise.all([152 bankeraTokenInstance.approve(spender, amount, { from: contractOwner })153 ]).then(function(tx) {154 var logs = tx[0].logs;155 assert.equal(logs.length, 1);156 assert.equal(logs[0].event, 'Approval');157 assert.equal(logs[0].args._owner, contractOwner);158 assert.equal(logs[0].args._spender, spender);159 assert(logs[0].args._value.eq(amount));160 })161 });162 });163 });164 });165 describe('Increase approval function', function () {166 var bankeraTokenInstance;167 var contractOwner;168 var anotherAccount = accounts[12];169 const amount = 100;170 describe('when the spender is not the zero address', function () {171 const spender = anotherAccount;172 describe('when the sender has enough balance', function () {173 it('emits an approval event', function () {174 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {175 bankeraTokenInstance = instance;176 contractOwner = accounts[0];177 return Promise.all([178 bankeraTokenInstance.increaseApproval(spender, amount, { from: contractOwner })179 ]).then(function(tx) {180 var logs = tx[0].logs;181 assert.equal(logs.length, 1);182 assert.equal(logs[0].event, 'Approval');183 assert.equal(logs[0].args._owner, contractOwner);184 assert.equal(logs[0].args._spender, spender);185 assert(logs[0].args._value.eq(amount));186 })187 });188 });189 describe('when there was no approved amount before', function () {190 it('approves the requested amount', function () {191 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {192 bankeraTokenInstance = instance;193 contractOwner = accounts[0];194 return Promise.all([195 bankeraTokenInstance.increaseApproval(spender, amount, { from: contractOwner })196 ]).then(function(values) {197 return Promise.all([198 bankeraTokenInstance.allowance(contractOwner, spender)199 ])200 }).then(function(allowance) {201 assert.equal(allowance, amount);202 })203 })204 });205 });206 describe('when the spender had an approved amount', function () {207 beforeEach(function () {208 return Promise.all([bankeraTokenInstance.approve(spender, 1, { from: contractOwner })]);209 });210 it('increases the spender allowance adding the requested amount', function () {211 return Promise.all([212 bankeraTokenInstance.increaseApproval(spender, amount, { from: contractOwner })213 ]).then(function(values) {214 return Promise.all([215 bankeraTokenInstance.allowance(contractOwner, spender)216 ])217 }).then(function(allowance) {218 assert.equal(allowance, amount + 1);219 })220 });221 });222 });223 describe('when the sender does not have enough balance', function () {224 const amount = 101;225 it('emits an approval event', function () {226 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {227 bankeraTokenInstance = instance;228 contractOwner = accounts[0];229 return Promise.all([230 bankeraTokenInstance.increaseApproval(spender, amount, { from: contractOwner })231 ]).then(function(tx) {232 var logs = tx[0].logs;233 assert.equal(logs.length, 1);234 assert.equal(logs[0].event, 'Approval');235 assert.equal(logs[0].args._owner, contractOwner);236 assert.equal(logs[0].args._spender, spender);237 assert(logs[0].args._value.eq(amount));238 })239 });240 });241 describe('when there was no approved amount before', function () {242 it('approves the requested amount', function () {243 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {244 bankeraTokenInstance = instance;245 contractOwner = accounts[0];246 return Promise.all([247 bankeraTokenInstance.increaseApproval(spender, amount, { from: contractOwner })248 ]).then(function(values) {249 return Promise.all([250 bankeraTokenInstance.allowance(contractOwner, spender)251 ])252 }).then(function(allowance) {253 assert.equal(allowance, amount);254 })255 })256 });257 });258 describe('when the spender had an approved amount', function () {259 beforeEach( function () {260 bankeraTokenInstance.approve(spender, 1, { from: contractOwner });261 });262 it('increases the spender allowance adding the requested amount', function () {263 return Promise.all([264 bankeraTokenInstance.increaseApproval(spender, amount, { from: contractOwner })265 ]).then(function(tx) {266 return Promise.all([267 bankeraTokenInstance.allowance(contractOwner, spender)268 ])269 }).then(function(allowance) {270 assert.equal(allowance, amount + 1);271 })272 });273 });274 });275 });276 describe('when the spender is the zero address', function () {277 const spender = ZERO_ADDRESS;278 it('approves the requested amount', function () {279 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {280 bankeraTokenInstance = instance;281 contractOwner = accounts[0];282 return Promise.all([283 bankeraTokenInstance.increaseApproval(spender, amount, { from: contractOwner })284 ]).then(function(values) {285 return Promise.all([286 bankeraTokenInstance.allowance(contractOwner, spender)287 ])288 }).then(function(allowance) {289 assert.equal(allowance, amount);290 })291 })292 });293 it('emits an approval event', function () {294 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {295 bankeraTokenInstance = instance;296 contractOwner = accounts[0];297 return Promise.all([298 bankeraTokenInstance.increaseApproval(spender, amount, { from: contractOwner })299 ]).then(function(tx) {300 var logs = tx[0].logs;301 assert.equal(logs.length, 1);302 assert.equal(logs[0].event, 'Approval');303 assert.equal(logs[0].args._owner, contractOwner);304 assert.equal(logs[0].args._spender, spender);305 assert(logs[0].args._value.eq(amount));306 })307 });308 });309 });310 });311 describe('Decrease approval function', function () {312 var recipient = accounts[13];313 var bankeraTokenInstance;314 var contractOwner;315 describe('when the spender is not the zero address', function () {316 const spender = recipient;317 describe('when the sender has enough balance', function () {318 const amount = 100;319 it('emits an approval event', function () {320 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {321 bankeraTokenInstance = instance;322 contractOwner = accounts[0];323 return Promise.all([324 bankeraTokenInstance.decreaseApproval(spender, amount, { from: contractOwner })325 ]).then(function(tx) {326 var logs = tx[0].logs;327 assert.equal(logs.length, 1);328 assert.equal(logs[0].event, 'Approval');329 assert.equal(logs[0].args._owner, contractOwner);330 assert.equal(logs[0].args._spender, spender);331 assert(logs[0].args._value.eq(0));332 })333 });334 });335 describe('when there was no approved amount before', function () {336 it('keeps the allowance to zero', function () {337 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {338 bankeraTokenInstance = instance;339 contractOwner = accounts[0];340 return Promise.all([341 bankeraTokenInstance.decreaseApproval(spender, amount, { from: contractOwner })342 ]).then(function(values) {343 return Promise.all([344 bankeraTokenInstance.allowance(contractOwner, spender)345 ])346 }).then(function(allowance) {347 assert.equal(allowance, 0);348 })349 })350 });351 });352 describe('when the spender had an approved amount', function () {353 beforeEach(function () {354 return Promise.all([bankeraTokenInstance.approve(spender, amount + 1, { from: contractOwner })]);355 });356 it('decreases the spender allowance subtracting the requested amount', function () {357 return Promise.all([358 bankeraTokenInstance.decreaseApproval(spender, amount, { from: contractOwner })359 ]).then(function(values) {360 return Promise.all([361 bankeraTokenInstance.allowance(contractOwner, spender)362 ])363 }).then(function(allowance) {364 assert.equal(allowance, 1);365 })366 });367 });368 });369 describe('when the sender does not have enough balance', function () {370 const amount = 101;371 it('emits an approval event', function () {372 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {373 bankeraTokenInstance = instance;374 contractOwner = accounts[0];375 return Promise.all([376 bankeraTokenInstance.decreaseApproval(spender, amount, { from: contractOwner })377 ]).then(function(tx) {378 var logs = tx[0].logs;379 assert.equal(logs.length, 1);380 assert.equal(logs[0].event, 'Approval');381 assert.equal(logs[0].args._owner, contractOwner);382 assert.equal(logs[0].args._spender, spender);383 assert(logs[0].args._value.eq(0));384 })385 });386 });387 describe('when there was no approved amount before', function () {388 it('keeps the allowance to zero', function () {389 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {390 bankeraTokenInstance = instance;391 contractOwner = accounts[0];392 return Promise.all([393 bankeraTokenInstance.decreaseApproval(spender, amount, { from: contractOwner })394 ]).then(function(values) {395 return Promise.all([396 bankeraTokenInstance.allowance(contractOwner, spender)397 ])398 }).then(function(allowance) {399 assert.equal(allowance, 0);400 })401 })402 });403 });404 describe('when the spender had an approved amount', function () {405 beforeEach(function () {406 return Promise.all([bankeraTokenInstance.approve(spender, amount + 1, { from: contractOwner })]);407 });408 it('decreases the spender allowance subtracting the requested amount', function () {409 return Promise.all([410 bankeraTokenInstance.decreaseApproval(spender, amount, { from: contractOwner })411 ]).then(function(values) {412 return Promise.all([413 bankeraTokenInstance.allowance(contractOwner, spender)414 ])415 }).then(function(allowance) {416 assert.equal(allowance, 1);417 })418 });419 });420 });421 });422 describe('when the spender is the zero address', function () {423 const amount = 100;424 const spender = ZERO_ADDRESS;425 it('decreases the requested amount', function () {426 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {427 bankeraTokenInstance = instance;428 contractOwner = accounts[0];429 return Promise.all([430 bankeraTokenInstance.decreaseApproval(spender, amount, { from: contractOwner })431 ]).then(function(values) {432 return Promise.all([433 bankeraTokenInstance.allowance(contractOwner, spender)434 ])435 }).then(function(allowance) {436 assert.equal(allowance, 0);437 })438 })439 });440 it('emits an approval event', function () {441 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {442 bankeraTokenInstance = instance;443 contractOwner = accounts[0];444 return Promise.all([445 bankeraTokenInstance.decreaseApproval(spender, amount, { from: contractOwner })446 ]).then(function(tx) {447 var logs = tx[0].logs;448 assert.equal(logs.length, 1);449 assert.equal(logs[0].event, 'Approval');450 assert.equal(logs[0].args._owner, contractOwner);451 assert.equal(logs[0].args._spender, spender);452 assert(logs[0].args._value.eq(0));453 })454 });455 });456 });457 });458 describe('transfer from function', function () {459 const spender = recipient;460 const owner = accounts[11];461 var bankeraTokenInstance;462 var contractOwner;463 beforeEach(function () {464 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {465 bankeraTokenInstance = instance;466 contractOwner = accounts[0];467 });468 });469 describe('when the recipient is not the zero address', function () {470 const to = accounts[15];471 describe('when the spender has enough approved balance', function () {472 beforeEach(function () {473 return Promise.all([474 bankeraTokenInstance.approve(spender, 100, { from: owner }),475 bankeraTokenInstance.issueTokens(owner, 100, {from: contractOwner})476 ]);477 });478 describe('when the owner has enough balance', function () {479 const amount = 100;480 it('transfers the requested amount', function () {481 return Promise.all([482 bankeraTokenInstance.transferFrom(owner, to, amount, { from: spender })483 ]).then(function(tx) {484 return Promise.all([485 bankeraTokenInstance.balanceOf(owner),486 bankeraTokenInstance.balanceOf(to)487 ])488 }).then(function(values) {489 assert.equal(values[0], 0);490 assert.equal(values[1], amount);491 });492 });493 it('decreases the spender allowance', function () {494 return Promise.all([495 bankeraTokenInstance.transferFrom(owner, to, amount, { from: spender })496 ]).then(function(values) {497 return Promise.all([498 bankeraTokenInstance.allowance(owner, spender)499 ])500 }).then(function(allowance) {501 assert.equal(allowance, 0);502 })503 });504 it('emits a transfer event', function () {505 return Promise.all([506 bankeraTokenInstance.transferFrom(owner, to, amount, { from: spender })507 ]).then(function(tx) {508 var logs = tx[0].logs;509 assert.equal(logs.length, 2);510 //ERC223 event511 assert.equal(logs[0].event, 'Transfer');512 assert.equal(logs[0].args._from, owner);513 assert.equal(logs[0].args._to, to);514 assert.equal(logs[0].args._data, '0x');515 assert(logs[0].args._value.eq(amount));516 //ERC20 event517 assert.equal(logs[1].event, 'Transfer');518 assert.equal(logs[1].args._from, owner);519 assert.equal(logs[1].args._to, to);520 assert(logs[1].args._value.eq(amount));521 })522 });523 });524 describe('when the owner does not have enough balance', function () {525 const amount = 101;526 it('reverts', function () {527 return bankeraTokenInstance.transferFrom(owner, to, amount, { from: spender })528 .then(function (tx) {529 console.log(tx);530 assert.fail("Unexpected error");531 }).catch(function(tx) {532 assertJump(tx);533 })534 });535 });536 });537 describe('when the spender does not have enough approved balance', function () {538 beforeEach(function () {539 return Promise.all([540 bankeraTokenInstance.approve(spender, 99, { from: owner }),541 bankeraTokenInstance.issueTokens(owner, 100, {from: contractOwner})542 ]);543 });544 describe('when the owner has enough balance', function () {545 const amount = 100;546 it('reverts', function () {547 return bankeraTokenInstance.transferFrom(owner, to, amount, { from: spender })548 .then(function (tx) {549 console.log(tx);550 assert.fail("Unexpected error");551 }).catch(function(tx) {552 assertJump(tx);553 })554 });555 });556 describe('when the owner does not have enough balance', function () {557 const amount = 101;558 it('reverts', function () {559 return bankeraTokenInstance.transferFrom(owner, to, amount, { from: spender })560 .then(function (tx) {561 console.log(tx);562 assert.fail("Unexpected error");563 }).catch(function(tx) {564 assertJump(tx);565 })566 });567 });568 });569 });570 describe('when the recipient is the zero address', function () {571 const amount = 100;572 const to = ZERO_ADDRESS;573 beforeEach(function () {574 bankeraTokenInstance.approve(spender, amount, { from: owner });575 });576 it('reverts', function () {577 return bankeraTokenInstance.transferFrom(owner, to, amount, { from: spender })578 .then(function (tx) {579 console.log(tx);580 assert.fail("Unexpected error");581 }).catch(function(tx) {582 assertJump(tx);583 })584 });585 });586 });587 describe('transfer function', function () {588 var bankeraTokenInstance;589 var contractOwner;590 beforeEach(function () {591 return BankeraToken.new(blocksPerRound, startingRoundNumber).then(function (instance) {592 bankeraTokenInstance = instance;593 contractOwner = accounts[0];594 });595 });596 describe('when the recipient is not the zero address', function () {597 const to = recipient;598 const owner = accounts[5];599 beforeEach(function () {600 return Promise.all([601 bankeraTokenInstance.approve(owner, 100, { from: owner }),602 bankeraTokenInstance.issueTokens(owner, 100, {from: contractOwner})603 ]);604 });605 describe('when the sender does not have enough balance', function () {606 const amount = 101;607 it('reverts', function () {608 return bankeraTokenInstance.transfer(to, amount, { from: owner })609 .then(function (tx) {610 console.log(tx);611 assert.fail("Unexpected error");612 }).catch(function(tx) {613 assertJump(tx);614 })615 });616 });617 describe('when the sender has enough balance', function () {618 const amount = 100;619 it('transfers the requested amount', function () {620 return Promise.all([621 bankeraTokenInstance.transfer(to, amount, { from: owner })622 ]).then(function(tx) {623 return Promise.all([624 bankeraTokenInstance.balanceOf(owner),625 bankeraTokenInstance.balanceOf(to)626 ])627 }).then(function(values) {628 assert.equal(values[0], 0);629 assert.equal(values[1], amount);630 });631 });632 it('emits a transfer event', function () {633 return Promise.all([634 bankeraTokenInstance.transfer(to, amount, { from: owner })635 ]).then(function(tx) {636 var logs = tx[0].logs;637 assert.equal(logs.length, 2);638 //ERC223 event639 assert.equal(logs[0].event, 'Transfer');640 assert.equal(logs[0].args._from, owner);641 assert.equal(logs[0].args._to, to);642 assert.equal(logs[0].args._data, '0x');643 assert(logs[0].args._value.eq(amount));644 //ERC20 event645 assert.equal(logs[1].event, 'Transfer');646 assert.equal(logs[1].args._from, owner);647 assert.equal(logs[1].args._to, to);...
_SyncPromise.qunit.js
Source:_SyncPromise.qunit.js
...145 oThenPromise = oFixture.thenReject146 ? Promise.reject(oResult)147 : Promise.resolve(oResult),148 oThenSyncPromise = _SyncPromise.resolve(oThenPromise);149 return Promise.all([oInitialPromise, oThenPromise])[sMethod](function () {150 // 'then' on a settled _SyncPromise is called synchronously151 var oNewSyncPromise = oFixture.initialReject152 ? oInitialSyncPromise.then(fail, callback)153 : oInitialSyncPromise.then(callback, fail);154 function callback() {155 // returning a settled _SyncPromise keeps us sync156 return oThenSyncPromise;157 }158 function fail() {159 assert.ok(false, "unexpected call");160 }161 if (oFixture.thenReject) {162 assertRejected(assert, oNewSyncPromise, oResult);163 } else {164 assertFulfilled(assert, oNewSyncPromise, oResult);165 }166 });167 });168 });169 //*********************************************************************************************170 QUnit.test("sync -> sync: throws", function (assert) {171 var oError = new Error(),172 oInitialSyncPromise = _SyncPromise.resolve(),173 // 'then' on a settled _SyncPromise is called synchronously174 oNewSyncPromise = oInitialSyncPromise.then(callback, fail);175 function callback() {176 throw oError;177 }178 function fail() {179 assert.ok(false, "unexpected call");180 }181 assertRejected(assert, oNewSyncPromise, oError);182 });183 //*********************************************************************************************184 QUnit.test("access to state and result: rejects", function (assert) {185 var oNewPromise,186 oReason = {},187 oPromise = Promise.reject(oReason),188 oSyncPromise;189 oSyncPromise = _SyncPromise.resolve(oPromise);190 assertPending(assert, oSyncPromise);191 oNewPromise = oSyncPromise.then(function () {192 assert.ok(false);193 }, function (vReason) {194 assert.strictEqual(vReason, oReason);195 });196 assertPending(assert, oNewPromise);197 return oPromise.catch(function () {198 assertRejected(assert, oSyncPromise, oReason);199 return oNewPromise;200 });201 });202 //*********************************************************************************************203 QUnit.test("'then' on a rejected _SyncPromise", function (assert) {204 var oReason = {},205 oPromise = Promise.reject(oReason),206 oSyncPromise = _SyncPromise.resolve(oPromise);207 return oPromise.catch(function () {208 var bCalled = false,209 oNewSyncPromise;210 oNewSyncPromise = oSyncPromise211 .then(/* then w/o callbacks does not change result */)212 .then(null, "If onRejected is not a function, it must be ignored")213 .then(function () {214 assert.ok(false);215 }, function (vReason) {216 assertRejected(assert, oSyncPromise, oReason);217 assert.strictEqual(vReason, oReason);218 assert.strictEqual(bCalled, false, "then called exactly once");219 bCalled = true;220 return "OK";221 });222 assertFulfilled(assert, oNewSyncPromise, "OK");223 assert.strictEqual(bCalled, true, "called synchronously");224 oNewSyncPromise.then(function (sResult) {225 assert.strictEqual(sResult, oNewSyncPromise.getResult(), "OK");226 });227 });228 });229 //*********************************************************************************************230 QUnit.test("_SyncPromise.all: simple values", function (assert) {231 assertFulfilled(assert, _SyncPromise.all([]), []);232 assertFulfilled(assert, _SyncPromise.all([42]), [42]);233 assertFulfilled(assert, _SyncPromise.all([_SyncPromise.resolve(42)]), [42]);234 return _SyncPromise.all([42]).then(function (aAnswers) {235 assert.deepEqual(aAnswers, [42]);236 });237 });238 //*********************************************************************************************239 QUnit.test("_SyncPromise.all: then", function (assert) {240 var oPromiseAll = _SyncPromise.all([Promise.resolve(42)]),241 oThenResult,242 done = assert.async();243 assertPending(assert, oPromiseAll);244 // code under test: "then" on a _SyncPromise.all()245 oThenResult = oPromiseAll.then(function (aAnswers) {246 assert.strictEqual(aAnswers[0], 42);247 assertFulfilled(assert, oPromiseAll, [42]);248 done();249 });250 assertPending(assert, oThenResult);251 });252 //*********************************************************************************************253 QUnit.test("_SyncPromise.all: catch", function (assert) {254 var oCatchResult,255 oReason = {},256 oPromiseAll = _SyncPromise.all([Promise.reject(oReason)]),257 done = assert.async();258 assertPending(assert, oPromiseAll);259 // code under test: "catch" on a _SyncPromise.all()260 oCatchResult = oPromiseAll.catch(function (oReason0) {261 assert.strictEqual(oReason0, oReason);262 assertRejected(assert, oPromiseAll, oReason);263 done();264 });265 assertPending(assert, oCatchResult);266 });267 //*********************************************************************************************268 [true, false].forEach(function (bWrap) {269 QUnit.test("_SyncPromise.all: one Promise resolves, wrap = " + bWrap, function (assert) {270 var oPromise = Promise.resolve(42),271 oPromiseAll;272 if (bWrap) {273 oPromise = _SyncPromise.resolve(oPromise);274 }275 oPromiseAll = _SyncPromise.all([oPromise]);276 assertPending(assert, oPromiseAll);277 return oPromise.then(function () {278 assertFulfilled(assert, oPromiseAll, [42]);279 });280 });281 });282 //*********************************************************************************************283 QUnit.test("_SyncPromise.all: two Promises resolve", function (assert) {284 var oPromiseAll,285 oPromise0 = Promise.resolve(42), // timeout 0286 oPromise1 = new Promise(function (resolve, reject) {287 setTimeout(function () {288 assertPending(assert, oPromiseAll); // not yet289 }, 5);290 setTimeout(function () {291 resolve("OK");292 }, 10);293 }),294 aPromises = [oPromise0, oPromise1];295 oPromiseAll = _SyncPromise.all(aPromises);296 assertPending(assert, oPromiseAll);297 return Promise.all(aPromises).then(function () {298 assertFulfilled(assert, oPromiseAll, [42, "OK"]);299 assert.deepEqual(aPromises, [oPromise0, oPromise1], "caller's array unchanged");300 });301 });302 //*********************************************************************************************303 QUnit.test("_SyncPromise.all: one Promise rejects", function (assert) {304 var oReason = {},305 oPromise = Promise.reject(oReason),306 oPromiseAll;307 oPromiseAll = _SyncPromise.all([oPromise]);308 assertPending(assert, oPromiseAll);309 return oPromise.catch(function () {310 assertRejected(assert, oPromiseAll, oReason);311 });312 });313 //*********************************************************************************************314 QUnit.test("_SyncPromise.all: two Promises reject", function (assert) {315 var oReason = {},316 oPromiseAll,317 oPromise0 = Promise.reject(oReason), // timeout 0318 oPromise1 = new Promise(function (resolve, reject) {319 setTimeout(function () {320 assertRejected(assert, oPromiseAll, oReason);321 }, 5);322 setTimeout(function () {323 reject("Unexpected");324 }, 10);325 }),326 aPromises = [oPromise0, oPromise1];327 oPromiseAll = _SyncPromise.all(aPromises);328 assertPending(assert, oPromiseAll);329 return oPromise1.catch(function () { // wait for the "slower" promise330 assertRejected(assert, oPromiseAll, oReason); // rejection reason does not change331 assert.deepEqual(aPromises, [oPromise0, oPromise1], "caller's array unchanged");332 });333 });334 //*********************************************************************************************335 QUnit.test("'catch' delegates to 'then'", function (assert) {336 var oNewPromise = {},337 fnOnRejected = function () {},338 oSyncPromise = _SyncPromise.resolve();339 this.mock(oSyncPromise).expects("then")340 .withExactArgs(undefined, fnOnRejected)341 .returns(oNewPromise);...
index.js
Source:index.js
...3const RabbitBus = require('../');4const connectionOptions = process.env.RABBITMQ_URL || 'amqp://localhost';5describe('Test the basic features of the RabbitBus', () => {6 it('Should connect, publish to a channel, and receive the message to a subscriber', (done) => {7 Promise.all([8 new RabbitBus(connectionOptions),9 new RabbitBus(connectionOptions)10 ])11 .then((connections) => {12 const message = 'Test message';13 const publisher = connections[0];14 const subscriber = connections[1];15 subscriber.subscribe('message', (payload) => {16 expect(payload.message).to.equal(message);17 Promise.all([publisher.end(), subscriber.end()])18 .then(() => done());19 })20 .then(() => {21 publisher.publish('message', { message });22 });23 })24 .catch(err => {25 console.log('err', err);26 });27 });28 it('Should connect, publish an error to a channel, and the subscriber should get the error message', (done) => {29 Promise.all([30 new RabbitBus(connectionOptions),31 new RabbitBus(connectionOptions)32 ])33 .then((connections) => {34 const message = { error: new Error('Test error message') };35 const publisher = connections[0];36 const subscriber = connections[1];37 subscriber.subscribe('message', (payload) => {38 expect(payload.message.error).to.equal(message.error.message);39 Promise.all([publisher.end(), subscriber.end()])40 .then(() => done());41 })42 .then(() => {43 publisher.publish('message', { message });44 });45 })46 .catch(err => {47 console.log('err', err);48 });49 });50 it('Should connect, publish to a channel, and only one of the subscribers should get the message', (done) => {51 Promise.all([52 new RabbitBus(connectionOptions),53 new RabbitBus(connectionOptions)54 ])55 .then((connections) => {56 const message = 'Test message';57 const publisher = connections[0];58 const subscriber = connections[1];59 subscriber.subscribe('message', (payload) => {60 expect(payload.message).to.equal(message);61 Promise.all([publisher.end(), subscriber.end()])62 .then(() => done());63 })64 .then(() => {65 return subscriber.subscribe('not-the-message', (payload) => {66 done('Should not get the published message!');67 });68 })69 .then(() => {70 publisher.publish('message', { message });71 });72 })73 .catch(done);74 });75 it('Should connect, publish to a channel, and have two subscribers get the message', (done) => {76 Promise.all([77 new RabbitBus(connectionOptions),78 new RabbitBus(connectionOptions),79 new RabbitBus(connectionOptions)80 ])81 .then((connections) => {82 const message = 'Test message';83 const publisher = connections[0];84 const subscriber1 = connections[1];85 const subscriber2 = connections[2];86 const allDone = _.after(2, ()=> {87 Promise.all([publisher.end(), subscriber1.end(), subscriber2.end()])88 .then(() => done());89 });90 Promise.all([91 subscriber1.subscribe('message', (payload) => {92 expect(payload.message).to.equal(message);93 allDone();94 }),95 subscriber2.subscribe('message', (payload) => {96 expect(payload.message).to.equal(message);97 allDone();98 })99 ])100 .then(() => {101 publisher.publish('message', { message });102 });103 })104 .catch(done);105 });106 it('Should use one publisher instance and one subscriber instance two pub/sub to two different channels', (done) => {107 Promise.all([108 new RabbitBus(connectionOptions),109 new RabbitBus(connectionOptions)110 ])111 .then((connections) => {112 const message = 'Test message';113 const publisher = connections[0];114 const subscriber = connections[1];115 const allDone = _.after(2, ()=> {116 Promise.all([publisher.end(), subscriber.end()])117 .then(() => done());118 });119 Promise.all([120 subscriber.subscribe('firstMessage', (payload) => {121 expect(payload.message).to.equal(message);122 allDone();123 }),124 subscriber.subscribe('secondMessage', (payload) => {125 expect(payload.message).to.equal(message);126 allDone();127 })128 ])129 .then(() => {130 publisher.publish('firstMessage', { message });131 publisher.publish('secondMessage', { message });132 });133 })134 .catch(done);135 });136 it('Should use one publisher instance and two subscribers listening to the same channel', (done) => {137 Promise.all([138 new RabbitBus(connectionOptions),139 new RabbitBus(connectionOptions),140 new RabbitBus(connectionOptions)141 ])142 .then((connections) => {143 const message = 'Test message';144 const publisher = connections[0];145 const subscriber1 = connections[1];146 const subscriber2 = connections[2];147 const allDone = _.after(2, ()=> {148 Promise.all([publisher.end(), subscriber1.end(), subscriber2.end()])149 .then(() => done());150 });151 Promise.all([152 subscriber1.subscribe('message', (payload) => {153 expect(payload.message).to.equal(message);154 allDone();155 }),156 subscriber2.subscribe('message', (payload) => {157 expect(payload.message).to.equal(message);158 allDone();159 })160 ])161 .then(() => {162 publisher.publish('message', { message });163 });164 })165 .catch(done);166 });167 it('Should use two publisher instances and two subscribers listening to the same channel', (done) => {168 Promise.all([169 new RabbitBus(connectionOptions),170 new RabbitBus(connectionOptions),171 new RabbitBus(connectionOptions),172 new RabbitBus(connectionOptions)173 ])174 .then((connections) => {175 const message = 'Test message';176 const publisher1 = connections[0];177 const publisher2 = connections[1];178 const subscriber1 = connections[2];179 const subscriber2 = connections[3];180 const allDone = _.after(4, ()=> {181 Promise.all([publisher1.end(), publisher2.end(), subscriber1.end(), subscriber2.end()])182 .then(() => done());183 });184 Promise.all([185 subscriber1.subscribe('message', (payload) => {186 expect(payload.message).to.equal(message);187 allDone();188 }),189 subscriber2.subscribe('message', (payload) => {190 expect(payload.message).to.equal(message);191 allDone();192 })193 ])194 .then(() => {195 publisher1.publish('message', { message });196 publisher2.publish('message', { message });197 });198 })199 .catch(done);200 });201 it('Should publish 1000 messages', (done) => {202 Promise.all([203 new RabbitBus(connectionOptions),204 new RabbitBus(connectionOptions)205 ])206 .then((connections) => {207 const message = 'Test message';208 const publisher = connections[0];209 const subscriber = connections[1];210 const messageAmount = 1000;211 const allDone = _.after(messageAmount, ()=> {212 Promise.all([publisher.end(), subscriber.end()])213 .then(() => done());214 });215 subscriber.subscribe('lotsOfMessages', (payload) => {216 expect(payload.message).to.equal(message);217 allDone();218 })219 .then(() => {220 _.times(messageAmount, () => {221 publisher.publish('lotsOfMessages', { message });222 });223 });224 })225 .catch(done);226 });...
browser_dbg_search-sources-02.js
Source:browser_dbg_search-sources-02.js
1/* Any copyright is dedicated to the Public Domain.2 http://creativecommons.org/publicdomain/zero/1.0/ */3/**4 * Tests more complex functionality of sources filtering (file search).5 */6const TAB_URL = EXAMPLE_URL + "doc_editor-mode.html";7let gTab, gPanel, gDebugger;8let gSources, gSourceUtils, gSearchView, gSearchBox;9function test() {10 // Debug test slaves are a bit slow at this test.11 requestLongerTimeout(3);12 initDebugger(TAB_URL).then(([aTab,, aPanel]) => {13 gTab = aTab;14 gPanel = aPanel;15 gDebugger = gPanel.panelWin;16 gSources = gDebugger.DebuggerView.Sources;17 gSourceUtils = gDebugger.SourceUtils;18 gSearchView = gDebugger.DebuggerView.FilteredSources;19 gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;20 waitForSourceShown(gPanel, "-01.js")21 .then(firstSearch)22 .then(secondSearch)23 .then(thirdSearch)24 .then(fourthSearch)25 .then(fifthSearch)26 .then(goDown)27 .then(goDownAndWrap)28 .then(goUpAndWrap)29 .then(goUp)30 .then(returnAndSwitch)31 .then(firstSearch)32 .then(clickAndSwitch)33 .then(() => closeDebuggerAndFinish(gPanel))34 .then(null, aError => {35 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);36 });37 });38}39function firstSearch() {40 let finished = promise.all([41 ensureSourceIs(gPanel, "-01.js"),42 ensureCaretAt(gPanel, 1),43 once(gDebugger, "popupshown"),44 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND)45 ]);46 setText(gSearchBox, ".");47 return finished.then(() => promise.all([48 ensureSourceIs(gPanel, "-01.js"),49 ensureCaretAt(gPanel, 1),50 verifyContents([51 "code_script-switching-01.js?a=b",52 "code_test-editor-mode?c=d",53 "doc_editor-mode.html"54 ])55 ]));56}57function secondSearch() {58 let finished = promise.all([59 ensureSourceIs(gPanel, "-01.js"),60 ensureCaretAt(gPanel, 1),61 once(gDebugger, "popupshown"),62 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND)63 ]);64 typeText(gSearchBox, "-0");65 return finished.then(() => promise.all([66 ensureSourceIs(gPanel, "-01.js"),67 ensureCaretAt(gPanel, 1),68 verifyContents(["code_script-switching-01.js?a=b"])69 ]));70}71function thirdSearch() {72 let finished = promise.all([73 ensureSourceIs(gPanel, "-01.js"),74 ensureCaretAt(gPanel, 1),75 once(gDebugger, "popupshown"),76 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND)77 ]);78 backspaceText(gSearchBox, 1);79 return finished.then(() => promise.all([80 ensureSourceIs(gPanel, "-01.js"),81 ensureCaretAt(gPanel, 1),82 verifyContents([83 "code_script-switching-01.js?a=b",84 "code_test-editor-mode?c=d",85 "doc_editor-mode.html"86 ])87 ]));88}89function fourthSearch() {90 let finished = promise.all([91 ensureSourceIs(gPanel, "-01.js"),92 ensureCaretAt(gPanel, 1),93 once(gDebugger, "popupshown"),94 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),95 waitForSourceShown(gPanel, "test-editor-mode")96 ]);97 setText(gSearchBox, "code_test");98 return finished.then(() => promise.all([99 ensureSourceIs(gPanel, "test-editor-mode"),100 ensureCaretAt(gPanel, 1),101 verifyContents(["code_test-editor-mode?c=d"])102 ]));103}104function fifthSearch() {105 let finished = promise.all([106 ensureSourceIs(gPanel, "test-editor-mode"),107 ensureCaretAt(gPanel, 1),108 once(gDebugger, "popupshown"),109 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),110 waitForSourceShown(gPanel, "-01.js")111 ]);112 backspaceText(gSearchBox, 4);113 return finished.then(() => promise.all([114 ensureSourceIs(gPanel, "-01.js"),115 ensureCaretAt(gPanel, 1),116 verifyContents([117 "code_script-switching-01.js?a=b",118 "code_test-editor-mode?c=d"119 ])120 ]));121}122function goDown() {123 let finished = promise.all([124 ensureSourceIs(gPanel, "-01.js"),125 ensureCaretAt(gPanel, 1),126 waitForSourceShown(gPanel, "test-editor-mode"),127 ]);128 EventUtils.sendKey("DOWN", gDebugger);129 return finished.then(() => promise.all([130 ensureSourceIs(gPanel,"test-editor-mode"),131 ensureCaretAt(gPanel, 1),132 verifyContents([133 "code_script-switching-01.js?a=b",134 "code_test-editor-mode?c=d"135 ])136 ]));137}138function goDownAndWrap() {139 let finished = promise.all([140 ensureSourceIs(gPanel, "test-editor-mode"),141 ensureCaretAt(gPanel, 1),142 waitForSourceShown(gPanel, "-01.js")143 ]);144 EventUtils.synthesizeKey("g", { metaKey: true }, gDebugger);145 return finished.then(() => promise.all([146 ensureSourceIs(gPanel,"-01.js"),147 ensureCaretAt(gPanel, 1),148 verifyContents([149 "code_script-switching-01.js?a=b",150 "code_test-editor-mode?c=d"151 ])152 ]));153}154function goUpAndWrap() {155 let finished = promise.all([156 ensureSourceIs(gPanel,"-01.js"),157 ensureCaretAt(gPanel, 1),158 waitForSourceShown(gPanel, "test-editor-mode")159 ]);160 EventUtils.synthesizeKey("G", { metaKey: true }, gDebugger);161 return finished.then(() => promise.all([162 ensureSourceIs(gPanel,"test-editor-mode"),163 ensureCaretAt(gPanel, 1),164 verifyContents([165 "code_script-switching-01.js?a=b",166 "code_test-editor-mode?c=d"167 ])168 ]));169}170function goUp() {171 let finished = promise.all([172 ensureSourceIs(gPanel,"test-editor-mode"),173 ensureCaretAt(gPanel, 1),174 waitForSourceShown(gPanel, "-01.js"),175 ]);176 EventUtils.sendKey("UP", gDebugger);177 return finished.then(() => promise.all([178 ensureSourceIs(gPanel,"-01.js"),179 ensureCaretAt(gPanel, 1),180 verifyContents([181 "code_script-switching-01.js?a=b",182 "code_test-editor-mode?c=d"183 ])184 ]));185}186function returnAndSwitch() {187 let finished = promise.all([188 ensureSourceIs(gPanel,"-01.js"),189 ensureCaretAt(gPanel, 1),190 once(gDebugger, "popuphidden")191 ]);192 EventUtils.sendKey("RETURN", gDebugger);193 return finished.then(() => promise.all([194 ensureSourceIs(gPanel,"-01.js"),195 ensureCaretAt(gPanel, 1)196 ]));197}198function clickAndSwitch() {199 let finished = promise.all([200 ensureSourceIs(gPanel,"-01.js"),201 ensureCaretAt(gPanel, 1),202 once(gDebugger, "popuphidden"),203 waitForSourceShown(gPanel, "test-editor-mode")204 ]);205 EventUtils.sendMouseEvent({ type: "click" }, gSearchView.items[1].target, gDebugger);206 return finished.then(() => promise.all([207 ensureSourceIs(gPanel,"test-editor-mode"),208 ensureCaretAt(gPanel, 1)209 ]));210}211function verifyContents(aMatches) {212 is(gSources.visibleItems.length, 3,213 "The unmatched sources in the widget should not be hidden.");214 is(gSearchView.itemCount, aMatches.length,215 "The filtered sources view should have the right items available.");216 for (let i = 0; i < gSearchView.itemCount; i++) {217 let trimmedLabel = gSourceUtils.trimUrlLength(gSourceUtils.trimUrlQuery(aMatches[i]));218 let trimmedLocation = gSourceUtils.trimUrlLength(EXAMPLE_URL + aMatches[i], 0, "start");219 ok(gSearchView.widget._parent.querySelector(".results-panel-item-label[value=\"" + trimmedLabel + "\"]"),220 "The filtered sources view should have the correct source labels.");221 ok(gSearchView.widget._parent.querySelector(".results-panel-item-label-below[value=\"" + trimmedLocation + "\"]"),222 "The filtered sources view should have the correct source locations.");223 }224}225registerCleanupFunction(function() {226 gTab = null;227 gPanel = null;228 gDebugger = null;229 gSources = null;230 gSourceUtils = null;231 gSearchView = null;232 gSearchBox = null;...
browser_dbg_search-sources-01.js
Source:browser_dbg_search-sources-01.js
1/* Any copyright is dedicated to the Public Domain.2 http://creativecommons.org/publicdomain/zero/1.0/ */3/**4 * Tests basic functionality of sources filtering (file search).5 */6const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";7let gTab, gPanel, gDebugger;8let gSources, gSearchView, gSearchBox;9function test() {10 // Debug test slaves are a bit slow at this test.11 requestLongerTimeout(3);12 initDebugger(TAB_URL).then(([aTab,, aPanel]) => {13 gTab = aTab;14 gPanel = aPanel;15 gDebugger = gPanel.panelWin;16 gSources = gDebugger.DebuggerView.Sources;17 gSearchView = gDebugger.DebuggerView.FilteredSources;18 gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;19 waitForSourceShown(gPanel, "-01.js")20 .then(bogusSearch)21 .then(firstSearch)22 .then(secondSearch)23 .then(thirdSearch)24 .then(fourthSearch)25 .then(fifthSearch)26 .then(sixthSearch)27 .then(seventhSearch)28 .then(() => closeDebuggerAndFinish(gPanel))29 .then(null, aError => {30 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);31 });32 });33}34function bogusSearch() {35 let finished = promise.all([36 ensureSourceIs(gPanel, "-01.js"),37 ensureCaretAt(gPanel, 1),38 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_NOT_FOUND)39 ]);40 setText(gSearchBox, "BOGUS");41 return finished.then(() => promise.all([42 ensureSourceIs(gPanel, "-01.js"),43 ensureCaretAt(gPanel, 1),44 verifyContents({ itemCount: 0, hidden: true })45 ]));46}47function firstSearch() {48 let finished = promise.all([49 ensureSourceIs(gPanel, "-01.js"),50 ensureCaretAt(gPanel, 1),51 once(gDebugger, "popupshown"),52 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),53 waitForSourceShown(gPanel, "-02.js")54 ]);55 setText(gSearchBox, "-02.js");56 return finished.then(() => promise.all([57 ensureSourceIs(gPanel, "-02.js"),58 ensureCaretAt(gPanel, 1),59 verifyContents({ itemCount: 1, hidden: false })60 ]));61}62function secondSearch() {63 let finished = promise.all([64 once(gDebugger, "popupshown"),65 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),66 waitForSourceShown(gPanel, "-01.js")67 ])68 .then(() => {69 let finished = promise.all([70 once(gDebugger, "popupshown"),71 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),72 waitForCaretUpdated(gPanel, 5)73 ])74 .then(() => promise.all([75 ensureSourceIs(gPanel, "-01.js"),76 ensureCaretAt(gPanel, 5),77 verifyContents({ itemCount: 1, hidden: false })78 ]));79 typeText(gSearchBox, ":5");80 return finished;81 });82 setText(gSearchBox, ".*-01\.js");83 return finished;84}85function thirdSearch() {86 let finished = promise.all([87 once(gDebugger, "popupshown"),88 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),89 waitForSourceShown(gPanel, "-02.js")90 ])91 .then(() => {92 let finished = promise.all([93 once(gDebugger, "popupshown"),94 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),95 waitForCaretUpdated(gPanel, 6, 6)96 ])97 .then(() => promise.all([98 ensureSourceIs(gPanel, "-02.js"),99 ensureCaretAt(gPanel, 6, 6),100 verifyContents({ itemCount: 1, hidden: false })101 ]));102 typeText(gSearchBox, "#deb");103 return finished;104 });105 setText(gSearchBox, ".*-02\.js");106 return finished;107}108function fourthSearch() {109 let finished = promise.all([110 once(gDebugger, "popupshown"),111 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),112 waitForSourceShown(gPanel, "-01.js")113 ])114 .then(() => {115 let finished = promise.all([116 once(gDebugger, "popupshown"),117 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),118 waitForCaretUpdated(gPanel, 2, 9),119 ])120 .then(() => promise.all([121 ensureSourceIs(gPanel, "-01.js"),122 ensureCaretAt(gPanel, 2, 9),123 verifyContents({ itemCount: 1, hidden: false })124 // ...because we simply searched for ":" in the current file.125 ]));126 typeText(gSearchBox, "#:"); // # has precedence.127 return finished;128 });129 setText(gSearchBox, ".*-01\.js");130 return finished;131}132function fifthSearch() {133 let finished = promise.all([134 once(gDebugger, "popupshown"),135 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),136 waitForSourceShown(gPanel, "-02.js")137 ])138 .then(() => {139 let finished = promise.all([140 once(gDebugger, "popuphidden"),141 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_NOT_FOUND),142 waitForCaretUpdated(gPanel, 1, 3)143 ])144 .then(() => promise.all([145 ensureSourceIs(gPanel, "-02.js"),146 ensureCaretAt(gPanel, 1, 3),147 verifyContents({ itemCount: 0, hidden: true })148 // ...because the searched label includes ":5", so nothing is found.149 ]));150 typeText(gSearchBox, ":5#*"); // # has precedence.151 return finished;152 });153 setText(gSearchBox, ".*-02\.js");154 return finished;155}156function sixthSearch() {157 let finished = promise.all([158 ensureSourceIs(gPanel, "-02.js"),159 ensureCaretAt(gPanel, 1, 3),160 once(gDebugger, "popupshown"),161 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),162 waitForCaretUpdated(gPanel, 5)163 ]);164 backspaceText(gSearchBox, 2);165 return finished.then(() => promise.all([166 ensureSourceIs(gPanel, "-02.js"),167 ensureCaretAt(gPanel, 5),168 verifyContents({ itemCount: 1, hidden: false })169 ]));170}171function seventhSearch() {172 let finished = promise.all([173 ensureSourceIs(gPanel, "-02.js"),174 ensureCaretAt(gPanel, 5),175 once(gDebugger, "popupshown"),176 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),177 waitForSourceShown(gPanel, "-01.js"),178 ]);179 backspaceText(gSearchBox, 6);180 return finished.then(() => promise.all([181 ensureSourceIs(gPanel, "-01.js"),182 ensureCaretAt(gPanel, 1),183 verifyContents({ itemCount: 2, hidden: false })184 ]));185}186function verifyContents(aArgs) {187 is(gSources.visibleItems.length, 2,188 "The unmatched sources in the widget should not be hidden.");189 is(gSearchView.itemCount, aArgs.itemCount,190 "No sources should be displayed in the sources container after a bogus search.");191 is(gSearchView.hidden, aArgs.hidden,192 "No sources should be displayed in the sources container after a bogus search.");193}194registerCleanupFunction(function() {195 gTab = null;196 gPanel = null;197 gDebugger = null;198 gSources = null;199 gSearchView = null;200 gSearchBox = null;...
Promise-static-all.js
Source:Promise-static-all.js
...32var p6 = new Promise(function(_, reject) { reject('p6'); });33var p7 = new Promise(function(_, reject) { reject('p7'); });34var p8 = new Promise(function(_, reject) { reject('p8'); });35var p9 = new Promise(function(resolve) { resolve(p2); });36Promise.all([p1, p2, p5]).then(function(result) {37 testFailed('Promise.all([p1, p2, p5]) is fulfilled.');38}, function() {39 testFailed('Promise.all([p1, p2, p5]) is rejected.');40});41Promise.all().then(function() {42 testFailed('Promise.all() is fulfilled.');43}, function() {44 testPassed('Promise.all() is rejected.');45 return Promise.all([]).then(function(localResult) {46 testPassed('Promise.all([]) is fulfilled.');47 result = localResult;48 shouldBe('result.length', '0');49 }, function() {50 testFailed('Promise.all([]) is rejected.');51 });52}).then(function() {53 return Promise.all([p1, p2, p3]).then(function(localResult) {54 testPassed('Promise.all([p1, p2, p3]) is fulfilled.');55 result = localResult;56 shouldBe('result.length', '3');57 shouldBeEqualToString('result[0]', 'p1');58 shouldBeEqualToString('result[1]', 'p2');59 shouldBeEqualToString('result[2]', 'p3');60 }, function() {61 testFailed('Promise.all([p1, p2, p3]) is rejected.');62 });63}).then(function() {64 return Promise.all([p1, p6, p5]).then(function(localResult) {65 testFailed('Promise.all([p1, p6, p5]) is fulfilled.');66 }, function(localResult) {67 testPassed('Promise.all([p1, p6, p5]) is rejected.');68 result = localResult;69 shouldBeEqualToString('result', 'p6');70 });71}).then(function() {72 return Promise.all([p9]).then(function(localResult) {73 testPassed('Promise.all([p9]) is fulfilled.');74 result = localResult;75 shouldBe('result.length', '1');76 shouldBeEqualToString('result[0]', 'p2');77 }, function(result) {78 testFailed('Promise.all([p9]) is rejected.');79 });80}).then(function() {81 // Array hole should not be skipped.82 return Promise.all([p9,,,]).then(function(localResult) {83 testPassed('Promise.all([p9,,,]) is fulfilled.');84 result = localResult;85 shouldBe('result.length', '3');86 shouldBeEqualToString('result[0]', 'p2');87 shouldBe('result[1]', 'undefined');88 shouldBe('result[2]', 'undefined');89 }, function(localResult) {90 testFailed('Promise.all([p9,,,]) is rejected.');91 });92}).then(function() {93 // Immediate value should be converted to a promise object by the94 // ToPromise operation.95 return Promise.all([p9,42]).then(function(localResult) {96 testPassed('Promise.all([p9,42]) is fulfilled.');97 result = localResult;98 shouldBe('result.length', '2');99 shouldBeEqualToString('result[0]', 'p2');100 shouldBe('result[1]', '42');101 }, function(localResult) {102 testFailed('Promise.all([p9,42]) is rejected.');103 });104}).then(function() {105 return Promise.all({}).then(function(localResult) {106 testFailed('Promise.all({}) is fulfilled.');107 }, function(localResult) {108 testPassed('Promise.all({}) is rejected.');109 });110}).then(finishJSTest, finishJSTest);...
each.js
Source:each.js
1"use strict";2module.exports = function(Promise, INTERNAL) {3var PromiseReduce = Promise.reduce;4var PromiseAll = Promise.all;5function promiseAllThis() {6 return PromiseAll(this);7}8function PromiseMapSeries(promises, fn) {9 return PromiseReduce(promises, fn, INTERNAL, INTERNAL);10}11Promise.prototype.each = function (fn) {12 return PromiseReduce(this, fn, INTERNAL, 0)13 ._then(promiseAllThis, undefined, undefined, this, undefined);14};15Promise.prototype.mapSeries = function (fn) {16 return PromiseReduce(this, fn, INTERNAL, INTERNAL);17};18Promise.each = function (promises, fn) {19 return PromiseReduce(promises, fn, INTERNAL, 0)20 ._then(promiseAllThis, undefined, undefined, promises, undefined);21};22Promise.mapSeries = PromiseMapSeries;...
Using AI Code Generation
1Cypress.Commands.add('uploadFile', (fileName, fileType = ' ', selector) => {2 cy.fixture(fileName, 'base64').then(fileContent => {3 cy.get(selector).upload(4 { fileContent, fileName, mimeType: fileType },5 { subjectType: 'drag-n-drop' }6 );7 });8});9Cypress.Commands.add('uploadFile', (fileName, fileType = ' ', selector) => {10 cy.fixture(fileName, 'base64').then(fileContent => {11 cy.get(selector).upload(12 { fileContent, fileName, mimeType: fileType },13 { subjectType: 'drag-n-drop' }14 );15 });16});17Cypress.Commands.add('uploadFile', (fileName, fileType = ' ', selector) => {18 cy.fixture(fileName, 'base64').then(fileContent => {19 cy.get(selector).upload(20 { fileContent, fileName, mimeType: fileType },21 { subjectType: 'drag-n-drop' }22 );23 });24});25Cypress.Commands.add('uploadFile', (fileName, fileType = ' ', selector) => {26 cy.fixture(fileName, 'base64').then(fileContent => {27 cy.get(selector).upload(28 { fileContent, fileName, mimeType: fileType },29 { subjectType: 'drag-n-drop' }30 );31 });32});33Cypress.Commands.add('uploadFile', (fileName, fileType = ' ', selector) => {34 cy.fixture(fileName, 'base64').then(fileContent => {35 cy.get(selector).upload(36 { fileContent, fileName, mimeType: fileType },37 { subjectType: 'drag-n-drop' }38 );39 });40});41Cypress.Commands.add('uploadFile', (fileName, fileType = ' ', selector) => {42 cy.fixture(fileName, 'base64').then(fileContent => {43 cy.get(selector).upload(44 { fileContent, fileName, mimeType: fileType },45 { subjectType: 'drag-n-drop' }46 );47 });48});49Cypress.Commands.add('uploadFile', (fileName, fileType = ' ', selector) => {50 cy.fixture(fileName, 'base64').then(fileContent => {51 cy.get(selector).upload(52 { fileContent, fileName, mimeType: fileType },53 { subjectType: 'drag-n-drop' }54 );55 });56});57Cypress.Commands.add('uploadFile', (fileName, fileType = ' ', selector) => {58 cy.fixture(fileName, 'base64').then(file
Using AI Code Generation
1describe('My First Test Suite', function() 2{3 it('My FirstTest case',function() 4 {5 cy.get('.search-keyword').type('ca')6 cy.wait(2000)7 cy.get('.products').as('productLocator')8 cy.get('@productLocator').find('.product').should('have.length',4)9 cy.get(':nth-child(3) > .product-action > button').click()10 cy.get('@productLocator').find('.product').should('have.length',3)11 cy.get(':nth-child(2) > .product-action > button').click()12 cy.get('@productLocator').find('.product').should('have.length',2)
Using AI Code Generation
1describe('Promise.all', () => {2 it('should load 2 pages', () => {3 })4})5describe('Promise.all', () => {6 it('should load 2 pages', () => {7 })8})9describe('Promise.all', () => {10 it('should load 2 pages', () => {11 })12})13describe('Promise.all', () => {14 it('should load 2 pages', () => {15 })16})17describe('Promise.all', () => {18 it('should load 2 pages', () => {19 })20})21describe('Promise.all', () => {22 it('should load 2 pages', () => {23 })24})25describe('Promise.all', () => {26 it('should load 2 pages', () => {27 })28})29describe('Promise.all', () => {30 it('should load 2 pages', () => {31 })32})33describe('Promise.all', () => {34 it('should load
Using AI Code Generation
1describe('Test', () => {2 it('test', () => {3 cy.get('input[type=text]').type('Cypress')4 cy.get('input[type=submit]').click()5 cy.get('h3.r > a:first').then((a) => {6 cy.request(a.prop('href')).then((res) => {7 expect(res.status).to.eq(200)8 })9 })10 cy.get('h3.r > a:first').then((a) => {11 cy.request(a.prop('href')).then((res) => {12 expect(res.status).to.eq(200)13 })14 })15 cy.get('h3.r > a:first').then((a) => {16 cy.request(a.prop('href')).then((res) => {17 expect(res.status).to.eq(200)18 })19 })20 cy.get('h3.r > a:first').then((a) => {21 cy.request(a.prop('href')).then((res) => {22 expect(res.status).to.eq(200)23 })24 })25 cy.get('h3.r > a:first').then((a) => {26 cy.request(a.prop('href')).then((res) => {27 expect(res.status).to.eq(200)28 })29 })30 })31})32describe('Test', () => {33 it('test', () => {34 cy.get('input[type=text]').type('Cypress')35 cy.get('input[type=submit]').click()36 cy.get('h3.r > a:first').then((a) => {37 cy.request(a.prop('href')).then((res) => {38 expect(res.status).to.eq(200)39 })40 })41 cy.get('h3.r > a:first').then((a) => {42 cy.request(a.prop('href')).then((res) => {43 expect(res.status).to.eq(200)44 })45 })46 cy.get('h3.r > a:first').then((a) => {47 cy.request(a.prop('href')).then((res) => {48 expect(res.status).to.eq(200)49 })50 })51 cy.get('h3.r > a:first').then((a) => {52 cy.request(a.prop
Using AI Code Generation
1describe('Cypress Promise', function() {2 it('Promise', function() {3 cy.get('input[name="q"]').type('Cypress')4 cy.get('input[name="btnK"]').click()5 cy.get('h3.LC20lb').then(function($a){6 const firstLink = $a.first()7 const secondLink = $a.eq(1)8 const thirdLink = $a.last()9 cy.wrap(firstLink).invoke('text').as('firstLinkText')10 cy.wrap(secondLink).invoke('text').as('secondLinkText')11 cy.wrap(thirdLink).invoke('text').as('thirdLinkText')12 cy.get('@firstLinkText').then(function(firstLinkText){13 cy.log(firstLinkText)14 })15 cy.get('@secondLinkText').then(function(secondLinkText){16 cy.log(secondLinkText)17 })18 cy.get('@thirdLinkText').then(function(thirdLinkText){19 cy.log(thirdLinkText)20 })21 cy.wrap(firstLink).click()22 cy.go('back')23 cy.wrap(secondLink).click()24 cy.go('back')25 cy.wrap(thirdLink).click()26 cy.go('back')27 })28 })29})30describe('Cypress Promise', function() {31 it('Promise', function() {32 cy.get('input[name="q"]').type('Cypress')33 cy.get('input[name="btnK"]').click()34 cy.get('h3.LC20lb').then(function($a){35 const firstLink = $a.first()36 const secondLink = $a.eq(1)37 const thirdLink = $a.last()38 cy.wrap(firstLink).invoke('text').as('firstLinkText')39 cy.wrap(secondLink).invoke('text').as('secondLinkText')40 cy.wrap(thirdLink).invoke('text').as('thirdLinkText')41 cy.get('@firstLinkText').then(function(firstLinkText){42 cy.log(firstLinkText)43 })44 cy.get('@secondLinkText').then(function(secondLinkText){45 cy.log(secondLinkText)46 })47 cy.get('@thirdLinkText').then(function(thirdLinkText){48 cy.log(thirdLinkText)
Using AI Code Generation
1describe('Cypress Promise.all', () => {2 it('Promise.all', () => {3 cy.get('#lst-ib').type('Cypress')4 cy.get('#lst-ib').type('{enter}')5 cy.get('#rso > div > div > div:nth-child(1) > div > div > h3 > a').then(($link) => {6 const link = $link.text()7 cy.log(link)8 cy.get('#rso > div > div > div:nth-child(1) > div > div > h3 > a').click()9 cy.title().should('eq', link)10 })11 cy.get('#rso > div > div > div:nth-child(2) > div > div > h3 > a').then(($link) => {12 const link = $link.text()13 cy.log(link)14 cy.get('#rso > div > div > div:nth-child(2) > div > div > h3 > a').click()15 cy.title().should('eq', link)16 })17 cy.get('#rso > div > div > div:nth-child(3) > div > div > h3 > a').then(($link) => {18 const link = $link.text()19 cy.log(link)20 cy.get('#rso > div > div > div:nth-child(3) > div > div > h3 > a').click()21 cy.title().should('eq', link)22 })23 cy.get('#rso > div > div > div:nth-child(4) > div > div > h3 > a').then(($link) => {24 const link = $link.text()25 cy.log(link)26 cy.get('#rso > div > div > div:nth-child(4) > div > div > h3 > a').click()27 cy.title().should('eq', link)28 })29 cy.get('#rso > div > div > div:nth-child(5) > div > div > h3 > a').then(($link) => {30 const link = $link.text()31 cy.log(link)32 cy.get('#rso > div > div > div:nth-child(5) > div > div > h3 > a').click()33 cy.title().should('eq', link)34 })35 })36})
Using AI Code Generation
1Cypress.Commands.add("waitOnAPI", (url1, url2) => {2 cy.request(url1)3 cy.request(url2)4})5Cypress.Commands.add("waitOnAPI", (url1, url2, url3) => {6 cy.request(url1)7 cy.request(url2)8 cy.request(url3)9})10Cypress.Commands.add("waitOnAPI", (url1, url2, url3, url4) => {11 cy.request(url1)12 cy.request(url2)13 cy.request(url3)14 cy.request(url4)15})16Cypress.Commands.add("waitOnAPI", (url1, url2, url3, url4, url5) => {17 cy.request(url1)18 cy.request(url2)19 cy.request(url3)20 cy.request(url4)21 cy.request(url5)22})23Cypress.Commands.add("waitOnAPI", (url1, url2, url3, url4, url5, url6) => {24 cy.request(url1)25 cy.request(url2)26 cy.request(url3)27 cy.request(url4)28 cy.request(url5)29 cy.request(url6)30})31Cypress.Commands.add("waitOnAPI", (url1, url2, url3, url4, url5, url6, url7) => {32 cy.request(url1)33 cy.request(url2)34 cy.request(url3)35 cy.request(url4)
Using AI Code Generation
1const request = require('cypress/types/request');2Promise.all([3 request(url),4 request(url2),5 request(url3)6]).then((responses) => {7 responses.forEach((response) => {8 expect(response.status).to.eq(200)9 })10})11const request = require('cypress/types/request');12Promise.all([13 request(url),14 request(url2),15 request(url3)16]).then((responses) => {17 responses.forEach((response) => {18 expect(response.status).to.eq(200)19 })20})21const request = require('cypress/types/request');22Promise.all([23 request(url),24 request(url2),25 request(url3)26]).then((responses) => {27 responses.forEach((response) => {28 expect(response.status).to.eq(200)29 })30})
Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.
You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!