Best JavaScript code snippet using qawolf
game_setup.js
Source:game_setup.js
...151 };152 // Turn on/off point feet (resets the game too).153 pointFeetCheckbox.oninput = function() {154 qwopGame.setPointFeet(pointFeetCheckbox.checked);155 resetRunner();156 };157 // Turn on/off torso angle stabilization controller.158 torsoAngleStabilizerCheckbox.oninput = function() {159 torsoAngleStabilization = torsoAngleStabilizerCheckbox.checked;160 torsoAngleStabilizerGainSlider.hidden = !torsoAngleStabilization;161 torsoStabilizerGainVal.hidden = !torsoAngleStabilization;162 torsoStabilizerGainVal.innerHTML = "Strength: " + torsoAngleStabilizerGainSlider.value;163 torsoAngleStabilizerK = torsoAngleStabilizerGainSlider.value * 100;164 torsoAngleStabilizerC = torsoAngleStabilizerGainSlider.value * 10;165 };166 torsoAngleStabilizerGainSlider.oninput = function() {167 torsoAngleStabilizerK = this.value * 100;168 torsoAngleStabilizerC = this.value * 10;169 torsoStabilizerGainVal.innerHTML = "Strength: " + this.value;170 };171 // Turn on/off torso angle stabilization controller.172 torsoVerticalStabilizerCheckbox.oninput = function() {173 torsoVerticalStabilization = torsoVerticalStabilizerCheckbox.checked;174 torsoVerticalStabilizerGainSlider.hidden = !torsoVerticalStabilization;175 torsoVertStabilizerGainVal.hidden = !torsoVerticalStabilization;176 torsoVertStabilizerGainVal.innerHTML = "Strength: " + torsoVerticalStabilizerGainSlider.value;177 torsoVerticalStabilizerK = torsoAngleStabilizerGainSlider.value * 0.6;178 torsoVerticalStabilizerC = torsoAngleStabilizerGainSlider.value * 0.06;179 };180 torsoVerticalStabilizerGainSlider.oninput = function() {181 torsoVerticalStabilizerK = this.value * 0.6;182 torsoVerticalStabilizerC = this.value * 0.06;183 torsoVertStabilizerGainVal.innerHTML = "Strength: " + this.value;184 };185 sequenceGoButton.onclick = function() {186 var sequenceStrArray = sequenceTextbox.value.split(',');187 actionQueue.clearAll();188 var currentKeyPos = 0;189 var keyOrder = [[false, false, false, false],190 [false, true, true, false], [false, false, false, false], [true, false, false, true]];191 resetRunner();192 for (let idx = 0; idx < sequenceStrArray.length; idx++) {193 actionQueue.addAction(new actions.Action(parseInt(sequenceStrArray[idx]),194 keyOrder[currentKeyPos][0],195 keyOrder[currentKeyPos][1],196 keyOrder[currentKeyPos][2],197 keyOrder[currentKeyPos][3]));198 currentKeyPos++;199 currentKeyPos %= 4;200 }201 };202 // QWOP and R reset key listeners.203 window.addEventListener('keydown', function(event) {204 switch (event.key) {205 case 'q':206 q = true;207 qbutton.style.borderStyle = "inset";208 break;209 case 'w':210 w = true;211 wbutton.style.borderStyle = "inset";212 break;213 case 'o':214 o = true;215 obutton.style.borderStyle = "inset";216 break;217 case 'p':218 p = true;219 pbutton.style.borderStyle = "inset";220 break;221 case 'r':222 resetbutton.style.borderStyle = "inset";223 resetRunner();224 break;225 }226 }, false);227 window.addEventListener('keyup', function(event) {228 switch (event.key) {229 case 'q':230 q = false;231 qbutton.style.borderStyle = "outset";232 break;233 case 'w':234 w = false;235 wbutton.style.borderStyle = "outset";236 break;237 case 'o':238 o = false;239 obutton.style.borderStyle = "outset";240 break;241 case 'p':242 p = false;243 pbutton.style.borderStyle = "outset";244 break;245 case 'r':246 resetbutton.style.borderStyle = "outset";247 break;248 }249 }, false);250 // Touch listeners for mobile.251 qbutton.addEventListener('touchstart', function(event) {252 q= true;253 qbutton.style.borderStyle = "inset";254 }, false);255 qbutton.addEventListener('touchend', function(event) {256 q= false;257 qbutton.style.borderStyle = "outset";258 }, false);259 wbutton.addEventListener('touchstart', function(event) {260 w= true;261 wbutton.style.borderStyle = "inset";262 }, false);263 wbutton.addEventListener('touchend', function(event) {264 w= false;265 wbutton.style.borderStyle = "outset";266 }, false);267 obutton.addEventListener('touchstart', function(event) {268 o= true;269 obutton.style.borderStyle = "inset";270 }, false);271 obutton.addEventListener('touchend', function(event) {272 o= false;273 obutton.style.borderStyle = "outset";274 }, false);275 pbutton.addEventListener('touchstart', function(event) {276 p= true;277 pbutton.style.borderStyle = "inset";278 }, false);279 pbutton.addEventListener('touchend', function(event) {280 p= false;281 pbutton.style.borderStyle = "outset";282 }, false);283 resetbutton.addEventListener('touchstart', function(event) {284 resetRunner();285 resetbutton.style.borderStyle = "inset";286 }, false);287 resetbutton.addEventListener('touchend', function(event) {288 resetbutton.style.borderStyle = "outset";289 }, false);290 resetbutton.addEventListener('mousedown', function(event) {291 resetRunner();292 resetbutton.style.borderStyle = "inset";293 }, false);294 resetbutton.addEventListener('mouseup', function(event) {295 resetbutton.style.borderStyle = "outset";296 }, false);297 setInterval(loop, frameDelay);298};...
index.test.ts
Source:index.test.ts
...32 test: 123,33}34describe('Throttle middleware', () => {35 beforeEach(() => {36 resetRunner();37 jest.restoreAllMocks();38 jest.resetAllMocks();39 jest.clearAllMocks();40 });41 describe('setup', () => {42 test('initial state should be empty object', () => {43 expect(getMiddlewareState()).toEqual({});44 });45 46 test('setup: empty config', () => {47 init({});48 49 expect(getMiddlewareState()).toEqual({});50 });51 52 test('setup: one action, empty config', () => {53 init({54 CUSTOM_ACTION: {55 ...defaultConfig,56 }57 });58 59 const state = getMiddlewareState().CUSTOM_ACTION;60 61 expect(state.counter).toEqual(0);62 expect(state.config).toEqual(defaultConfig);63 expect(state.data).toEqual({});64 expect(state.runner).toBeInstanceOf(Function);65 });66 test('setup: one action, full config (array)', () => {67 const configWithArrayType = { 68 ...customConfig, 69 [actionName]: {70 ...customConfig[actionName],71 defaultValue: [],72 } 73 }74 init(configWithArrayType);75 76 const state = getMiddlewareState().CUSTOM_ACTION;77 expect(state.counter).toEqual(0);78 expect(state.config).toEqual(configWithArrayType[actionName]);79 expect(state.data).toEqual([]);80 expect(state.runner).toBeInstanceOf(Function);81 });82 describe('createRunner', () => {83 test('object + logger', () => {84 resetRunner();85 init({86 ...customConfig,87 [actionName]: {88 ...customConfig[actionName],89 logger: true,90 }91 });92 const dispatch = jest.fn();93 // const runner = jest.spyOn(state, 'runner');94 const consoleFn = jest.spyOn(global.console, 'log').mockImplementation();95 // const state = getMiddlewareState()[actionName];96 const runner = createRunner(actionName, true, {});97 98 runner(dispatch);99 expect(dispatch.mock.calls.length).toBe(1);100 expect(consoleFn).toBeCalledTimes(1);101 expect(consoleFn).toHaveBeenCalledWith(`Batched ${actionName}: 0`, {});102 103 expect(dispatch.mock.calls[0][0]).toEqual({104 type: actionName,105 payload: {},106 meta: {107 isThrottled: true,108 },109 });110 const newState = getMiddlewareState()[actionName];111 expect(newState.counter).toBe(0);112 expect(newState.data).toEqual({});113 });114 test('array + no logger', () => {115 resetRunner();116 init({117 ...customConfig,118 [actionName]: {119 ...customConfig[actionName],120 logger: false,121 defaultValue: [],122 }123 });124 const testData = [1,2,3,5];125 const state = getMiddlewareState()[actionName];126 const dispatch = jest.fn();127 const consoleFn = jest.spyOn(global.console, 'log').mockImplementation();128 const runner = createRunner(actionName, false, []);129 state.data = testData;130 131 runner(dispatch);132 expect(dispatch.mock.calls.length).toBe(1);133 expect(consoleFn).toBeCalledTimes(0);134 135 expect(dispatch.mock.calls[0][0]).toEqual({136 type: actionName,137 payload: testData,138 meta: {139 isThrottled: true,140 },141 });142 const newState = getMiddlewareState()[actionName];143 expect(newState.counter).toBe(0);144 expect(newState.data).toEqual([]);145 });146 });147 describe('middleware', () => {148 beforeEach(() => {149 resetRunner();150 init(customConfig);151 });152 test('action: unknown action (not registered)', () => {153 const action = {154 type: 'TEST',155 payload: payloadObject,156 };157 158 const dispatch = jest.fn();159 const getState = jest.fn();160 const next = jest.fn();161 middleware({ dispatch, getState })(next)(action);162 expect(next.mock.calls.length).toBe(1);163 expect(next.mock.calls[0][0]).toEqual(action);164 });165 test('action: no merge', (done) => {166 const action = {167 ...baseAction,168 payload: payloadObject,169 };170 171 const dispatch = jest.fn();172 const getState = jest.fn();173 const next = jest.fn();174 middleware({ dispatch, getState })(next)(action);175 middleware({ dispatch, getState })(next)(action);176 middleware({ dispatch, getState })(next)(action);177 middleware({ dispatch, getState })(next)(action);178 const state = getMiddlewareState();179 expect(next.mock.calls.length).toBe(0);180 expect(state[actionName].counter).toBe(0);181 // wait for defered action182 setTimeout(() => {183 const state = getMiddlewareState();184 185 expect(state[actionName].counter).toBe(4);186 expect(state[actionName].data).toEqual(payloadObject);187 done();188 }, 50);189 });190 test('action: merge', (done) => {191 resetRunner();192 init({...customConfig, [actionName]: {193 ...customConfig[actionName],194 shouldMerge: true,195 }});196 const action = {197 ...baseAction,198 payload: payloadObject,199 };200 const payload2 = { a: 5555 };201 202 const dispatch = jest.fn();203 const getState = jest.fn();204 const next = jest.fn();205 middleware({ dispatch, getState })(next)({206 ...action, payload: payload2,207 });208 middleware({ dispatch, getState })(next)(action);209 const state = getMiddlewareState();210 expect(next.mock.calls.length).toBe(0);211 expect(state[actionName].counter).toBe(0);212 // wait for defered action213 setTimeout(() => {214 const state = getMiddlewareState();215 216 expect(state[actionName].counter).toBe(2);217 expect(state[actionName].data).toEqual({218 ...payloadObject, ...payload2,219 });220 done();221 }, 50);222 });223 test('action: merge array of primitive values', (done) => {224 resetRunner();225 expect(getMiddlewareState()).toEqual({});226 init({227 ...customConfig, 228 [actionName]: {229 ...customConfig[actionName],230 defaultValue: [],231 shouldMerge: true,232 }233 });234 const payload = [1,2,3,4];235 const payload2 = [3,4,5];236 237 const dispatch = jest.fn();238 const getState = jest.fn();239 const next = jest.fn();240 middleware({ dispatch, getState })(next)({241 ...baseAction, 242 payload: payload,243 });244 middleware({ dispatch, getState })(next)({245 ...baseAction, 246 payload: payload2,247 });248 const state = getMiddlewareState();249 expect(next.mock.calls.length).toBe(0);250 expect(state[actionName].counter).toBe(0);251 expect(state[actionName].data).toEqual([]);252 // wait for defered action253 setTimeout(() => {254 const state = getMiddlewareState();255 256 expect(state[actionName].counter).toBe(2);257 expect(state[actionName].data).toEqual([258 ...payload, ...payload2,259 ]);260 done();261 }, 50);262 });263 test('action: merge array of objects', (done) => {264 resetRunner();265 expect(getMiddlewareState()).toEqual({});266 init({267 ...customConfig, 268 [actionName]: {269 ...customConfig[actionName],270 defaultValue: [],271 shouldMerge: true,272 }273 });274 const payload = [{ a: 1, b: 2 }];275 const payload2 = [{ a: 5, b: 2 }];276 const payload3 = [{ c: 3 }];277 278 const dispatch = jest.fn();279 const getState = jest.fn();280 const next = jest.fn();281 middleware({ dispatch, getState })(next)({282 ...baseAction, 283 payload: payload,284 });285 middleware({ dispatch, getState })(next)({286 ...baseAction, 287 payload: payload2,288 });289 middleware({ dispatch, getState })(next)({290 ...baseAction, 291 payload: payload3,292 });293 const state = getMiddlewareState();294 expect(next.mock.calls.length).toBe(0);295 expect(state[actionName].counter).toBe(0);296 expect(state[actionName].data).toEqual([]);297 // wait for defered action298 setTimeout(() => {299 const state = getMiddlewareState();300 301 expect(state[actionName].counter).toBe(3);302 expect(state[actionName].data).toEqual([303 ...payload, ...payload2, ...payload3,304 ]);305 done();306 }, 50);307 });308 309 test('action: merge array of objects (replace by key)', (done) => {310 resetRunner();311 expect(getMiddlewareState()).toEqual({});312 init({313 ...customConfig, 314 [actionName]: {315 ...customConfig[actionName],316 defaultValue: [],317 shouldMerge: true,318 mergeByKey: 'id',319 }320 });321 const payload = [{ id: 11111, a: 1, b: 1 }];322 const payload2 = [{ id: 11111, a: 2, b: 2, c: 2 }];323 const payload3 = [{ id: 33333, a: 3, b: 3, c: 3 }];324 325 const dispatch = jest.fn();326 const getState = jest.fn();327 const next = jest.fn();328 middleware({ dispatch, getState })(next)({329 ...baseAction, 330 payload: payload,331 });332 middleware({ dispatch, getState })(next)({333 ...baseAction, 334 payload: payload2,335 });336 middleware({ dispatch, getState })(next)({337 ...baseAction, 338 payload: payload3,339 });340 const state = getMiddlewareState();341 expect(next.mock.calls.length).toBe(0);342 expect(state[actionName].counter).toBe(0);343 expect(state[actionName].data).toEqual([]);344 // wait for defered action345 setTimeout(() => {346 const state = getMiddlewareState();347 expect(state[actionName].counter).toBe(3);348 expect(state[actionName].data).toEqual([349 { id: 33333, a: 3, b: 3, c: 3 },350 { id: 11111, a: 2, b: 2, c: 2 },351 ]);352 done();353 }, 50);354 });355 test('shoul call next - batched action', (done) => {356 const dispatch = jest.fn();357 const getState = jest.fn();358 const next = jest.fn();359 middleware({ dispatch, getState })(next)({360 ...baseAction,361 meta: {362 isThrottled: true,363 }364 });365 const state = getMiddlewareState();366 expect(next.mock.calls.length).toBe(1);367 expect(state[actionName].counter).toBe(0);368 setTimeout(() => {369 expect(state[actionName].counter).toBe(0);370 expect(state[actionName].data).toEqual({});371 done();372 }, 50);373 }); 374 });375 });376 describe('reset state', () => {377 test('should reset state', () => {378 resetRunner();379 expect(getMiddlewareState()).toEqual({});380 });381 });...
3.贪吃蛇 插件版.js
Source:3.贪吃蛇 插件版.js
...6outer.innerHTML = `<div class="block-outer--board" ><div class="unit"></div></div><div class="toggle" onclick="unfold()"></div>`7document.body.appendChild(outer);8var snake = [20 + 2, 20 + 3, 20 + 4,], toDirection = 'right', direction = 'right', start = false, isUnfold = false, stop = false, board = document.getElementsByClassName("block-outer--board")[0], keyMap = { 119: 'up', 115: 'down', 97: 'left', 100: 'right' }, food = 130, gameRunner, speed = 100;9var eventMap = {10 43: () => { speed /= 1.1; resetRunner() }, 45: () => { speed *= 1.1; resetRunner() }, 32: () => (stop = !stop) ? (clearInterval(gameRunner) && (gameRunner = null)) : runGame()11};12function resetRunner() {13 clearInterval(gameRunner);14 gameRunner = null;15 runGame();16}17board.innerHTML = snake.reduce((res, item) => res + `<div class="unit" style="left:${(item - 1) % 20 * 20}px;top:${Math.floor((item - 1) / 20) * 20}px;"></div>`, '')// åå§å渲æ18document.onkeypress = e => {19 isUnfold // æ¯å¦å±å¼20 ?(start // æ¯å¦å¼å§21 ? (keyMap[e.keyCode] // æ¯å¦æ¯ä¸ä¸å·¦å³é® 22 ? (toDirection = keyMap[e.keyCode]) 23 : (eventMap[e.keyCode] // æ¯å¦å±äºäºä»¶é®24 ? eventMap[e.keyCode]() 25 : '')) 26 : init()) ...
Agent.js
Source:Agent.js
...41 this.position.add(this.downVel); 42 }43 this.diff.subVectors(this.position, this.target); 44 if (this.diff.length() < 0.01) {45 this.resetRunner(); 46 }47 }48 syncPosition() {49 SparkUtility.syncSceneObject(this.sceneObject, this.position);50 }51 resetRunner() {52 let length = this.tesseracts.length; 53 // Find a new random index, anything except the current index. 54 let randIdx = SparkUtility.random(0, length-1); 55 while (randIdx === this.idx) {56 randIdx = SparkUtility.random(0, length-1); 57 }58 // Choose the tesseract or plane as the starting position59 let t = this.tesseracts[randIdx];60 let p = this.planes[randIdx]; 61 let d = SparkUtility.random(0, 1); ; // 0 or 1 62 // Choose tesseract. 63 if (d === 0) {64 this.position = t.getPosition(); 65 this.target = p.getPosition(); ...
Using AI Code Generation
1const { resetRunner } = require("qawolf");2resetRunner();3const { create } = require("qawolf");4create();5const { launch } = require("qawolf");6launch();7const { click } = require("qawolf");8click();9const { type } = require("qawolf");10type();11const { press } = require("qawolf");12press();13const { select } = require("qawolf");14select();15const { waitFor } = require("qawolf");16waitFor();17const { waitForText } = require("qawolf");18waitForText();19const { waitForSelector } = require("qawolf");20waitForSelector();21const { waitForNavigation } = require("qawolf");22waitForNavigation();23const { waitForXPath } = require("qawolf");24waitForXPath();25const { waitForFunction } = require("qawolf");26waitForFunction();27const { waitForResponse } = require("qawolf");
Using AI Code Generation
1const { resetRunner } = require('qawolf');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 await resetRunner(context);7 await browser.close();8})();9const { resetRunner } = require('qawolf');10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch();13 const context = await browser.newContext();14 await resetRunner(context);15 await browser.close();16})();17const { resetRunner } = require('qawolf');18const { chromium } = require('playwright');19(async () => {20 const browser = await chromium.launch();21 const context = await browser.newContext();22 await resetRunner(context);23 await browser.close();24})();25const { resetRunner } = require('qawolf');26const { chromium } = require('playwright');27(async () => {28 const browser = await chromium.launch();29 const context = await browser.newContext();30 await resetRunner(context);31 await browser.close();32})();33const { resetRunner } = require('qawolf');34const { chromium } = require('playwright');35(async () => {36 const browser = await chromium.launch();37 const context = await browser.newContext();38 await resetRunner(context);39 await browser.close();40})();41const { resetRunner } = require('qawolf');42const { chromium } = require('playwright');43(async () => {44 const browser = await chromium.launch();45 const context = await browser.newContext();46 await resetRunner(context);47 await browser.close();48})();
Using AI Code Generation
1const { resetRunner } = require("qawolf");2resetRunner();3const { create } = require("qawolf");4const { create } = require("qawolf");5const { create } = require("qawolf");6const { create } = require("qawolf");7const { create } = require("qawolf");8const { create } = require("qawolf");9const { create } = require("qawolf");10const { create } = require("qawolf");11const { create } = require("qawolf");12const { create } = require("qawolf");13const { create } = require("qawolf");14const { create } = require("qawolf");15const { create } = require("qawolf");16const browser = await create({
Using AI Code Generation
1const { resetRunner } = require("qawolf");2resetRunner();3const { create } = require("qawolf");4const browser = await create();5const { launch } = require("qawolf");6const browser = await launch();7const { generate } = require("qawolf");8const browser = await generate();9const { register } = require("qawolf");10const browser = await register();11const { create } = require("qawolf");12const browser = await create();13const { launch } = require("qawolf");14const browser = await launch();15const { generate } = require("qawolf");16const browser = await generate();17const { register } = require("qawolf");18const browser = await register();19const { create } = require("qawolf");20const browser = await create();21const { launch } = require("qawolf");22const browser = await launch();23const { generate } = require("qawolf");24const browser = await generate();25const { register } = require("qawolf");26const browser = await register();27const { create } = require("qawolf");28const browser = await create();29const { launch } = require("qawolf");30const browser = await launch();31const { generate } = require("qawolf");32const browser = await generate();33const { register } = require("qawolf");34const browser = await register();35const { create } = require("qawolf");36const browser = await create();37const { launch } = require("qawolf");
Using AI Code Generation
1const { resetRunner } = require("qawolf");2resetRunner();3const browser = await launch({ headless: false });4const page = await browser.newPage();5await browser.close();6const { resetRunner } = require("qawolf");7resetRunner();8const browser = await launch({ headless: false });9const page = await browser.newPage();10await browser.close();11const { resetRunner } = require("qawolf");12resetRunner();13const browser = await launch({ headless: false });14const page = await browser.newPage();15await browser.close();16const { resetRunner } = require("qawolf");17resetRunner();18const browser = await launch({ headless: false });19const page = await browser.newPage();20await browser.close();21const { resetRunner } = require("qawolf");22resetRunner();23const browser = await launch({ headless: false });24const page = await browser.newPage();25await browser.close();26const { resetRunner } = require("qawolf");27resetRunner();28const browser = await launch({ headless: false });
Using AI Code Generation
1const { resetRunner } = require("qawolf");2resetRunner();3const { launch, browserType, devices } = require("qawolf");4const iPhone = devices["iPhone 11 Pro Max"];5test("test", async () => {6 const context = browser.context();7 const page = await browser.page();8 const element = await page.$("#tsf > div:nth-child(2) > div > div.RNNXgb > div > div.a4bIc > input");9 await element.type("hello");10 await page.click("#tsf > div:nth-child(2) > div > div.FPdoLc.VlcLAe > center > input[type='submit']:nth-child(1)");11 await page.waitForSelector(".LC20lb");12 await context.close();13 await browser.close();14});15const { resetRunner } = require("qawolf");16resetRunner();17const { launch, browserType, devices } = require("qawolf");18const iPhone = devices["iPhone 11 Pro Max"];19test("test", async () => {20 const context = browser.context();21 const page = await browser.page();22 const element = await page.$("#tsf > div:nth-child(2) > div > div.RNNXgb > div > div.a4bIc > input");23 await element.type("world");24 await page.click("#tsf > div:nth-child(2) > div > div.FPdoLc.VlcLAe > center > input[type='submit']:nth-child(1)");25 await page.waitForSelector(".LC20lb");26 await context.close();27 await browser.close();28});29const { resetRunner } = require("qawolf");30resetRunner();
Using AI Code Generation
1const { resetRunner } = require("qawolf");2resetRunner();3const { resetRunner } = require("qawolf");4resetRunner();5const { resetRunner } = require("qawolf");6resetRunner();7const { resetRunner } = require("qawolf");8resetRunner();9const { resetRunner } = require("qawolf");10resetRunner();11const { resetRunner } = require("qawolf");12resetRunner();13const { resetRunner } = require("qawolf");14resetRunner();15const { resetRunner } = require("qawolf");16resetRunner();17const { resetRunner } = require("qawolf");
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!!