Best JavaScript code snippet using fast-check-monorepo
89-delay_spec.js
Source:89-delay_spec.js
1/**2 * Copyright JS Foundation and other contributors, http://js.foundation3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 **/16var should = require("should");17var delayNode = require("nr-test-utils").require("@node-red/nodes/core/function/89-delay.js");18var helper = require("node-red-node-test-helper");19var RED = require("nr-test-utils").require("node-red/lib/red");20var GRACE_PERCENTAGE=10;21var nanosToSeconds = 1000000000;22var millisToSeconds = 1000;23var secondsToMinutes = 60;24var secondsToHours = 3600;25var secondsToDays = 86400;26describe('delay Node', function() {27 beforeEach(function(done) {28 helper.startServer(done);29 });30 afterEach(function(done) {31 RED.settings.nodeMessageBufferMaxLength = 0;32 helper.unload();33 helper.stopServer(done);34 });35 it('should be loaded', function(done) {36 var flow = [{"id":"delayNode1","type":"delay", "nbRateUnits":"1", "name":"delayNode","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"day","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[[]]}];37 helper.load(delayNode, flow, function() {38 var delayNode1 = helper.getNode("delayNode1");39 delayNode1.should.have.property('name', 'delayNode');40 delayNode1.should.have.property('rate', 86400000);41 done();42 });43 });44 it('should be able to set rate to hour', function(done) {45 var flow = [{"id":"delayNode1","type":"delay", "nbRateUnits":"1", "name":"delayNode","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"hour","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[[]]}];46 helper.load(delayNode, flow, function() {47 var delayNode1 = helper.getNode("delayNode1");48 delayNode1.should.have.property('name', 'delayNode');49 delayNode1.should.have.property('rate', 3600000);50 done();51 });52 });53 it('should be able to set rate to minute', function(done) {54 var flow = [{"id":"delayNode1","type":"delay", "nbRateUnits":"1", "name":"delayNode","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"minute","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[[]]}];55 helper.load(delayNode, flow, function() {56 var delayNode1 = helper.getNode("delayNode1");57 delayNode1.should.have.property('name', 'delayNode');58 delayNode1.should.have.property('rate', 60000);59 done();60 });61 });62 var TimeUnitEnum = {63 MILLIS : "milliseconds",64 SECONDS : "seconds",65 MINUTES : "minutes",66 HOURS : "hours",67 DAYS : "days"68 }69 /**70 * Tells whether two numeric values are close enough to each other71 * @param actualValue - the value we're testing72 * @param expectedValue - the value we're matching the test value against73 * @param tolerancePercent - the percentage of tolerated deviation (0 means equals)74 */75 function closeEnough(actualValue, expectedValue, tolerancePercent) {76 var toReturn;77 var toleranceFraction = expectedValue * (tolerancePercent/100);78 var minExpected = expectedValue - toleranceFraction;79 var maxExpected = expectedValue + toleranceFraction;80 if (actualValue >= minExpected && actualValue <= maxExpected) {81 toReturn = true;82 } else {83 toReturn = false;84 }85 return toReturn;86 }87 /**88 * Runs a delay test89 * @param aTimeout - the timeout quantity90 * @param aTimeoutUnit - the unit of the timeout: milliseconds, seconds, minutes, hours, days91 */92 function genericDelayTest(aTimeout, aTimeoutUnit, done) {93 var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"delay","timeout":aTimeout,"timeoutUnits":aTimeoutUnit,"rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]},94 {id:"helperNode1", type:"helper", wires:[]}];95 helper.load(delayNode, flow, function() {96 var delayNode1 = helper.getNode("delayNode1");97 var helperNode1 = helper.getNode("helperNode1");98 helperNode1.on("input", function(msg) {99 try {100 var endTime = process.hrtime(startTime);101 var runtimeNanos = ( (endTime[0] * nanosToSeconds) + endTime[1] );102 var runtimeSeconds = runtimeNanos / nanosToSeconds;103 var aTimeoutUnifiedToSeconds;104 // calculating the timeout in seconds105 if (aTimeoutUnit == TimeUnitEnum.MILLIS) {106 aTimeoutUnifiedToSeconds = aTimeout / millisToSeconds;107 } else if (aTimeoutUnit == TimeUnitEnum.SECONDS) {108 aTimeoutUnifiedToSeconds = aTimeout;109 } else if (aTimeoutUnit == TimeUnitEnum.MINUTES) {110 aTimeoutUnifiedToSeconds = aTimeout * secondsToMinutes;111 } else if (aTimeoutUnit == TimeUnitEnum.HOURS) {112 aTimeoutUnifiedToSeconds = aTimeout * secondsToHours;113 } else if (aTimeoutUnit == TimeUnitEnum.DAYS) {114 aTimeoutUnifiedToSeconds = aTimeout * secondsToDays;115 }116 if (closeEnough(runtimeSeconds, aTimeoutUnifiedToSeconds, GRACE_PERCENTAGE)) {117 done();118 } else {119 try {120 should.fail(null, null, "Delayed runtime seconds " + runtimeSeconds + " was not close enough to exlected timeout seconds: " + aTimeoutUnifiedToSeconds);121 } catch (err) {122 done(err);123 }124 }125 } catch(err) {126 done(err);127 }128 });129 var startTime = process.hrtime();130 delayNode1.receive({payload:"delayMe"});131 });132 }133 /**134 * We send a message, take a timestamp then when the message is received by the helper node, we take another timestamp.135 * Then check if the message has been delayed by the expected amount.136 */137 it('delays the message in seconds', function(done) {138 genericDelayTest(0.5, "seconds", done);139 });140 it('delays the message in milliseconds', function(done) {141 genericDelayTest(500, "milliseconds", done);142 });143 it('delays the message in minutes', function(done) { // this is also 0.5 seconds144 genericDelayTest(0.00833, "minutes", done);145 });146 it('delays the message in hours', function(done) { // this is also 0.5 seconds147 genericDelayTest(0.0001388, "hours", done);148 });149 it('delays the message in days', function(done) { // this is also 0.5 seconds150 genericDelayTest(0.000005787, "days", done);151 });152 /**153 * Runs a rate limit test - only testing seconds!154 * @param aLimit - the message limit count155 * @param nbUnit - the multiple of the unit, aLimit Message for nbUnit Seconds156 * @param runtimeInMillis - when to terminate run and count messages received157 */158 function genericRateLimitSECONDSTest(aLimit, nbUnit, runtimeInMillis, rateValue, done) {159 var flow = [{"id":"delayNode1","type":"delay","nbRateUnits":nbUnit,"name":"delayNode","pauseType":"rate","timeout":5,"timeoutUnits":"seconds","rate":aLimit,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]},160 {id:"helperNode1", type:"helper", wires:[]}];161 helper.load(delayNode, flow, function() {162 var delayNode1 = helper.getNode("delayNode1");163 var helperNode1 = helper.getNode("helperNode1");164 var receivedMessagesStack = [];165 var rate = 1000 / aLimit * nbUnit;166 var receiveTimestamp;167 helperNode1.on("input", function(msg) {168 if (receiveTimestamp) {169 var elapse = process.hrtime(receiveTimestamp);170 var receiveInterval = (elapse[0] * 1000) + ((elapse[1] / nanosToSeconds) * 1000);171 receiveInterval.should.be.above(rate * 0.9);172 }173 receiveTimestamp = process.hrtime();174 receivedMessagesStack.push(msg);175 });176 var possibleMaxMessageCount = Math.ceil(aLimit * (runtimeInMillis / 1000) + aLimit); // +aLimit as at the start of the 2nd period, we're allowing the 3rd burst177 var i = 0;178 for (; i < possibleMaxMessageCount + 1; i++) {179 delayNode1.receive({ payload: i, rate: rateValue });180 }181 setTimeout(function() {182 try {183 receivedMessagesStack.length.should.be.lessThan(possibleMaxMessageCount);184 for (var j = 0; j < receivedMessagesStack.length; j++) {185 if (receivedMessagesStack[j].payload === j) {186 if (j === (receivedMessagesStack.length -1)) { // last message, all matched so far187 done();188 }189 } else {190 should.fail(null, null, "Received messages were not received in order. Message was " + receivedMessagesStack[i].payload + " on count " + i);191 }192 }193 } catch (err) {194 done(err);195 }196 }, runtimeInMillis);197 });198 }199 it('limits the message rate to 1 per second', function(done) {200 genericRateLimitSECONDSTest(1, 1, 1500, null, done);201 });202 it('limits the message rate to 1 per 2 seconds', function(done) {203 this.timeout(6000);204 genericRateLimitSECONDSTest(1, 2, 3000, null, done);205 });206 it('limits the message rate to 2 per seconds, 2 seconds', function(done) {207 this.timeout(6000);208 genericRateLimitSECONDSTest(2, 1, 2100, null, done);209 });210 it('limits the message rate using msg.rate', function (done) {211 RED.settings.nodeMessageBufferMaxLength = 3;212 genericRateLimitSECONDSTest(1, 1, 1500, 2000, done);213 });214 /**215 * Runs a rate limit test with drop support - only testing seconds!216 * @param aLimit - the message limit count217 * @param nbUnit - the multiple of the unit, aLimit Message for nbUnit Seconds218 * @param runtimeInMillis - when to terminate run and count messages received219 */220 function dropRateLimitSECONDSTest(aLimit, nbUnit, runtimeInMillis, rateValue, sendIntermediate, done) {221 if (!done) {222 done = sendIntermediate;223 sendIntermediate = false;224 }225 var outputs = 1;226 if (sendIntermediate) {227 outputs = 2;228 }229 var flow = [230 {"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"rate","timeout":5,"nbRateUnits":nbUnit,"timeoutUnits":"seconds","rate":aLimit,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,outputs:outputs,"wires":[["helperNode1"],["helperNode2"]]},231 {id:"helperNode1", type:"helper", wires:[]},232 {id:"helperNode2", type:"helper", wires:[]}233 ]234 ;235 helper.load(delayNode, flow, function() {236 var delayNode1 = helper.getNode("delayNode1");237 var helperNode1 = helper.getNode("helperNode1");238 var helperNode2 = helper.getNode("helperNode2");239 var receivedMessagesStack = [];240 var receivedIntermediateMessagesStack = [];241 // Add a small grace to the calculated delay242 var rate = 1000/aLimit + 10;243 var receiveTimestamp;244 helperNode1.on("input", function(msg) {245 if (receiveTimestamp) {246 var elapse = process.hrtime(receiveTimestamp);247 var receiveInterval = (elapse[0] * 1000) + ((elapse[1] / nanosToSeconds) * 1000);248 receiveInterval.should.be.above(rate * 0.9);249 }250 receiveTimestamp = process.hrtime();251 receivedMessagesStack.push(msg);252 });253 helperNode2.on("input", function(msg) {254 receivedIntermediateMessagesStack.push(msg);255 });256 var possibleMaxMessageCount = Math.ceil(aLimit * (runtimeInMillis / 1000) + aLimit); // +aLimit as at the start of the 2nd period, we're allowing the 3rd burst257 var i = 0;258 delayNode1.receive({ payload: i, rate: rateValue });259 i++;260 for (; i < possibleMaxMessageCount + 1; i++) {261 setTimeout(function() {262 delayNode1.receive({payload:i});263 }, 2 * ((rate * i) / possibleMaxMessageCount) );264 }265 //we need to send a message delayed so that it doesn't get dropped266 setTimeout(function() {267 delayNode1.receive({payload:++i});268 }, runtimeInMillis - 300); // should give enough time to squeeze another message in269 setTimeout(function() {270 try {271 receivedMessagesStack.length.should.be.lessThan(possibleMaxMessageCount + 1);272 receivedMessagesStack.length.should.be.greaterThan(2); // ensure that we receive more than 1st and last message273 receivedMessagesStack[0].payload.should.be.exactly(0); // means we received the last message injected just before test termination274 var foundAtLeastOneDrop = false;275 for (var i = 0; i < receivedMessagesStack.length; i++) {276 if (i > 0) {277 if (receivedMessagesStack[i].payload - receivedMessagesStack[i - 1].payload > 1) {278 foundAtLeastOneDrop = true;279 }280 }281 }282 foundAtLeastOneDrop.should.be.true();283 if (sendIntermediate) {284 receivedIntermediateMessagesStack.length.should.be.greaterThan(0);285 } else {286 receivedIntermediateMessagesStack.length.should.be.exactly(0);287 }288 done();289 } catch (err) {290 done(err);291 }292 }, runtimeInMillis);293 });294 }295 it('limits the message rate to 1 per second, 4 seconds, with drop', function(done) {296 this.timeout(6000);297 dropRateLimitSECONDSTest(1, 1, 4000, null, done);298 });299 it('limits the message rate to 1 per 2 seconds, 4 seconds, with drop', function(done) {300 this.timeout(6000);301 dropRateLimitSECONDSTest(1, 2, 4500, null, done);302 });303 it('limits the message rate to 2 per second, 5 seconds, with drop', function(done) {304 this.timeout(6000);305 dropRateLimitSECONDSTest(2, 1, 5000, null, done);306 });307 it('limits the message rate to 2 per second, 5 seconds, with drop, 2nd output', function(done) {308 this.timeout(6000);309 dropRateLimitSECONDSTest(2, 1, 5000, null, true, done);310 });311 it('limits the message rate with drop using msg.rate', function (done) {312 this.timeout(6000);313 RED.settings.nodeMessageBufferMaxLength = 3;314 dropRateLimitSECONDSTest(2, 1, 5000, 1000, done);315 });316 /**317 * Returns true if the actualTimeout is gracefully in between the timeoutFrom and timeoutTo318 * values. Gracefully means that inBetween could actually mean smaller/greater values319 * than the timeout range so long as it's within an actual grace percentage.320 * @param timeoutFrom - The expected timeout range (low number)321 * @param timeoutTo - The expected timeout range (high number)322 * @param actualTimeout - The actual measured timeout value of test323 * @param allowedGracePercent - The percentage of grace allowed324 */325 function inBetweenDelays(timeoutFrom, timeoutTo, actualTimeout, allowedGracePercent) {326 if (closeEnough(actualTimeout, timeoutFrom, allowedGracePercent)) {327 return true;328 } else if (closeEnough(actualTimeout, timeoutTo, allowedGracePercent)) {329 return true;330 } else if (timeoutFrom < actualTimeout && timeoutTo > actualTimeout) {331 return true;332 } else {333 return false;334 }335 }336 /**337 * Runs a VARIABLE DELAY test, checks if the delay is in between the given timeout values338 * @param aTimeoutFrom - the timeout quantity which is the minimal acceptable wait period339 * @param aTimeoutTo - the timeout quantity which is the maximum acceptable wait period340 * @param aTimeoutUnit - the unit of the timeout: milliseconds, seconds, minutes, hours, days341 * @param delay - the variable delay: milliseconds342 */343 function variableDelayTest(aTimeoutFrom, aTimeoutTo, aTimeoutUnit, delay, done) {344 var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"delayv","timeout":0.5,"timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":aTimeoutFrom,"randomLast":aTimeoutTo,"randomUnits":aTimeoutUnit,"drop":false,"wires":[["helperNode1"]]},345 {id:"helperNode1", type:"helper", wires:[]}];346 helper.load(delayNode, flow, function() {347 var delayNode1 = helper.getNode("delayNode1");348 var helperNode1 = helper.getNode("helperNode1");349 helperNode1.on("input", function(msg) {350 try {351 var endTime = process.hrtime(startTime);352 var runtimeNanos = ( (endTime[0] * nanosToSeconds) + endTime[1] );353 var runtimeSeconds = runtimeNanos / nanosToSeconds;354 var aTimeoutFromUnifiedToSeconds;355 var aTimeoutToUnifiedToSeconds;356 // calculating the timeout in seconds357 if (aTimeoutUnit == TimeUnitEnum.MILLIS) {358 aTimeoutFromUnifiedToSeconds = aTimeoutFrom / millisToSeconds;359 aTimeoutToUnifiedToSeconds = aTimeoutTo / millisToSeconds;360 } else if (aTimeoutUnit == TimeUnitEnum.SECONDS) {361 aTimeoutFromUnifiedToSeconds = aTimeoutFrom;362 aTimeoutToUnifiedToSeconds = aTimeoutTo;363 } else if (aTimeoutUnit == TimeUnitEnum.MINUTES) {364 aTimeoutFromUnifiedToSeconds = aTimeoutFrom * secondsToMinutes;365 aTimeoutToUnifiedToSeconds = aTimeoutTo * secondsToMinutes;366 } else if (aTimeoutUnit == TimeUnitEnum.HOURS) {367 aTimeoutFromUnifiedToSeconds = aTimeoutFrom * secondsToHours;368 aTimeoutToUnifiedToSeconds = aTimeoutTo * secondsToHours;369 } else if (aTimeoutUnit == TimeUnitEnum.DAYS) {370 aTimeoutFromUnifiedToSeconds = aTimeoutFrom * secondsToDays;371 aTimeoutToUnifiedToSeconds = aTimeoutTo * secondsToDays;372 }373 if (inBetweenDelays(aTimeoutFromUnifiedToSeconds, aTimeoutToUnifiedToSeconds, runtimeSeconds, GRACE_PERCENTAGE)) {374 done();375 } else {376 try {377 should.fail(null, null, "Delayed runtime seconds " + runtimeSeconds + " was not \"in between enough\" enough to expected values of: " + aTimeoutFromUnifiedToSeconds + " and " + aTimeoutToUnifiedToSeconds);378 } catch (err) {379 done(err);380 }381 }382 } catch(err) {383 done(err);384 }385 });386 var startTime = process.hrtime();387 delayNode1.receive({payload:"delayMe", delay:delay});388 });389 }390 it('variable delay set by msg.delay the message in milliseconds', function(done) {391 variableDelayTest("200", "300", "milliseconds", 250, done);392 });393 it('variable delay is the default if msg.delay not specified', function(done) {394 variableDelayTest("450", "550", "milliseconds", null, done);395 });396 it('variable delay is zero if msg.delay is zero', function(done) {397 variableDelayTest("0", "20", "milliseconds", 0, done);398 });399 it('variable delay is zero if msg.delay is negative', function(done) {400 variableDelayTest("0", "20", "milliseconds", -250, done);401 });402 /**403 * Runs a RANDOM DELAY test, checks if the delay is in between the given timeout values404 * @param aTimeoutFrom - the timeout quantity which is the minimal acceptable wait period405 * @param aTimeoutTo - the timeout quantity which is the maximum acceptable wait period406 * @param aTimeoutUnit - the unit of the timeout: milliseconds, seconds, minutes, hours, days407 */408 function randomDelayTest(aTimeoutFrom, aTimeoutTo, aTimeoutUnit, done) {409 var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"random","timeout":5,"timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":aTimeoutFrom,"randomLast":aTimeoutTo,"randomUnits":aTimeoutUnit,"drop":false,"wires":[["helperNode1"]]},410 {id:"helperNode1", type:"helper", wires:[]}];411 helper.load(delayNode, flow, function() {412 var delayNode1 = helper.getNode("delayNode1");413 var helperNode1 = helper.getNode("helperNode1");414 helperNode1.on("input", function(msg) {415 try {416 var endTime = process.hrtime(startTime);417 var runtimeNanos = ( (endTime[0] * nanosToSeconds) + endTime[1] );418 var runtimeSeconds = runtimeNanos / nanosToSeconds;419 var aTimeoutFromUnifiedToSeconds;420 var aTimeoutToUnifiedToSeconds;421 // calculating the timeout in seconds422 if (aTimeoutUnit == TimeUnitEnum.MILLIS) {423 aTimeoutFromUnifiedToSeconds = aTimeoutFrom / millisToSeconds;424 aTimeoutToUnifiedToSeconds = aTimeoutTo / millisToSeconds;425 } else if (aTimeoutUnit == TimeUnitEnum.SECONDS) {426 aTimeoutFromUnifiedToSeconds = aTimeoutFrom;427 aTimeoutToUnifiedToSeconds = aTimeoutTo;428 } else if (aTimeoutUnit == TimeUnitEnum.MINUTES) {429 aTimeoutFromUnifiedToSeconds = aTimeoutFrom * secondsToMinutes;430 aTimeoutToUnifiedToSeconds = aTimeoutTo * secondsToMinutes;431 } else if (aTimeoutUnit == TimeUnitEnum.HOURS) {432 aTimeoutFromUnifiedToSeconds = aTimeoutFrom * secondsToHours;433 aTimeoutToUnifiedToSeconds = aTimeoutTo * secondsToHours;434 } else if (aTimeoutUnit == TimeUnitEnum.DAYS) {435 aTimeoutFromUnifiedToSeconds = aTimeoutFrom * secondsToDays;436 aTimeoutToUnifiedToSeconds = aTimeoutTo * secondsToDays;437 }438 if (inBetweenDelays(aTimeoutFromUnifiedToSeconds, aTimeoutToUnifiedToSeconds, runtimeSeconds, GRACE_PERCENTAGE)) {439 done();440 } else {441 try {442 should.fail(null, null, "Delayed runtime seconds " + runtimeSeconds + " was not \"in between enough\" enough to expected values of: " + aTimeoutFromUnifiedToSeconds + " and " + aTimeoutToUnifiedToSeconds);443 } catch (err) {444 done(err);445 }446 }447 } catch(err) {448 done(err);449 }450 });451 var startTime = process.hrtime();452 delayNode1.receive({payload:"delayMe"});453 });454 }455 it('randomly delays the message in seconds', function(done) {456 randomDelayTest(0.4, 0.8, "seconds", done);457 });458 it('randomly delays the message in milliseconds', function(done) {459 randomDelayTest("400", "800", "milliseconds", done);460 });461 it('randomly delays the message in minutes', function(done) {462 randomDelayTest(0.0066, 0.0133, "minutes", done);463 });464 it('delays the message in hours', function(done) {465 randomDelayTest(0.000111111, 0.000222222, "hours", done);466 });467 it('delays the message in days', function(done) {468 randomDelayTest(0.0000046296, 0.0000092593, "days", done);469 });470 it('handles delay queue', function(done) {471 this.timeout(2000);472 var flow = [{id:"delayNode1", type :"delay","name":"delayNode","nbRateUnits":"1","pauseType":"queue","timeout":1,"timeoutUnits":"seconds","rate":4,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]},473 {id:"helperNode1", type:"helper", wires:[]}];474 helper.load(delayNode, flow, function() {475 var delayNode1 = helper.getNode("delayNode1");476 var helperNode1 = helper.getNode("helperNode1");477 var t = Date.now();478 helperNode1.on("input", function(msg) {479 msg.should.have.a.property('payload');480 msg.should.have.a.property('topic');481 try {482 if (msg.topic === "_none_") {483 msg.payload.should.equal(2);484 (Date.now() - t).should.be.approximately(500,200);485 }486 else if (msg.topic === "A") {487 msg.payload.should.equal(4);488 (Date.now() - t).should.be.approximately(750,200);489 }490 else {491 msg.topic.should.equal("B");492 msg.payload.should.equal(1);493 (Date.now() - t).should.be.approximately(1000,200);494 done();495 }496 } catch(e) {497 done(e);498 }499 });500 setTimeout(function() {501 // send test messages502 delayNode1.receive({payload:1}); // send something with blank topic503 delayNode1.receive({payload:1,topic:"A"}); // and something with a fixed topic504 delayNode1.receive({payload:1,topic:"B"}); // and something else with a fixed topic (3rd tick)505 delayNode1.receive({payload:2,topic:"A"}); // these should replace them in queue506 delayNode1.receive({payload:3,topic:"A"}); // ditto507 delayNode1.receive({payload:2}); // so only this should get out on first tick508 delayNode1.receive({payload:4,topic:"A"}); // and this one on second tick509 }, 275); // wait one tick beofre starting.. (to test no messages in queue path.)510 });511 });512 it('handles timed queue', function(done) {513 this.timeout(2000);514 var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"timed","timeout":1,"timeoutUnits":"seconds","rate":2,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]},515 {id:"helperNode1", type:"helper", wires:[]}];516 helper.load(delayNode, flow, function() {517 var delayNode1 = helper.getNode("delayNode1");518 var helperNode1 = helper.getNode("helperNode1");519 var t = Date.now();520 helperNode1.on("input", function(msg) {521 msg.should.have.a.property('payload');522 msg.should.have.a.property('topic');523 try {524 if (msg.topic === "_none_") {525 msg.payload.should.equal(2);526 (Date.now() - t).should.be.approximately(500,200);527 }528 else if (msg.topic === "A") {529 msg.payload.should.equal(4);530 (Date.now() - t).should.be.approximately(500,200);531 }532 else {533 msg.topic.should.equal("B");534 msg.payload.should.equal(1);535 (Date.now() - t).should.be.approximately(500,200);536 done();537 }538 } catch(e) {539 done(e);540 }541 });542 // send test messages543 delayNode1.receive({payload:1}); // send something with blank topic544 delayNode1.receive({payload:1,topic:"A"}); // and something with a fixed topic545 delayNode1.receive({payload:1,topic:"B"}); // and something else with a fixed topic546 delayNode1.receive({payload:2,topic:"A"}); // these should replace them in queue547 delayNode1.receive({payload:3,topic:"A"}); // ditto548 delayNode1.receive({payload:2}); // so all should go on first tick549 delayNode1.receive({payload:4,topic:"A"}); // and nothing on second550 });551 });552 it('can flush delay queue', function(done) {553 this.timeout(2000);554 var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"delay","timeout":1,"timeoutUnits":"seconds","rate":2,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]},555 {id:"helperNode1", type:"helper", wires:[]}];556 helper.load(delayNode, flow, function() {557 var delayNode1 = helper.getNode("delayNode1");558 var helperNode1 = helper.getNode("helperNode1");559 var t = Date.now();560 var c = 0;561 helperNode1.on("input", function(msg) {562 msg.should.have.a.property('payload');563 msg.should.have.a.property('topic');564 try {565 if (msg.topic === "foo") {566 msg.payload.should.equal(1);567 (Date.now() - t).should.be.approximately(0,100);568 c = c + 1;569 }570 else {571 if (msg.topic === "bar") {572 msg.payload.should.equal(1);573 (Date.now() - t).should.be.approximately(0,100);574 c = c + 1;575 }576 }577 if (c === 5) { done(); }578 } catch(e) {579 done(e);580 }581 });582 // send test messages583 delayNode1.receive({payload:1,topic:"foo"}); // send something with blank topic584 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic585 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic586 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic587 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic588 setImmediate( function() { delayNode1.receive({flush:true}); }); // reset the queue589 });590 });591 it('can part flush delay queue', function(done) {592 this.timeout(2000);593 var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"delay","timeout":1,"timeoutUnits":"seconds","rate":2,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]},594 {id:"helperNode1", type:"helper", wires:[]}];595 helper.load(delayNode, flow, function() {596 var delayNode1 = helper.getNode("delayNode1");597 var helperNode1 = helper.getNode("helperNode1");598 var t = Date.now();599 var c = 0;600 helperNode1.on("input", function(msg) {601 msg.should.have.a.property('payload');602 msg.should.have.a.property('topic');603 try {604 if (msg.topic === "foo") {605 msg.payload.should.equal(1);606 (Date.now() - t).should.be.approximately(0,100);607 c = c + 1;608 }609 else if (msg.topic === "bar") {610 msg.payload.should.equal(1);611 (Date.now() - t).should.be.approximately(200,100);612 c = c + 1;613 }614 else if (msg.topic === "boo") {615 msg.payload.should.equal(1);616 (Date.now() - t).should.be.approximately(400,100);617 c = c + 1;618 }619 if (c === 5) { done(); }620 } catch(e) {621 done(e);622 }623 });624 // send test messages625 delayNode1.receive({payload:1,topic:"foo"});626 setImmediate( function() { delayNode1.receive({payload:1,topic:"foo"}); } );627 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } );628 setImmediate( function() { delayNode1.receive({payload:1,topic:"boo"}); } );629 setImmediate( function() { delayNode1.receive({payload:1,topic:"boo"}); } );630 setImmediate( function() { delayNode1.receive({flush:2}); });631 setTimeout( function() { delayNode1.receive({flush:1}); }, 200);632 setTimeout( function() { delayNode1.receive({flush:4}); }, 400);633 });634 });635 it('can reset delay queue', function(done) {636 this.timeout(2000);637 var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"delay","timeout":1,"timeoutUnits":"seconds","rate":2,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]},638 {id:"helperNode1", type:"helper", wires:[]}];639 helper.load(delayNode, flow, function() {640 var delayNode1 = helper.getNode("delayNode1");641 var helperNode1 = helper.getNode("helperNode1");642 var t = Date.now();643 var c = 0;644 helperNode1.on("input", function(msg) {645 c = c + 1;646 });647 setTimeout( function() {648 if (c === 0) { done(); }649 }, 700);650 // send test messages651 delayNode1.receive({payload:1,topic:"foo"}); // send something with blank topic652 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic653 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic654 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic655 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic656 setImmediate( function() { delayNode1.receive({reset:true}); }); // reset the queue657 });658 });659 it('can flush rate limit queue', function(done) {660 this.timeout(2000);661 var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"rate","timeout":1,"timeoutUnits":"seconds","rate":2,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]},662 {id:"helperNode1", type:"helper", wires:[]}];663 helper.load(delayNode, flow, function() {664 var delayNode1 = helper.getNode("delayNode1");665 var helperNode1 = helper.getNode("helperNode1");666 var t = Date.now();667 var c = 0;668 helperNode1.on("input", function(msg) {669 msg.should.have.a.property('payload');670 msg.should.have.a.property('topic');671 try {672 if (msg.topic === "foo") {673 msg.payload.should.equal(1);674 (Date.now() - t).should.be.approximately(0,100);675 c = c + 1;676 }677 else {678 if (msg.topic === "bar") {679 msg.payload.should.equal(1);680 (Date.now() - t).should.be.approximately(0,100);681 c = c + 1;682 }683 }684 if (c === 5) { done(); }685 } catch(e) {686 done(e);687 }688 });689 // send test messages690 delayNode1.receive({payload:1,topic:"foo"}); // send something with blank topic691 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic692 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic693 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic694 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic695 setImmediate( function() { delayNode1.receive({flush:true}); }); // reset the queue696 });697 });698 it('can part flush rate limit queue', function(done) {699 this.timeout(2000);700 var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"rate","timeout":1,"timeoutUnits":"seconds","rate":2,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]},701 {id:"helperNode1", type:"helper", wires:[]}];702 helper.load(delayNode, flow, function() {703 var delayNode1 = helper.getNode("delayNode1");704 var helperNode1 = helper.getNode("helperNode1");705 var t = Date.now();706 var c = 0;707 helperNode1.on("input", function(msg) {708 msg.should.have.a.property('payload');709 msg.should.have.a.property('topic');710 try {711 if (msg.topic === "foo") {712 msg.payload.should.equal(1);713 (Date.now() - t).should.be.approximately(0,100);714 c = c + 1;715 }716 else if (msg.topic === "bar") {717 msg.payload.should.equal(1);718 (Date.now() - t).should.be.approximately(200,100);719 c = c + 1;720 }721 else if (msg.topic === "boo") {722 msg.payload.should.equal(1);723 (Date.now() - t).should.be.approximately(400,100);724 c = c + 1;725 }726 if (c === 5) { done(); }727 } catch(e) {728 done(e);729 }730 });731 // send test messages732 delayNode1.receive({payload:1,topic:"foo"});733 setImmediate( function() { delayNode1.receive({payload:1,topic:"foo"}); } );734 setImmediate( function() { delayNode1.receive({payload:1,topic:"foo"}); } );735 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } );736 setImmediate( function() { delayNode1.receive({payload:1,topic:"boo"}); } );737 setImmediate( function() { delayNode1.receive({flush:2}); });738 setTimeout( function() { delayNode1.receive({flush:1}); }, 200);739 setTimeout( function() { delayNode1.receive({flush:4}); }, 400);740 });741 });742 it('can part push to front of rate limit queue', function(done) {743 this.timeout(2000);744 var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"rate","timeout":1,"timeoutUnits":"seconds","rate":1,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]},745 {id:"helperNode1", type:"helper", wires:[]}];746 helper.load(delayNode, flow, function() {747 var delayNode1 = helper.getNode("delayNode1");748 var helperNode1 = helper.getNode("helperNode1");749 var t = Date.now();750 var c = 0;751 helperNode1.on("input", function(msg) {752 msg.should.have.a.property('payload');753 msg.should.have.a.property('topic');754 try {755 if (msg.topic === "aoo") {756 msg.payload.should.equal(1);757 (Date.now() - t).should.be.approximately(2,50);758 c = c + 1;759 }760 else if (msg.topic === "eoo") {761 msg.payload.should.equal(1);762 (Date.now() - t).should.be.approximately(4,50);763 c = c + 1;764 }765 else if (msg.topic === "coo") {766 msg.payload.should.equal(1);767 (Date.now() - t).should.be.approximately(202,50);768 c = c + 1;769 }770 else if (msg.topic === "boo") {771 msg.payload.should.equal(1);772 (Date.now() - t).should.be.approximately(406,50);773 c = c + 1;774 }775 else if (msg.topic === "doo") {776 msg.payload.should.equal(1);777 (Date.now() - t).should.be.approximately(4,50);778 c = c + 1;779 }780 if (c === 5) { done(); }781 } catch(e) {782 done(e);783 }784 });785 // send test messages786 delayNode1.receive({payload:1,topic:"aoo"});787 setImmediate( function() { delayNode1.receive({payload:1,topic:"boo"}); } );788 setImmediate( function() { delayNode1.receive({payload:1,topic:"coo",toFront:true}); } );789 setImmediate( function() { delayNode1.receive({payload:1,topic:"doo",toFront:true,flush:1}); } );790 setImmediate( function() { delayNode1.receive({payload:1,topic:"eoo",toFront:true}); } );791 setImmediate( function() { delayNode1.receive({flush:1}); });792 setTimeout( function() { delayNode1.receive({flush:1}); }, 200);793 setTimeout( function() { delayNode1.receive({flush:4}); }, 400);794 });795 });796 it('can reset rate limit queue', function(done) {797 this.timeout(2000);798 var flow = [{"id":"delayNode1","type":"delay","name":"delayNode","pauseType":"rate","timeout":1,"timeoutUnits":"seconds","rate":2,"rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"wires":[["helperNode1"]]},799 {id:"helperNode1", type:"helper", wires:[]}];800 helper.load(delayNode, flow, function() {801 var delayNode1 = helper.getNode("delayNode1");802 var helperNode1 = helper.getNode("helperNode1");803 var t = Date.now();804 var c = 0;805 helperNode1.on("input", function(msg) {806 msg.should.have.a.property('payload');807 msg.should.have.a.property('topic');808 try {809 if (msg.topic === "foo") {810 msg.payload.should.equal(1);811 (Date.now() - t).should.be.approximately(0,100);812 c = c + 1;813 }814 } catch(e) {815 done(e);816 }817 });818 setTimeout( function() {819 if (c === 1) { done(); }820 }, 700);821 // send test messages822 delayNode1.receive({payload:1,topic:"foo"}); // send something with blank topic823 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic824 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic825 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic826 setImmediate( function() { delayNode1.receive({payload:1,topic:"bar"}); } ); // send something with blank topic827 setImmediate( function() { delayNode1.receive({reset:true}); }); // reset the queue828 });829 });830 /* Messaging API support */831 function mapiDoneTestHelper(done, pauseType, drop, msgAndTimings) {832 const completeNode = require("nr-test-utils").require("@node-red/nodes/core/common/24-complete.js");833 const flow = [{id:"delayNode1",type:"delay",name:"delayNode", pauseType:pauseType, timeout:"1", timeoutUnits: "seconds",834 rate: "1", nbRateUnits: "1", rateUnits: "second", randomFirst:"950", randomLast:"1050",randomUnits:"milliseconds",835 drop: drop, wires: [[]]},836 {id:"completeNode1",type:"complete",scope: ["delayNode1"],uncaught:false,wires:[["helperNode1"]]},837 {id:"helperNode1",type:"helper", wires:[[]]}];838 const numMsgs = msgAndTimings.length;839 helper.load([delayNode, completeNode], flow, function () {840 const delayNode1 = helper.getNode("delayNode1");841 const helperNode1 = helper.getNode("helperNode1");842 const t = Date.now();843 let c = 0;844 helperNode1.on("input", function (msg) {845 msg.should.have.a.property('payload', msgAndTimings[c].msg.payload);846 (Date.now() - t).should.be.approximately(msgAndTimings[c].avr, msgAndTimings[c].var);847 c += 1;848 if ( c === numMsgs) {849 done();850 }851 });852 for (let i = 0; i < numMsgs; i++) {853 setImmediate( function() { delayNode1.receive(msgAndTimings[i].msg); } );854 }855 });856 }857 it('calls done when queued message is emitted (type: delay)', function(done) {858 mapiDoneTestHelper(done, "delay", false, [{msg:{payload:1}, avr:1000, var:100}]);859 });860 it('calls done when queued message is emitted (type: delayv)', function(done) {861 mapiDoneTestHelper(done, "delayv", false, [{msg:{payload:1, delay:1000}, avr:1000, var:100}]);862 });863 it('calls done when queued message is emitted (type: delay)', function(done) {864 mapiDoneTestHelper(done, "random", false, [{msg:{payload:1}, avr:1000, var:100}]);865 });866 it('calls done when queued message is cleared (type: delay)', function(done) {867 mapiDoneTestHelper(done, "delay", false, [{msg:{payload:1}, avr:100, var:100},868 {msg:{payload:2,reset:true}, avr:100, var:100}]);869 });870 it('calls done when queued message is cleared (type: delayv)', function(done) {871 mapiDoneTestHelper(done, "delayv", false, [{msg:{payload:1, delay:1000}, avr:100, var:100},872 {msg:{payload:2, reset:true}, avr:100, var:100}]);873 });874 it('calls done when queued message is cleared (type: random)', function(done) {875 mapiDoneTestHelper(done, "random", false, [{msg:{payload:1}, avr:100, var:100},876 {msg:{payload:2,reset:true}, avr:100, var:100}]);877 });878 it('calls done when queued message is flushed (type: delay)', function(done) {879 mapiDoneTestHelper(done, "delay", false, [{msg:{payload:1}, avr:100, var:100},880 {msg:{payload:2,flush:true}, avr:100, var:100}]);881 });882 it('calls done when queued message is flushed (type: delayv)', function(done) {883 mapiDoneTestHelper(done, "delayv", false, [{msg:{payload:1, delay:1000}, avr:100, var:100},884 {msg:{payload:2, flush:true}, avr:100, var:100}]);885 });886 it('calls done when queued message is flushed (type: random)', function(done) {887 mapiDoneTestHelper(done, "random", false, [{msg:{payload:1}, avr:100, var:100},888 {msg:{payload:2,flush:true}, avr:100, var:100}]);889 });890 it('calls done when rated message is emitted (drop: false)', function(done) {891 mapiDoneTestHelper(done, "rate", false, [{msg:{payload:1}, avr:0, var:100},892 {msg:{payload:2}, avr:1000, var:100}]);893 });894 it('calls done when rated message is emitted (drop: true)', function(done) {895 mapiDoneTestHelper(done, "rate", true, [{msg:{payload:1}, avr:0, var:100},896 {msg:{payload:2}, avr:0, var:100}]);897 });898 it('calls done when rated message is flushed', function(done) {899 mapiDoneTestHelper(done, "rate", false, [{msg:{payload:1}, avr:0, var:100},900 {msg:{payload:2}, avr:0, var:100},901 {msg:{payload:3,flush:true}, avr:0, var:100}]);902 });903 it('calls done when queued messages are sent (queue)', function(done) {904 this.timeout(3000);905 mapiDoneTestHelper(done, "queue", false, [{msg:{payload:1,topic:"A"}, avr:1000, var:700},906 {msg:{payload:2,topic:"B"}, avr:2000, var:700}]);907 });908 it('calls done when queued messages are sent (timed)', function(done) {909 mapiDoneTestHelper(done, "timed", false, [{msg:{payload:1,topic:"a"}, avr:500, var:700},910 {msg:{payload:2,topic:"b"}, avr:500, var:700}]);911 });912 it('calls done when queue is reset (queue/timed)', function(done) {913 mapiDoneTestHelper(done, "timed", false, [{msg:{payload:1,topic:"a"}, avr:0, var:500},914 {msg:{payload:2,reset:true}, avr:0, var:500}]);915 });916 it('calls done when queue is flushed (queue/timed)', function(done) {917 mapiDoneTestHelper(done, "timed", false, [{msg:{payload:1,topic:"a"}, avr:0, var:500},918 {msg:{payload:2,flush:true}, avr:0, var:500}]);919 });...
script.js
Source:script.js
1/* global $ TweenMax Power0 Power1 Power2 Power3 */23var stopWatch,4 loops = 1;56//A simple helper function to do display:none to multiple items7function hideAll(whichOnes) {8 for (var q = 0; q < whichOnes.length; q++) {9 $(whichOnes[q]).hide();10 }11}12//This will echo how many seconds have passed13function returnTimer() {14 stopWatch = ((new Date().getTime()) - stopWatch) * 0.001;15 console.log(stopWatch + " seconds");16}17//Set the initial states of all divs here18function setInitialStates() {19 hideAll([20 // images21 '.bg1',22 '.copy1',23 '.logo_white', 24 '.copy2txt1',25 '.copy2txt2',26 '.copy2txt3',27 '.copy2txt4',28 '.copy2plus1',29 '.copy2plus2',30 '.copy2plus3',31 '.copy2plus4',32 '.legal',33 '.blue_container',34 '.content_blue_container',35 '.logo_blue', 36 '.copy3',37 '.cta',38 '.left_border',39 '.bottom_border',40 '.right_border', 41 '.cta',42 '.logo1',43 '.backOpacity',44 '.copy4',45 ]);46}4748function resetAll() {49 TweenMax.set($(".container").find('*'), { clearProps: "all" });50}5152function replay() {53 TweenMax.killTweensOf($(".container").find('*'));54 resetAll();55 setInitialStates();56 seq01();57}5859function mainInit() {60 setInitialStates();61 $('.container').show();62 stopWatch = new Date().getTime();63 seq01();64}6566function seq01() {67 var twnDelay = 0;68 $(".bg1").show();69 $(".copy1").show();70 $(".logo_white").show();71 TweenMax.from($(".bg1"), 3, { alpha: 1, ease: Power2.easeOut, delay: twnDelay });72 twnDelay += 0.2;73 TweenMax.from($(".logo_white"), 3, { alpha: 1,x:0, ease: Power2.easeOut, delay: twnDelay });74 twnDelay += 0.5;75 TweenMax.from($(".copy1"), 3, { alpha: 0, x:0, ease: Power2.easeOut, delay: twnDelay });76 twnDelay += 1.5;77 TweenMax.delayedCall(twnDelay, seq02);78}7980function seq02() {81 var twnDelay = 0;82 $('.copy2txt1').show(); 83 $('.copy2plus1').show(); 84 $('.copy2txt2').show(); 85 $('.copy2plus2').show(); 86 $('.copy2txt3').show(); 87 $('.copy2plus3').show(); 88 $('.copy2txt4').show(); 89 $('.copy2plus4').show();90 91 $('.backOpacity').show();92 TweenMax.to($(".bg1"), 1, { alpha: 1, ease: Power2.easeOut, delay: twnDelay });93 twnDelay += 0.2;94 TweenMax.to($(".copy1"), 1, { alpha: 0, ease: Power2.easeOut, delay: twnDelay });95 twnDelay += 0.5;96 TweenMax.from($(".backOpacity"), 1.5, { alpha: 0, ease: Power2.easeOut, delay: twnDelay });97 twnDelay += 0.6; 98 TweenMax.from($(".copy2plus1"), 3, { alpha: 0, ease: Power2.easeOut, delay: twnDelay });99 TweenMax.from($(".copy2txt1"), 3, { alpha: 0, ease: Power2.easeOut, delay: twnDelay });100 twnDelay += 0.6; 101 TweenMax.from($(".copy2plus2"), 3, { alpha: 0, ease: Power2.easeOut, delay: twnDelay });102 TweenMax.from($(".copy2txt2"), 3, { alpha: 0, ease: Power2.easeOut, delay: twnDelay });103 twnDelay += 0.6; 104 TweenMax.from($(".copy2plus3"), 3, { alpha: 0, ease: Power2.easeOut, delay: twnDelay });105 TweenMax.from($(".copy2txt3"), 3, { alpha: 0, ease: Power2.easeOut, delay: twnDelay });106 twnDelay += 0.6; 107 TweenMax.from($(".copy2plus4"), 3, { alpha: 0, ease: Power2.easeOut, delay: twnDelay });108 TweenMax.from($(".copy2txt4"), 3, { alpha: 0, ease: Power2.easeOut, delay: twnDelay });109 110 twnDelay += 2.2;111 TweenMax.delayedCall(twnDelay, seq03);112}113function seq03() {114 var twnDelay = 0; 115 $('.copy3').show(); 116 twnDelay += 0.4; 117 TweenMax.to($(".bg1"), 1, { alpha: 1, ease: Power2.easeOut, delay: twnDelay });118 TweenMax.to($(".copy2plus1,.copy2plus2,.copy2plus3,.copy2plus4,.copy2txt1,.copy2txt2,.copy2txt3,.copy2txt4"), 1, { alpha: 0, ease: Power2.easeOut, delay: twnDelay });119 twnDelay += 0.4; 120 TweenMax.from($(".copy3"), 1, { alpha: 0, ease: Power2.easeOut, delay: twnDelay }); 121 twnDelay += 1;122 TweenMax.delayedCall(twnDelay, seq04);123}124function seq04() {125 var twnDelay = 0; 126 $('.left_border').show();127 $('.bottom_border').show();128 $('.right_border').show();129 $('.logo_blue').show();130 $('.copy4').show();131 $('.copy4a').show();132 $('.blue_container').show();133 $('.content_blue_container').show();134 $('.cta').show();135 $('.legal').show(); 136 TweenMax.to($(".bg1"), 1, { alpha: 1, scale:0.56, y:-38, x:90, ease: Quad.easeInOut, delay: twnDelay });137 TweenMax.to($(".copy3,.backOpacity"), 1.5, { alpha: 0, ease: Power2.easeOut, delay: twnDelay }); 138 twnDelay += 0.6;139 TweenMax.from($(".left_border"), 0.6, { height: 0, ease: Power1.easeOut, delay: twnDelay });140 twnDelay += 0.3;141 TweenMax.from($(".bottom_border"), 0.4, { width: 0, ease: Power1.easeOut, delay: twnDelay +0.30});142 143 TweenMax.from($(".logo_blue"), 0.9, { alpha: 0, ease: Power2.easeOut, delay: twnDelay +0.30 });144 twnDelay += 0.2;145 TweenMax.from($(".right_border"), 0.6, { y: 600, ease: Power1.easeOut, delay: twnDelay+0.35 }); 146 twnDelay += 1.2;147 TweenMax.from($(".copy4"), 2, { alpha: 0, ease: Power2.easeOut, delay: twnDelay });148 twnDelay += 0.3;149 TweenMax.from($(".copy4a"), 2, { alpha: 0, ease: Power2.easeOut, delay: twnDelay });150 twnDelay += 1;151 TweenMax.from($(".blue_container"), 0.9, { width: 0, ease: Power2.easeOut, delay: twnDelay });152 twnDelay += 0.8;153 TweenMax.from($(".content_blue_container"), 0.9, { alpha: 0, ease: Power2.easeOut, delay: twnDelay }); 154 TweenMax.from($(".legal"), 0.9, { opacity: 0, ease: Power1.easeOut, delay: twnDelay });155 twnDelay += 0.8;156 TweenMax.from($(".cta"), 0.9, { alpha: 0,x:-300, ease: Power2.easeOut, delay: twnDelay }); 157 twnDelay += 3.0;158 if (loops > 0) {159 loops -= 1;160 TweenMax.to($(".white_bg"), 0.3, { alpha: 1, ease: Power2.easeOut, delay: twnDelay });161 twnDelay += 0.1;162 TweenMax.to($(".white_bg"), 0.5, { alpha: 0, ease: Power2.easeOut, delay: twnDelay });163 TweenMax.delayedCall(twnDelay, function() {164 TweenMax.delayedCall(0, replay);165 });166 }167}
...
conditionaldelay_test.js
Source:conditionaldelay_test.js
1// Copyright 2008 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14goog.provide('goog.async.ConditionalDelayTest');15goog.setTestOnly('goog.async.ConditionalDelayTest');16goog.require('goog.async.ConditionalDelay');17goog.require('goog.testing.MockClock');18goog.require('goog.testing.jsunit');19var invoked = false;20var delay = null;21var clock = null;22var returnValue = true;23var onSuccessCalled = false;24var onFailureCalled = false;25function callback() {26 invoked = true;27 return returnValue;28}29function setUp() {30 clock = new goog.testing.MockClock(true);31 invoked = false;32 returnValue = true;33 onSuccessCalled = false;34 onFailureCalled = false;35 delay = new goog.async.ConditionalDelay(callback);36 delay.onSuccess = function() { onSuccessCalled = true; };37 delay.onFailure = function() { onFailureCalled = true; };38}39function tearDown() {40 clock.dispose();41 delay.dispose();42}43function testDelay() {44 delay.start(200, 200);45 assertFalse(invoked);46 clock.tick(100);47 assertFalse(invoked);48 clock.tick(100);49 assertTrue(invoked);50}51function testStop() {52 delay.start(200, 500);53 assertTrue(delay.isActive());54 clock.tick(100);55 assertFalse(invoked);56 delay.stop();57 clock.tick(100);58 assertFalse(invoked);59 assertFalse(delay.isActive());60}61function testIsActive() {62 assertFalse(delay.isActive());63 delay.start(200, 200);64 assertTrue(delay.isActive());65 clock.tick(200);66 assertFalse(delay.isActive());67}68function testRestart() {69 delay.start(200, 50000);70 clock.tick(100);71 delay.stop();72 assertFalse(invoked);73 delay.start(200, 50000);74 clock.tick(199);75 assertFalse(invoked);76 clock.tick(1);77 assertTrue(invoked);78 invoked = false;79 delay.start(200, 200);80 clock.tick(200);81 assertTrue(invoked);82 assertFalse(delay.isActive());83}84function testDispose() {85 delay.start(200, 200);86 delay.dispose();87 assertTrue(delay.isDisposed());88 clock.tick(500);89 assertFalse(invoked);90}91function testConditionalDelay_Success() {92 returnValue = false;93 delay.start(100, 300);94 clock.tick(99);95 assertFalse(invoked);96 clock.tick(1);97 assertTrue(invoked);98 assertTrue(delay.isActive());99 assertFalse(delay.isDone());100 assertFalse(onSuccessCalled);101 assertFalse(onFailureCalled);102 returnValue = true;103 invoked = false;104 clock.tick(100);105 assertTrue(invoked);106 assertFalse(delay.isActive());107 assertTrue(delay.isDone());108 assertTrue(onSuccessCalled);109 assertFalse(onFailureCalled);110 invoked = false;111 clock.tick(200);112 assertFalse(invoked);113}114function testConditionalDelay_Failure() {115 returnValue = false;116 delay.start(100, 300);117 clock.tick(99);118 assertFalse(invoked);119 clock.tick(1);120 assertTrue(invoked);121 assertTrue(delay.isActive());122 assertFalse(delay.isDone());123 assertFalse(onSuccessCalled);124 assertFalse(onFailureCalled);125 invoked = false;126 clock.tick(100);127 assertTrue(invoked);128 assertFalse(onSuccessCalled);129 assertFalse(onFailureCalled);130 invoked = false;131 clock.tick(90);132 assertFalse(invoked);133 clock.tick(10);134 assertTrue(invoked);135 assertFalse(delay.isActive());136 assertFalse(delay.isDone());137 assertFalse(onSuccessCalled);138 assertTrue(onFailureCalled);139}140function testInfiniteDelay() {141 returnValue = false;142 delay.start(100, -1);143 // Test in a big enough loop.144 for (var i = 0; i < 1000; ++i) {145 clock.tick(80);146 assertTrue(delay.isActive());147 assertFalse(delay.isDone());148 assertFalse(onSuccessCalled);149 assertFalse(onFailureCalled);150 }151 delay.stop();152 assertFalse(delay.isActive());153 assertFalse(delay.isDone());154 assertFalse(onSuccessCalled);155 assertFalse(onFailureCalled);156}157function testCallbackScope() {158 var callbackCalled = false;159 var scopeObject = {};160 function internalCallback() {161 assertEquals(this, scopeObject);162 callbackCalled = true;163 return true;164 }165 delay = new goog.async.ConditionalDelay(internalCallback, scopeObject);166 delay.start(200, 200);167 clock.tick(201);168 assertTrue(callbackCalled);...
delay.js
Source:delay.js
1// Copyright 2007 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14/**15 * @fileoverview Defines a class useful for handling functions that must be16 * invoked after a delay, especially when that delay is frequently restarted.17 * Examples include delaying before displaying a tooltip, menu hysteresis,18 * idle timers, etc.19*20 * @see ../demos/timers.html21 */22goog.provide('goog.Delay');23goog.provide('goog.async.Delay');24goog.require('goog.Disposable');25goog.require('goog.Timer');26/**27 * A Delay object invokes the associated function after a specified delay. The28 * interval duration can be specified once in the constructor, or can be defined29 * each time the delay is started. Calling start on an active delay will reset30 * the timer.31 *32 * @param {Function} listener Function to call when the delay completes.33 * @param {number=} opt_interval The default length of the invocation delay (in34 * milliseconds).35 * @param {Object=} opt_handler The object scope to invoke the function in.36 * @constructor37 * @extends {goog.Disposable}38 */39goog.async.Delay = function(listener, opt_interval, opt_handler) {40 /**41 * The function that will be invoked after a delay.42 * @type {Function}43 * @private44 */45 this.listener_ = listener;46 /**47 * The default amount of time to delay before invoking the callback.48 * @type {number}49 * @private50 */51 this.interval_ = opt_interval || 0;52 /**53 * The object context to invoke the callback in.54 * @type {Object|undefined}55 * @private56 */57 this.handler_ = opt_handler;58 /**59 * Cached callback function invoked when the delay finishes.60 * @type {Function}61 * @private62 */63 this.callback_ = goog.bind(this.doAction_, this);64};65goog.inherits(goog.async.Delay, goog.Disposable);66/**67 * A deprecated alias.68 * @deprecated Use goog.async.Delay instead.69 * @constructor70 */71goog.Delay = goog.async.Delay;72/**73 * Identifier of the active delay timeout, or 0 when inactive.74 * @type {number}75 * @private76 */77goog.async.Delay.prototype.id_ = 0;78/**79 * Disposes of the object, cancelling the timeout if it is still outstanding and80 * removing all object references.81 */82goog.async.Delay.prototype.disposeInternal = function() {83 goog.async.Delay.superClass_.disposeInternal.call(this);84 this.stop();85 delete this.listener_;86 delete this.handler_;87};88/**89 * Starts the delay timer. The provided listener function will be called after90 * the specified interval. Calling start on an active timer will reset the91 * delay interval.92 * @param {number=} opt_interval If specified, overrides the object's default93 * interval with this one (in milliseconds).94 */95goog.async.Delay.prototype.start = function(opt_interval) {96 this.stop();97 this.id_ = goog.Timer.callOnce(98 this.callback_,99 goog.isDef(opt_interval) ? opt_interval : this.interval_);100};101/**102 * Stops the delay timer if it is active. No action is taken if the timer is not103 * in use.104 */105goog.async.Delay.prototype.stop = function() {106 if (this.isActive()) {107 goog.Timer.clear(this.id_);108 }109 this.id_ = 0;110};111/**112 * Fires delay's action even if timer has already gone off or has not been113 * started yet; guarantees action firing. Stops the delay timer.114 */115goog.async.Delay.prototype.fire = function() {116 this.stop();117 this.doAction_();118};119/**120 * Fires delay's action only if timer is currently active. Stops the delay121 * timer.122 */123goog.async.Delay.prototype.fireIfActive = function() {124 if (this.isActive()) {125 this.fire();126 }127};128/**129 * @return {boolean} True if the delay is currently active, false otherwise.130 */131goog.async.Delay.prototype.isActive = function() {132 return this.id_ != 0;133};134/**135 * Invokes the callback function after the delay successfully completes.136 * @private137 */138goog.async.Delay.prototype.doAction_ = function() {139 this.id_ = 0;140 if (this.listener_) {141 this.listener_.call(this.handler_);142 }...
delaySettingsComponent.js
Source:delaySettingsComponent.js
...64 console.log("Random delayed enabled for " + this.divName + ", maxDelay is " + this.maxDelay + " sec");65 }66 67 console.log("Delay for " + this.divName + ", maxDelay is " + this.maxDelay + " sec");68 await this.delay(this.maxDelay * 1000);69 };70 71 _proto.resetDelay = function resetDelay() {72 clearTimeout(this.delayTimeout);73 this.resolveDelay();74 };75 76 _proto.delay = async function delay(ms) {77 var _this2 = this;78 79 return new Promise(function (resolve) {80 _this2.delayTimeout = setTimeout(resolve, ms);81 _this2.resolveDelay = resolve; // testing this extra resolve. Mabye will fix premature stop playing time issue82 });83 };84 85 return DelaySettings;...
classtorc_1_1generic_1_1PortDelay.js
Source:classtorc_1_1generic_1_1PortDelay.js
1var classtorc_1_1generic_1_1PortDelay =2[3 [ "Type", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#a45cb19496b2b5a502e6ff4fc105e9e24", [4 [ "eTypeDelay", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#a45cb19496b2b5a502e6ff4fc105e9e24aa6652c502f8e1f67fbc43d52c1eeb60f", null ],5 [ "eTypeLoadDelay", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#a45cb19496b2b5a502e6ff4fc105e9e24a578aebd3992b143d513c860bd4dbc459", null ]6 ] ],7 [ "PortDelay", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#ab99aef530d22fc0d9f71e853f4d95131", null ],8 [ "~PortDelay", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#a5edb1426eb490a911820f9460caf9d5b", null ],9 [ "PortDelay", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#afa150712a34ab20353ecb8cba7d36515", null ],10 [ "getAcLoad", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#ace26f23e9937daf056a82683fcdfa5af", null ],11 [ "getDelay", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#a19b1d258fe85df1354bf02df589d7981", null ],12 [ "getDerivation", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#afb89957a0ba41301aafa70d92fb3d003", null ],13 [ "getTransition", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#a78d3a3107a24e28425980d4fac7f25f3", null ],14 [ "getType", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#ad253db4f38a4039fe18d8ceed6e9b206", null ],15 [ "operator=", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#a0c461939892256ffe2772d5bf2289d0e", null ],16 [ "setAcLoad", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#abaf99c5e69b27289adf65c49745c684e", null ],17 [ "setDelay", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#ab33451b0f8567429b1447bb4fda24054", null ],18 [ "setDerivation", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#a52e76a5c176e2c9bf93f481a172f42d2", null ],19 [ "setTransition", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#a63e378668f70badc5cb074cdc45fa141", null ],20 [ "setType", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#a7b8ff0b308dbbf50974aebbb6be7ca56", null ],21 [ "mAcLoad", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#a756b2e1c3898bb84dc078fab5c4f5880", null ],22 [ "mDelay", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#af97a37198225e7b8bb75f08f013e7fd6", null ],23 [ "mDerivation", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#a1412cb51023ff901e12fd38d6d69b879", null ],24 [ "mTransition", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#a17de015b3b4a5079243e4861434b3f44", null ],25 [ "mType", "d6/d68/classtorc_1_1generic_1_1PortDelay.html#a7af0bd82d037ab01d624a863d9ed0a77", null ]...
classtorc_1_1generic_1_1PathDelay.js
Source:classtorc_1_1generic_1_1PathDelay.js
1var classtorc_1_1generic_1_1PathDelay =2[3 [ "Factory", "dd/d4b/classtorc_1_1generic_1_1PathDelay_1_1Factory.html", "dd/d4b/classtorc_1_1generic_1_1PathDelay_1_1Factory" ],4 [ "Pointer", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#aa542c6a420841f883b001bf0a3dae4ea", null ],5 [ "Type", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#ada56209702c7b3b537311ad9a8837712", null ],6 [ "WeakPointer", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#adfc2332b355880138234e8dbc94ef0dc", null ],7 [ "PathDelay", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#aaebd780e89f96955011dbbe689ad1721", null ],8 [ "~PathDelay", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#a8cf0a7d3becae5085dead5960cc2896e", null ],9 [ "PathDelay", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#a59be8601f6cbc68975b351ad7d370437", null ],10 [ "addEvent", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#a3b077fdb80d852799ce06ce4a4bcc295", null ],11 [ "getDelay", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#a4836fcdc25fd76aca979efecd658545f", null ],12 [ "getEvents", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#a78af1554af156b9fc293bbcd072552ac", null ],13 [ "getSharedThis", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#a0eaf75c752d45cd9a7c12dc87383838c", null ],14 [ "operator=", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#a3670e0d59ebeecc2dddda95f804ee084", null ],15 [ "setDelay", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#a3c721ff5e33e90ad0b253ed33ce9e18f", null ],16 [ "setEvents", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#ae8235ad0ac7620c37c3c055ebc53aa40", null ],17 [ "setWeakThis", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#ac9318ea3a2b0aaaff1bb44ea10b09260", null ],18 [ "FactoryType< PathDelay >", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#a2dfc5fae261bc6b0e4a1a3b70858861a", null ],19 [ "mDelay", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#ad7bed5488a5f26ae98b49a5a6a6634a7", null ],20 [ "mEvents", "d0/dbd/classtorc_1_1generic_1_1PathDelay.html#a8595109c508518670bcf704d183f2af1", null ]...
classtorc_1_1generic_1_1NetDelay.js
Source:classtorc_1_1generic_1_1NetDelay.js
1var classtorc_1_1generic_1_1NetDelay =2[3 [ "NetDelay", "d2/d20/classtorc_1_1generic_1_1NetDelay.html#ab7e8a196e317779cad0e1ca82d25761a", null ],4 [ "~NetDelay", "d2/d20/classtorc_1_1generic_1_1NetDelay.html#ac21bc3f0c8afafbbc685a00ce6de6929", null ],5 [ "NetDelay", "d2/d20/classtorc_1_1generic_1_1NetDelay.html#ad73904d5a52c85c8257c1cdbfd11e18c", null ],6 [ "getDelay", "d2/d20/classtorc_1_1generic_1_1NetDelay.html#aabe1b4ac939a0b6b6a4d30c6ab901c56", null ],7 [ "getDerivation", "d2/d20/classtorc_1_1generic_1_1NetDelay.html#acc1c7f3e2f506d8e8f077ae8486cb691", null ],8 [ "getTransition", "d2/d20/classtorc_1_1generic_1_1NetDelay.html#a258e426616a2224b36322a16fa9d5540", null ],9 [ "operator=", "d2/d20/classtorc_1_1generic_1_1NetDelay.html#aae42459b35e7729cc8904e0887f750da", null ],10 [ "setDelay", "d2/d20/classtorc_1_1generic_1_1NetDelay.html#a00434e111495d9553e283ed59723d1d8", null ],11 [ "setDerivation", "d2/d20/classtorc_1_1generic_1_1NetDelay.html#a53ad7532436e107d7420c8bb4108a40f", null ],12 [ "setTransition", "d2/d20/classtorc_1_1generic_1_1NetDelay.html#ad6794d009c6e870353c5c761aecb8407", null ],13 [ "mDelay", "d2/d20/classtorc_1_1generic_1_1NetDelay.html#aa1853f72d3c28e190c30bc2c6b68f26d", null ],14 [ "mDerivation", "d2/d20/classtorc_1_1generic_1_1NetDelay.html#aa712f1d1f96f3765eb67ac33b33c43b7", null ],15 [ "mTransition", "d2/d20/classtorc_1_1generic_1_1NetDelay.html#a86b94a7a153a2651a8c537330270779a", null ]...
Using AI Code Generation
1const fc = require("fast-check");2const delay = require("fast-check-monorepo");3fc.assert(4 fc.property(fc.integer(), async (n) => {5 await delay(n);6 return true;7 })8);
Using AI Code Generation
1function test3() {2 return fc.assert(3 fc.property(fc.integer(), fc.integer(), (a, b) => {4 fc.pre(a >= 0);5 fc.pre(b >= 0);6 return a + b === b + a;7 }),8 { verbose: true, endOnFailure: true }9 );10}11test3();12function test4() {13 return fc.assert(14 fc.property(fc.integer(), fc.integer(), (a, b) => {15 fc.pre(a >= 0);16 fc.pre(b >= 0);17 return a + b === b + a;18 }),19 { verbose: true, endOnFailure: true }20 );21}22test4();23function test5() {24 return fc.assert(25 fc.property(fc.integer(), fc.integer(), (a, b) => {26 fc.pre(a >= 0);27 fc.pre(b >= 0);28 return a + b === b + a;29 }),30 { verbose: true, endOnFailure: true }31 );32}33test5();34function test6() {35 return fc.assert(36 fc.property(fc.integer(), fc.integer(), (a, b) => {37 fc.pre(a >= 0);38 fc.pre(b >= 0);39 return a + b === b + a;40 }),41 { verbose: true, endOnFailure: true }42 );43}44test6();45function test7() {46 return fc.assert(47 fc.property(fc.integer(), fc.integer(), (a, b) => {48 fc.pre(a >= 0);49 fc.pre(b >= 0);50 return a + b === b + a;51 }),52 { verbose: true, endOnFailure: true }53 );54}55test7();56function test8() {57 return fc.assert(58 fc.property(fc.integer(), fc.integer(), (a, b) => {59 fc.pre(a >= 0);60 fc.pre(b
Using AI Code Generation
1const fc = require('fast-check');2fc.configureGlobal({ interruptAfterTimeLimit: 1000 });3const delay = require('@fast-check/delay');4fc.assert(5 fc.property(fc.integer(), fc.integer(), (a, b) => {6 return delay(1000).then(() => a + b === b + a);7 })8);
Using AI Code Generation
1const delay = require('fast-check/lib/check/arbitrary/DelayArbitrary').delay;2const fc = require('fast-check');3const { expect } = require('chai');4describe('test3', () => {5 it('should pass', async () => {6 await fc.assert(7 fc.asyncProperty(fc.integer(), async (n) => {8 await delay(500);9 expect(n).to.be.greaterThan(0);10 })11 );12 });13});14const delay = require('fast-check/lib/check/arbitrary/DelayArbitrary').delay;15const fc = require('fast-check');16const { expect } = require('chai');17describe('test4', () => {18 it('should pass', async () => {19 await fc.assert(20 fc.asyncProperty(fc.integer(), async (n) => {21 await delay(500);22 expect(n).to.be.greaterThan(0);23 })24 );25 });26});27const delay = require('fast-check/lib/check/arbitrary/DelayArbitrary').delay;28const fc = require('fast-check');29const { expect } = require('chai');30describe('test5', () => {31 it('should pass', async () => {32 await fc.assert(33 fc.asyncProperty(fc.integer(), async (n) => {34 await delay(500);35 expect(n).to.be.greaterThan(0);36 })37 );38 });39});40const delay = require('fast-check/lib/check/arbitrary/DelayArbitrary').delay;41const fc = require('fast-check');42const { expect } = require('chai');43describe('test6', () => {44 it('should pass', async () => {45 await fc.assert(46 fc.asyncProperty(fc.integer(), async (n) => {47 await delay(500);48 expect(n).to.be.greaterThan(0);49 })50 );51 });52});53const delay = require('fast-check/lib/check/arbitrary/DelayArbitrary').delay;54const fc = require('fast-check');55const { expect } = require('chai
Using AI Code Generation
1const fc = require('fast-check');2fc.assert(fc.property(fc.nat(), (n) => {3 fc.pre(n > 0);4 return n > 0;5}), { verbose: true, endOnFailure: true, seed: 0, path: 'test3.js' });6const fc = require('fast-check');7fc.assert(fc.property(fc.nat(), (n) => {8 fc.pre(n > 0);9 return n > 0;10}), { verbose: true, endOnFailure: true, seed: 0, path: 'test3.js' });11const fc = require('fast-check');12fc.assert(fc.property(fc.nat(), (n) => {13 fc.pre(n > 0);14 return n > 0;15}), { verbose: true, endOnFailure: true, seed: 0, path: 'test4.js' });16const fc = require('fast-check');17fc.assert(fc.property(fc.nat(), (n) => {18 fc.pre(n > 0);19 return n > 0;20}), { verbose: true, endOnFailure: true, seed: 0, path: 'test4.js' });21const fc = require('fast-check');22fc.assert(fc.property(fc.nat(), (n) => {23 fc.pre(n > 0);24 return n > 0;25}), { verbose: true, endOnFailure: true, seed: 0, path: 'test5.js' });26const fc = require('fast-check');27fc.assert(fc.property(fc.nat(), (n) => {28 fc.pre(n > 0);29 return n > 0;30}), { verbose: true, endOnFailure: true, seed: 0, path: 'test5.js' });31const fc = require('fast-check');32fc.assert(fc.property(fc.nat(), (n) => {
Using AI Code Generation
1const fc = require('fast-check');2const { delay } = require('fast-check/lib/utils/promise/PromiseUtils');3const { configureGlobal } = require('fast-check/lib/utils/ConfigureGlobal');4configureGlobal({ interruptAfterTimeLimit: 1000 });5const assert = require('assert');6describe('test3', () => {7 it('should pass', async () => {8 await fc.assert(9 fc.asyncProperty(fc.integer(), async (i) => {10 await delay(1000);11 assert(i >= 0);12 })13 );14 });15});
Using AI Code Generation
1const fc = require("fast-check");2const { delay } = require("fast-check/lib/test/arbitrary/AsyncArbitrary");3const { asyncProperty } = require("fast-check/lib/test/runner/AsyncProperty");4const myAsyncProperty = asyncProperty(5 fc.integer(),6 fc.integer(),7 async (a, b) => {8 await delay(1000);9 return a + b === b + a;10 }11);12fc.assert(myAsyncProperty);13const fc = require("fast-check");14const { delay } = require("fast-check/lib/test/arbitrary/AsyncArbitrary");15const { asyncProperty } = require("fast-check/lib/test/runner/AsyncProperty");16const myAsyncProperty = asyncProperty(17 fc.integer(),18 fc.integer(),19 async (a, b) => {20 await delay(1000);21 return a + b === b + a;22 }23);24fc.assert(myAsyncProperty);25const fc = require("fast-check");26const { delay } = require("fast-check/lib/test/arbitrary/AsyncArbitrary");27const { asyncProperty } = require("fast-check/lib/test/runner/AsyncProperty");28const myAsyncProperty = asyncProperty(29 fc.integer(),30 fc.integer(),31 async (a, b) => {32 await delay(1000);33 return a + b === b + a;34 }35);36fc.assert(myAsyncProperty);37const fc = require("fast-check");38const { delay } = require("fast-check/lib/test/arbitrary/AsyncArbitrary");39const { asyncProperty } = require("fast-check/lib/test/runner/AsyncProperty");40const myAsyncProperty = asyncProperty(41 fc.integer(),42 fc.integer(),43 async (a, b) => {44 await delay(1000);45 return a + b === b + a;46 }47);48fc.assert(myAsyncProperty);49const fc = require("fast-check");50const { delay } = require("fast-check/lib/test/arbitrary/AsyncArbitrary");51const { asyncProperty } = require("fast-check/lib/test
Using AI Code Generation
1const fc = require('fast-check');2const { delay } = require('fast-check-monorepo');3const myFunc = async () => {4 await delay(2000);5 return 'hello';6};7fc.assert(8 fc.asyncProperty(fc.integer(), async (n) => {9 const result = await myFunc();10 return result === 'hello';11 })12);13const fc = require('fast-check');14const { delay } = require('fast-check-monorepo');15const myFunc = async () => {16 await delay(2000);17 return 'hello';18};19fc.assert(20 fc.asyncProperty(fc.integer(), async (n) => {21 const result = await myFunc();22 return result === 'hello';23 })24);25const fc = require('fast-check');26const { delay } = require('fast-check-monorepo');27const myFunc = async () => {28 await delay(2000);29 return 'hello';30};31fc.assert(32 fc.asyncProperty(fc.integer(), async (n) => {33 const result = await myFunc();34 return result === 'hello';35 })36);37const fc = require('fast-check');38const { delay } = require('fast-check-monorepo');39const myFunc = async () => {40 await delay(2000);41 return 'hello';42};43fc.assert(44 fc.asyncProperty(fc.integer(), async (n) => {45 const result = await myFunc();46 return result === 'hello';47 })48);49const fc = require('fast-check');50const { delay } = require('fast-check-monorepo');51const myFunc = async () => {52 await delay(2000);53 return 'hello';54};55fc.assert(56 fc.asyncProperty(fc.integer(), async (n) => {
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!