How to use keep method in wpt

Best JavaScript code snippet using wpt

KeepAliveFacts.js

Source:KeepAliveFacts.js Github

copy

Full Screen

1QUnit.module("Transports Common - Keep Alive Facts");2QUnit.test("Monitor keep alive should initialize the lastKeepAlive flag.", function () {3 var connection = testUtilities.createHubConnection();4 // Ensure the connection can utilize the keep alive features5 connection.keepAliveData = {6 lastKeepAlive: false7 };8 $.signalR.transports._logic.monitorKeepAlive(connection);9 QUnit.ok(connection.keepAliveData.lastKeepAlive !== false, "Last keep alive should be set on the initialization of monitoring.");10 // Cleanup11 $.signalR.transports._logic.stopMonitoringKeepAlive(connection);12});13QUnit.test("Only starts monitoring keep alive if not already monitoring.", function () {14 var connection = testUtilities.createHubConnection();15 // Ensure the connection can utilize the keep alive features16 connection.keepAliveData = {17 lastKeepAlive: false18 };19 $.signalR.transports._logic.monitorKeepAlive(connection);20 // Reset the last keep alive to false so we can determine if we try and monitor it again21 connection.keepAliveData.lastKeepAlive = false;22 $.signalR.transports._logic.monitorKeepAlive(connection);23 QUnit.ok(connection.keepAliveData.lastKeepAlive === false, "Last keep alive should still be set to false because we should not have attempted to re-monitor the connection.");24 // Cleanup25 $.signalR.transports._logic.stopMonitoringKeepAlive(connection);26});27QUnit.test("Save updateKeepAlive binding so it can be unbound later.", function () {28 var connection = testUtilities.createHubConnection();29 // Ensure the connection can utilize the keep alive features30 connection.keepAliveData = {31 lastKeepAlive: false32 };33 QUnit.ok(!connection.keepAliveData.reconnectKeepAliveUpdate, "Binding does not exist prior to monitor");34 $.signalR.transports._logic.monitorKeepAlive(connection);35 // Reset the last keep alive to false so we can determine if our saved updateKeepAlive binding is saved36 connection.keepAliveData.lastKeepAlive = false37 QUnit.ok(connection.keepAliveData.reconnectKeepAliveUpdate, "Binding exists after monitor");38 connection.keepAliveData.reconnectKeepAliveUpdate();39 QUnit.ok(connection.keepAliveData.lastKeepAlive !== false, "Last keep alive should have changed due to the bound function executing.");40 // Cleanup41 $.signalR.transports._logic.stopMonitoringKeepAlive(connection);42});43QUnit.test("UpdateKeepAlive binding is triggered on reconnect", function () {44 var connection = testUtilities.createHubConnection();45 // Ensure the connection can utilize the keep alive features46 connection.keepAliveData = {47 lastKeepAlive: false48 };49 50 $.signalR.transports._logic.monitorKeepAlive(connection);51 // Reset the last keep alive to false so we can determine if our saved updateKeepAlive binding is executed on reconnect52 connection.keepAliveData.lastKeepAlive = false;53 $(connection).triggerHandler($.signalR.events.onReconnect);54 QUnit.ok(connection.keepAliveData.lastKeepAlive !== false, "Last keep alive should have changed due to the bound function executing from onReconnect.");55 // Cleanup56 $.signalR.transports._logic.stopMonitoringKeepAlive(connection);57});58QUnit.test("Stop monitoring handles monitoring flag appropriately.", function () {59 var connection = testUtilities.createHubConnection();60 // Ensure the connection can utilize the keep alive features61 connection.keepAliveData = {62 lastKeepAlive: false63 };64 $.signalR.transports._logic.stopMonitoringKeepAlive(connection);65 QUnit.isNotSet(connection.keepAliveData.monitoring, "The keep alive monitoring should still be unset, meaning stop did not trigger.");66 // Start monitoring so we can stop67 $.signalR.transports._logic.monitorKeepAlive(connection);68 QUnit.ok(connection.keepAliveData.monitoring === true, "Keep alive monitoring flag set to true after monitorKeepAlive.");69 $.signalR.transports._logic.stopMonitoringKeepAlive(connection);70 QUnit.isNotSet(connection.keepAliveData.monitoring, "Does not noop if monitor flag was enabled.");71});72QUnit.test("Stop monitoring unbinds reconnect flag.", function () {73 var connection = testUtilities.createHubConnection();74 // Ensure the connection can utilize the keep alive features75 connection.keepAliveData = {76 lastKeepAlive: false77 };78 $.signalR.transports._logic.monitorKeepAlive(connection);79 // Reset the last keep alive to false so we can determine if our saved updateKeepAlive binding is executed on reconnect80 connection.keepAliveData.lastKeepAlive = false;81 $(connection).triggerHandler($.signalR.events.onReconnect);82 QUnit.ok(connection.keepAliveData.lastKeepAlive !== false, "Last keep alive should have changed due to the bound function executing from onReconnect.");83 $.signalR.transports._logic.stopMonitoringKeepAlive(connection);84 QUnit.isNotSet(connection.keepAliveData.lastKeepAlive, "Last keep alive gets unset on stop monitoring of keep alive.");85 $(connection).triggerHandler($.signalR.events.onReconnect);86 QUnit.isNotSet(connection.keepAliveData.lastKeepAlive, "Last keep alive is still unset after triggering the reconnect event because it was unbound in stop monitoring.");87});88QUnit.test("Check if alive triggers OnConnectionSlow when keep out warning threshold is surpassed.", function () {89 var connection = testUtilities.createHubConnection(),90 savedUpdateKeepAlive = $.signalR.transports._logic.updateKeepAlive,91 failed = true;92 connection.connectionSlow(function () {93 failed = false;94 });95 // Null out the update Keep alive function so our junk "lastKeepAlive" is used96 $.signalR.transports._logic.updateKeepAlive = function () { };97 connection.keepAliveData = {98 timeoutWarning: 1000, // We should warn if the time difference between now and the last keep alive is greater than 1 second99 lastKeepAlive: new Date(new Date().valueOf() - 3000), // Set the last keep alive to 3 seconds ago100 timeout: 100000, // Large value so we don't timeout when we're looking for slow101 userNotified: false102 };103 connection.state = $.signalR.connectionState.connected;104 // Start monitoring keep alive again105 $.signalR.transports._logic.monitorKeepAlive(connection);106 QUnit.ok(!failed, "ConnectionSlow triggered on checkIfAlive (via monitorKeepAlive) if we breach the warn threshold."); 107 // Cleanup108 $.signalR.transports._logic.updateKeepAlive = savedUpdateKeepAlive;109 $.signalR.transports._logic.stopMonitoringKeepAlive(connection); 110});111QUnit.test("Check if alive detects transport timeout when keep out warning threshold is surpassed.", function () {112 var connection = testUtilities.createHubConnection(),113 savedUpdateKeepAlive = $.signalR.transports._logic.updateKeepAlive,114 keepAliveTimeout = 10000,115 failed = true;116 connection.connectionSlow(function () {117 failed = false;118 });119 // Null out the update Keep alive function so our junk "lastKeepAlive" is used120 $.signalR.transports._logic.updateKeepAlive = function () { };121 connection.keepAliveData = {122 timeoutWarning: 1000, // We should warn if the time difference between now and the last keep alive is greater than 1 second123 lastKeepAlive: new Date(new Date().valueOf() - 2 * keepAliveTimeout), // Set the last keep alive to 2x the timeout to ensure we timeout124 timeout: keepAliveTimeout, 125 userNotified: false126 };127 connection.transport = {};128 connection.transport.lostConnection = function () {129 failed = false;130 };131 connection.state = $.signalR.connectionState.connected;132 // Start monitoring keep alive again133 $.signalR.transports._logic.monitorKeepAlive(connection);134 // Set the last keep alive to a value that should trigger a timeout 135 QUnit.ok(!failed, "Lost Connection called on checkIfAlive (via monitorKeepAlive) if we breach the timeout threshold.");136 // Cleanup137 $.signalR.transports._logic.updateKeepAlive = savedUpdateKeepAlive;138 $.signalR.transports._logic.stopMonitoringKeepAlive(connection);...

Full Screen

Full Screen

function-toString-parentheses.js

Source:function-toString-parentheses.js Github

copy

Full Screen

1description(2"This test checks that parentheses are preserved when significant, and not added where inappropriate. " +3"We need this test because the JavaScriptCore parser removes all parentheses and the serializer then adds them back."4);5function compileAndSerialize(expression)6{7 var f = eval("(function () { return " + expression + "; })");8 var serializedString = f.toString();9 serializedString = serializedString.replace(/[ \t\r\n]+/g, " ");10 serializedString = serializedString.replace("function () { return ", "");11 serializedString = serializedString.replace("; }", "");12 return serializedString;13}14function compileAndSerializeLeftmostTest(expression)15{16 var f = eval("(function () { " + expression + "; })");17 var serializedString = f.toString();18 serializedString = serializedString.replace(/[ \t\r\n]+/g, " ");19 serializedString = serializedString.replace("function () { ", "");20 serializedString = serializedString.replace("; }", "");21 return serializedString;22}23var removesExtraParentheses = compileAndSerialize("(a + b) + c") == "a + b + c";24function testKeepParentheses(expression)25{26 shouldBe("compileAndSerialize('" + expression + "')",27 "'" + expression + "'");28}29function testOptionalParentheses(expression)30{31 stripped_expression = removesExtraParentheses32 ? expression.replace(/\(/g, '').replace(/\)/g, '')33 : expression;34 shouldBe("compileAndSerialize('" + expression + "')",35 "'" + stripped_expression + "'");36}37function testLeftAssociativeSame(opA, opB)38{39 testKeepParentheses("a " + opA + " b " + opB + " c");40 testOptionalParentheses("(a " + opA + " b) " + opB + " c");41 testKeepParentheses("a " + opA + " (b " + opB + " c)");42}43function testRightAssociativeSame(opA, opB)44{45 testKeepParentheses("a " + opA + " b " + opB + " c");46 testKeepParentheses("(a " + opA + " b) " + opB + " c");47 testOptionalParentheses("a " + opA + " (b " + opB + " c)");48}49function testHigherFirst(opHigher, opLower)50{51 testKeepParentheses("a " + opHigher + " b " + opLower + " c");52 testOptionalParentheses("(a " + opHigher + " b) " + opLower + " c");53 testKeepParentheses("a " + opHigher + " (b " + opLower + " c)");54}55function testLowerFirst(opLower, opHigher)56{57 testKeepParentheses("a " + opLower + " b " + opHigher + " c");58 testKeepParentheses("(a " + opLower + " b) " + opHigher + " c");59 testOptionalParentheses("a " + opLower + " (b " + opHigher + " c)");60}61var binaryOperators = [62 [ "*", "/", "%" ], [ "+", "-" ],63 [ "<<", ">>", ">>>" ],64 [ "<", ">", "<=", ">=", "instanceof", "in" ],65 [ "==", "!=", "===", "!==" ],66 [ "&" ], [ "^" ], [ "|" ],67 [ "&&" ], [ "||" ]68];69for (i = 0; i < binaryOperators.length; ++i) {70 var ops = binaryOperators[i];71 for (j = 0; j < ops.length; ++j) {72 var op = ops[j];73 testLeftAssociativeSame(op, op);74 if (j != 0)75 testLeftAssociativeSame(ops[0], op);76 if (i < binaryOperators.length - 1) {77 var nextOps = binaryOperators[i + 1];78 if (j == 0)79 for (k = 0; k < nextOps.length; ++k)80 testHigherFirst(op, nextOps[k]);81 else82 testHigherFirst(op, nextOps[0]);83 }84 }85}86var assignmentOperators = [ "=", "*=", "/=" , "%=", "+=", "-=", "<<=", ">>=", ">>>=", "&=", "^=", "|=" ];87for (i = 0; i < assignmentOperators.length; ++i) {88 var op = assignmentOperators[i];89 testRightAssociativeSame(op, op);90 if (i != 0)91 testRightAssociativeSame("=", op);92 testLowerFirst(op, "+");93 shouldThrow("compileAndSerialize('a + b " + op + " c')");94 testKeepParentheses("(a + b) " + op + " c");95 testKeepParentheses("a + (b " + op + " c)");96}97var prefixOperators = [ "delete", "void", "typeof", "++", "--", "+", "-", "~", "!" ];98var prefixOperatorSpace = [ " ", " ", " ", "", "", " ", " ", "", "" ];99for (i = 0; i < prefixOperators.length; ++i) {100 var op = prefixOperators[i] + prefixOperatorSpace[i];101 testKeepParentheses("" + op + "a + b");102 testOptionalParentheses("(" + op + "a) + b");103 testKeepParentheses("" + op + "(a + b)");104 testKeepParentheses("!" + op + "a");105 testOptionalParentheses("!(" + op + "a)");106}107testKeepParentheses("!a++");108testOptionalParentheses("!(a++)");109testKeepParentheses("(!a)++");110testKeepParentheses("!a--");111testOptionalParentheses("!(a--)");112testKeepParentheses("(!a)--");113testKeepParentheses("(-1)[a]");114testKeepParentheses("(-1)[a] = b");115testKeepParentheses("(-1)[a] += b");116testKeepParentheses("(-1)[a]++");117testKeepParentheses("++(-1)[a]");118testKeepParentheses("(-1)[a]()");119testKeepParentheses("new (-1)()");120testKeepParentheses("(-1).a");121testKeepParentheses("(-1).a = b");122testKeepParentheses("(-1).a += b");123testKeepParentheses("(-1).a++");124testKeepParentheses("++(-1).a");125testKeepParentheses("(-1).a()");126testKeepParentheses("(- 0)[a]");127testKeepParentheses("(- 0)[a] = b");128testKeepParentheses("(- 0)[a] += b");129testKeepParentheses("(- 0)[a]++");130testKeepParentheses("++(- 0)[a]");131testKeepParentheses("(- 0)[a]()");132testKeepParentheses("new (- 0)()");133testKeepParentheses("(- 0).a");134testKeepParentheses("(- 0).a = b");135testKeepParentheses("(- 0).a += b");136testKeepParentheses("(- 0).a++");137testKeepParentheses("++(- 0).a");138testKeepParentheses("(- 0).a()");139testOptionalParentheses("(1)[a]");140testOptionalParentheses("(1)[a] = b");141testOptionalParentheses("(1)[a] += b");142testOptionalParentheses("(1)[a]++");143testOptionalParentheses("++(1)[a]");144shouldBe("compileAndSerialize('(1)[a]()')",145 removesExtraParentheses ? "'1[a]()'" : "'(1)[a]()'");146shouldBe("compileAndSerialize('new (1)()')",147 removesExtraParentheses ? "'new 1()'" : "'new (1)()'");148testKeepParentheses("(1).a");149testKeepParentheses("(1).a = b");150testKeepParentheses("(1).a += b");151testKeepParentheses("(1).a++");152testKeepParentheses("++(1).a");153testKeepParentheses("(1).a()");154for (i = 0; i < assignmentOperators.length; ++i) {155 var op = assignmentOperators[i];156 testKeepParentheses("(-1) " + op + " a");157 testKeepParentheses("(- 0) " + op + " a");158 testKeepParentheses("1 " + op + " a");159}160shouldBe("compileAndSerializeLeftmostTest('({ }).x')", "'({ }).x'");161shouldBe("compileAndSerializeLeftmostTest('x = { }')", "'x = { }'");162shouldBe("compileAndSerializeLeftmostTest('(function () { })()')", "'(function () { })()'");163shouldBe("compileAndSerializeLeftmostTest('x = function () { }')", "'x = function () { }'");164shouldBe("compileAndSerializeLeftmostTest('var a')", "'var a'");165shouldBe("compileAndSerializeLeftmostTest('var a = 1')", "'var a = 1'");166shouldBe("compileAndSerializeLeftmostTest('var a, b')", "'var a, b'");167shouldBe("compileAndSerializeLeftmostTest('var a = 1, b = 2')", "'var a = 1, b = 2'");168shouldBe("compileAndSerializeLeftmostTest('var a, b, c')", "'var a, b, c'");169shouldBe("compileAndSerializeLeftmostTest('var a = 1, b = 2, c = 3')", "'var a = 1, b = 2, c = 3'");170shouldBe("compileAndSerializeLeftmostTest('const a = 1')", "'const a = 1'");171shouldBe("compileAndSerializeLeftmostTest('const a = (1, 2)')", "'const a = (1, 2)'");172shouldBe("compileAndSerializeLeftmostTest('const a, b = 1')", "'const a, b = 1'");173shouldBe("compileAndSerializeLeftmostTest('const a = 1, b')", "'const a = 1, b'");174shouldBe("compileAndSerializeLeftmostTest('const a = 1, b = 1')", "'const a = 1, b = 1'");175shouldBe("compileAndSerializeLeftmostTest('const a = (1, 2), b = 1')", "'const a = (1, 2), b = 1'");176shouldBe("compileAndSerializeLeftmostTest('const a = 1, b = (1, 2)')", "'const a = 1, b = (1, 2)'");177shouldBe("compileAndSerializeLeftmostTest('const a = (1, 2), b = (1, 2)')", "'const a = (1, 2), b = (1, 2)'");178shouldBe("compileAndSerialize('(function () { new (a.b()).c })')", "'(function () { new (a.b()).c })'");...

Full Screen

Full Screen

main.js

Source:main.js Github

copy

Full Screen

1/* global KEEP */2window.addEventListener('DOMContentLoaded', () => {3 KEEP.themeInfo = {4 theme: `Keep v${KEEP.theme_config.version}`,5 author: 'XPoet',6 repository: 'https://github.com/XPoet/hexo-theme-keep'7 }8 KEEP.localStorageKey = 'KEEP-THEME-STATUS';9 KEEP.styleStatus = {10 isExpandPageWidth: false,11 isDark: false,12 fontSizeLevel: 0,13 isOpenPageAside: true14 }15 // print theme base info16 KEEP.printThemeInfo = () => {17 console.log(`\n %c ${KEEP.themeInfo.theme} %c ${KEEP.themeInfo.repository} \n`, `color: #fadfa3; background: #333; padding: 5px 0;`, `background: #fadfa3; padding: 5px 0;`);18 }19 // set styleStatus to localStorage20 KEEP.setStyleStatus = () => {21 localStorage.setItem(KEEP.localStorageKey, JSON.stringify(KEEP.styleStatus));22 }23 // get styleStatus from localStorage24 KEEP.getStyleStatus = () => {25 let temp = localStorage.getItem(KEEP.localStorageKey);26 if (temp) {27 temp = JSON.parse(temp);28 for (let key in KEEP.styleStatus) {29 KEEP.styleStatus[key] = temp[key];30 }31 return temp;32 } else {33 return null;34 }35 }36 KEEP.refresh = () => {37 KEEP.initUtils();38 KEEP.initHeaderShrink();39 KEEP.initModeToggle();40 KEEP.initBack2Top();41 if (KEEP.theme_config.local_search.enable === true) {42 KEEP.initLocalSearch();43 }44 if (KEEP.theme_config.code_copy.enable === true) {45 KEEP.initCodeCopy();46 }47 if (KEEP.theme_config.lazyload.enable === true) {48 KEEP.initLazyLoad();49 }50 }51 KEEP.printThemeInfo();52 KEEP.refresh();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('webpagetest');2const test = wpt('API_KEY');3}, (err, data) => {4 if (err) {5 return console.error(err);6 }7 console.log(data);8});9const wpt = require('webpagetest');10const test = wpt('API_KEY');11}, (err, data) => {12 if (err) {13 return console.error(err);14 }15 console.log(data);16});17const wpt = require('webpagetest');18const test = wpt('API_KEY');19}, (err, data) => {20 if (err) {21 return console.error(err);22 }23 console.log(data);24});25const wpt = require('webpagetest');26const test = wpt('API_KEY');27}, (err, data) => {28 if (err) {29 return console.error(err);30 }31 console.log(data);32});33const wpt = require('webpagetest');34const test = wpt('API_KEY');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = wpt('www.webpagetest.org');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('webpagetest');10var test = wpt('www.webpagetest.org');11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('webpagetest');18var test = wpt('www.webpagetest.org');19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wpt = require('webpagetest');26var test = wpt('www.webpagetest.org');27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wpt = require('webpagetest');34var test = wpt('www.webpagetest.org');35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('webpagetest');42var test = wpt('www.webpagetest.org');43 if (err) {44 console.log(err);45 } else {46 console.log(data);47 }48});

Full Screen

Using AI Code Generation

copy

Full Screen

1 console.log(data);2});3{ statusCode: 200,4 data: { statusCode: 200, statusText: 'OK', data: 'OK' } }5{ statusCode: 200,6 data: { statusCode: 200, statusText: 'OK', data: 'OK' } }7{ statusCode: 200,8 data: { statusCode: 200, statusText: 'OK', data: 'OK' } }9{ statusCode: 200,10 data: { statusCode: 200, statusText: 'OK', data: 'OK' } }11{ statusCode: 200,12 data: { statusCode: 200, statusText: 'OK', data: 'OK' } }13{ statusCode: 200,14 data: { statusCode: 200, statusText

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Run wpt automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful