Best JavaScript code snippet using playwright-internal
createActionExecutor.spec.js
Source:createActionExecutor.spec.js
1const expect = require('chai').expect2const sinon = require('sinon')3const Bluebird = require('bluebird')4const ActionStatus = require('../../src/constants').ActionStatus5const ImmediateResult = require('../../src/ImmediateResult')6const createActionExecutor = require('../../src/internal/createActionExecutor')7const ServiceActionNotFoundError = require('../../src/ServiceError/ServiceActionNotFoundError')8const waitTick = () => new Promise(resolve => setTimeout(resolve))9const waitTickBluebird = () => new Bluebird(resolve => setTimeout(resolve))10describe('core', () => {11 describe('createActionExecutor', () => {12 it('should throw error without required options', () => {13 expect(() => createActionExecutor({})).to.throw()14 expect(() => createActionExecutor({ createContext: () => ({}) })).to.throw()15 })16 it('should create a function', () => {17 const fn = createActionExecutor({18 createContext: () => ({}),19 execute: () => true20 })21 expect(typeof fn).to.equal('function')22 })23 it('should return a valid promise', async () => {24 const fn = createActionExecutor({25 createContext: () => ({}),26 execute: () => 'blabla'27 })28 const result = fn()29 expect(typeof result.then).to.equal('function')30 const resolvedResult = await result31 expect(resolvedResult).to.equal('blabla')32 })33 it('should pass execution data for context function', async () => {34 const createContext = sinon.fake.returns({})35 const fn = createActionExecutor({36 createContext: createContext,37 execute: () => true38 })39 await fn('some-name', { par: 'ams', papa: 'dams' }, { some: 'meta', data: null })40 expect(createContext.called).to.equal(true)41 expect(createContext.calledWith(42 'some-name',43 { par: 'ams', papa: 'dams' },44 { some: 'meta', data: null }45 )).to.equal(true)46 })47 it('should pass context to executor', async () => {48 const ctx = { a: 10, b: 20, c: 30 }49 const executor = sinon.fake.returns(true)50 const fn = createActionExecutor({51 createContext: () => ctx,52 execute: executor53 })54 await fn()55 expect(executor.called).to.equal(true)56 expect(executor.calledWith(ctx)).to.equal(true)57 })58 it('should pass context to each function down', async () => {59 const ctx = { a: 10, b: 20, c: 30 }60 const processor = sinon.fake.returns(null)61 const preExecutor = sinon.fake.returns(null)62 const executor = sinon.fake.returns(null)63 const finalizer = sinon.fake.returns(null)64 const resultProcessor = sinon.fake.returns(null)65 const fn = createActionExecutor({66 createContext: () => ctx,67 process: processor,68 preExecute: preExecutor,69 execute: executor,70 processResult: resultProcessor,71 finalizeContext: finalizer72 })73 await fn()74 expect(processor.called).to.equal(true)75 expect(processor.calledWith(ctx)).to.equal(true)76 expect(preExecutor.called).to.equal(true)77 expect(preExecutor.calledWith(ctx)).to.equal(true)78 expect(executor.called).to.equal(true)79 expect(executor.calledWith(ctx)).to.equal(true)80 expect(finalizer.called).to.equal(true)81 expect(finalizer.calledWith(ctx, null)).to.equal(true)82 expect(resultProcessor.called).to.equal(true)83 expect(resultProcessor.calledWith(null, ctx)).to.equal(true)84 })85 it('should properly execute function', async () => {86 const fn = createActionExecutor({87 createContext: (name, params) => ({ name, params }),88 execute: (ctx) => ctx.params.a + ctx.params.b89 })90 const result = await fn('bla', { a: 10, b: 20 })91 expect(result).to.equal(30)92 })93 it('should allow mutating context', async () => {94 const createContext = (name, params) => ({95 name: name,96 params: {97 a: params.a * 5,98 b: params.b * 599 }100 })101 const mutateContext = ctx => {102 ctx.params.a *= 2103 ctx.params.b *= 3104 }105 const fn = createActionExecutor({106 createContext: createContext,107 process: mutateContext,108 preExecute: mutateContext,109 execute: (ctx) => ctx.params.a + ctx.params.b110 })111 const result = await fn('bla', { a: 10, b: 20 })112 expect(result).to.equal(1100)113 })114 it('should allow processing result', async () => {115 const createContext = (name, params) => ({116 name: name,117 params: params118 })119 const fn = createActionExecutor({120 createContext: createContext,121 execute: (ctx) => ctx.params.a + ctx.params.b,122 processResult: (value, ctx) => `${value} ${ctx.name}`123 })124 const result = await fn('apples', { a: 10, b: 20 })125 expect(result).to.equal('30 apples')126 })127 it('should handle asynchronous paths', async () => {128 const createContext = (name, params) => ({129 name: name,130 params: params131 })132 const mutateContextAsynchronously = ctx => {133 return new Promise((resolve) => setTimeout(() => {134 ctx.params.a *= 2135 ctx.params.b *= 3136 resolve()137 }))138 }139 const fn = createActionExecutor({140 createContext: createContext,141 process: mutateContextAsynchronously,142 preExecute: mutateContextAsynchronously,143 execute: (ctx) => ctx.params.a + ctx.params.b144 })145 const result = await fn('bla', { a: 10, b: 20 })146 expect(result).to.equal(220)147 })148 it('should allow only selected methods', async () => {149 const isActionSupported = name => name === 'allowedName'150 const createContext = (name, params) => ({ name: name, params: params })151 const fn = createActionExecutor({152 isActionSupported: isActionSupported,153 createContext: createContext,154 execute: (ctx) => ctx.params.a + ctx.params.b155 })156 const success = sinon.fake()157 const failure = sinon.fake()158 await fn('bla', { a: 10, b: 20 })159 .then(success, failure)160 .catch(() => {})161 expect(success.called).to.equal(false)162 expect(failure.called).to.equal(true)163 expect(failure.lastArg instanceof ServiceActionNotFoundError).to.equal(true)164 const success2 = sinon.fake()165 const failure2 = sinon.fake()166 await fn('allowedName', { a: 10, b: 20 })167 .then(success2, failure2)168 .catch(() => {})169 expect(success2.called).to.equal(true)170 expect(failure2.called).to.equal(false)171 expect(success2.lastArg).to.equal(30)172 })173 it('should emit events on each step of action execution (success)', async () => {174 const context = { a: 10, b: 20 }175 const createContext = () => context176 const events = []177 const onActionStateChange = (state, context, value) => events.push({178 state: state,179 context: context,180 value: value181 })182 const fn = createActionExecutor({183 createContext: createContext,184 onActionStateChange: onActionStateChange,185 execute: (ctx) => ctx.a + ctx.b186 })187 await fn('bla')188 expect(events).to.deep.equal([189 { state: ActionStatus.CREATED, context: context, value: undefined },190 { state: ActionStatus.READY, context: context, value: undefined },191 { state: ActionStatus.EXECUTION, context: context, value: undefined },192 { state: ActionStatus.SUCCESS, context: context, value: 30 }193 ])194 })195 it('should emit events on each step of action execution (unknown action)', async () => {196 const context = { a: 10, b: 20 }197 const createContext = () => context198 const isActionSupported = name => name === 'allowedName'199 const events = []200 const onActionStateChange = (state, context, value) => events.push({201 state: state,202 context: context,203 value: value204 })205 const fn = createActionExecutor({206 isActionSupported: isActionSupported,207 createContext: createContext,208 onActionStateChange: onActionStateChange,209 execute: (ctx) => ctx.a + ctx.b210 })211 await fn('bla').catch(() => {})212 expect(events).to.deep.equal([213 { state: ActionStatus.CREATED, context: context, value: undefined },214 { state: ActionStatus.UNKNOWN, context: context, value: undefined }215 ])216 })217 it('should emit events on each step of action execution (failure)', async () => {218 const context = { a: 10, b: 20 }219 const createContext = () => context220 const events = []221 const onActionStateChange = (state, context, value) => events.push({222 state: state,223 context: context,224 value: value225 })226 const fn = createActionExecutor({227 createContext: createContext,228 onActionStateChange: onActionStateChange,229 execute: (ctx) => ctx.unknownProperty.a + ctx.b230 })231 await fn('bla').catch(() => {})232 expect(events.length).to.equal(4)233 expect(events[3].value instanceof TypeError).to.equal(true)234 expect(events).to.deep.equal([235 { state: ActionStatus.CREATED, context: context, value: undefined },236 { state: ActionStatus.READY, context: context, value: undefined },237 { state: ActionStatus.EXECUTION, context: context, value: undefined },238 { state: ActionStatus.ERROR, context: context, value: events[3].value }239 ])240 })241 it('should emit events on each step of action execution (faster failure)', async () => {242 const context = { a: 10, b: 20 }243 const createContext = () => context244 const events = []245 const onActionStateChange = (state, context, value) => events.push({246 state: state,247 context: context,248 value: value249 })250 const fn1 = createActionExecutor({251 createContext: createContext,252 onActionStateChange: onActionStateChange,253 process: (ctx) => ctx.unknownProperty.a + ctx.b,254 execute: (ctx) => ctx.a + ctx.b255 })256 await fn1('bla').catch(() => {})257 expect(events.length).to.equal(2)258 expect(events[1].value instanceof TypeError).to.equal(true)259 expect(events).to.deep.equal([260 { state: ActionStatus.CREATED, context: context, value: undefined },261 { state: ActionStatus.ERROR, context: context, value: events[1].value }262 ])263 const fn2 = createActionExecutor({264 createContext: createContext,265 onActionStateChange: onActionStateChange,266 preExecute: (ctx) => ctx.unknownProperty.a + ctx.b,267 execute: (ctx) => ctx.a + ctx.b268 })269 events.splice(0, events.length)270 await fn2('bla').catch(() => {})271 expect(events.length).to.equal(3)272 expect(events[2].value instanceof TypeError).to.equal(true)273 expect(events).to.deep.equal([274 { state: ActionStatus.CREATED, context: context, value: undefined },275 { state: ActionStatus.READY, context: context, value: undefined },276 { state: ActionStatus.ERROR, context: context, value: events[2].value }277 ])278 })279 it('should return result before action execution', async () => {280 const context = { a: 10, b: 20 }281 const createContext = () => context282 const events = []283 const onActionStateChange = (state, context, value) => events.push({284 state: state,285 context: context,286 value: value287 })288 const fn = createActionExecutor({289 createContext: createContext,290 onActionStateChange: onActionStateChange,291 process: () => { throw new ImmediateResult('something') },292 execute: (ctx) => ctx.a + ctx.b293 })294 const result1 = await fn('bla')295 expect(result1).to.equal('something')296 expect(events.length).to.equal(2)297 expect(events).to.deep.equal([298 { state: ActionStatus.CREATED, context: context, value: undefined },299 { state: ActionStatus.SUCCESS, context: context, value: 'something' }300 ])301 const asyncFn = createActionExecutor({302 createContext: createContext,303 onActionStateChange: onActionStateChange,304 preExecute: waitTick,305 process: () => { throw new ImmediateResult('something') },306 execute: (ctx) => ctx.a + ctx.b307 })308 events.splice(0, events.length)309 const result2 = await asyncFn('bla')310 expect(result2).to.equal('something')311 expect(events.length).to.equal(2)312 expect(events).to.deep.equal([313 { state: ActionStatus.CREATED, context: context, value: undefined },314 { state: ActionStatus.SUCCESS, context: context, value: 'something' }315 ])316 })317 it('should process immediate result', async () => {318 const context = { a: 10, b: 20 }319 const createContext = () => context320 const events = []321 const onActionStateChange = (state, context, value) => events.push({322 state: state,323 context: context,324 value: value325 })326 const fn = createActionExecutor({327 createContext: createContext,328 onActionStateChange: onActionStateChange,329 process: () => { throw new ImmediateResult('something') },330 processResult: (result) => `${result} there`,331 execute: (ctx) => ctx.a + ctx.b332 })333 const result = await fn('bla')334 expect(result).to.equal('something there')335 expect(events.length).to.equal(2)336 expect(events).to.deep.equal([337 { state: ActionStatus.CREATED, context: context, value: undefined },338 { state: ActionStatus.SUCCESS, context: context, value: 'something there' }339 ])340 })341 it('should choose proper Promise implementation', async () => {342 const context = { a: 10, b: 20 }343 const createContext = () => context344 const fn = createActionExecutor({345 Promise: Bluebird,346 createContext: createContext,347 processResult: (result) => `${result} there`,348 execute: (ctx) => ctx.a + ctx.b349 })350 const promise1 = fn('bla')351 await promise1352 expect(promise1 instanceof Bluebird).to.equal(true)353 const asyncFn = createActionExecutor({354 Promise: Bluebird,355 createContext: createContext,356 preExecute: waitTick,357 execute: (ctx) => ctx.a + ctx.b358 })359 const promise2 = asyncFn('bla')360 await promise2361 expect(promise2 instanceof Bluebird).to.equal(true)362 })363 it('could reuse Promise implementation sent inside', async () => {364 const context = { a: 10, b: 20 }365 const createContext = () => context366 const fn1 = createActionExecutor({367 ensurePromiseImplementation: false,368 Promise: Bluebird,369 preExecute: waitTick, // it will use native Promise370 createContext: createContext,371 execute: (ctx) => ctx.a + ctx.b372 })373 const promise1 = fn1('bla')374 await promise1375 expect(promise1 instanceof Promise).to.equal(true)376 const fn2 = createActionExecutor({377 ensurePromiseImplementation: false,378 Promise: Promise,379 preExecute: waitTickBluebird, // it will use Bluebird promises380 createContext: createContext,381 execute: (ctx) => ctx.a + ctx.b382 })383 const promise2 = fn2('bla')384 await promise2385 expect(promise2 instanceof Bluebird).to.equal(true)386 })387 it('should attach context to promise (success)', async () => {388 const context = { a: 10, b: 20 }389 const createContext = () => context390 const fn = createActionExecutor({391 createContext: createContext,392 execute: (ctx) => ctx.a + ctx.b393 })394 const promise = fn('bla')395 expect(promise.context).to.equal(context)396 await promise397 expect(promise.context).to.equal(context)398 })399 it('should not attach context to promise (success)', async () => {400 const context = { a: 10, b: 20 }401 const createContext = () => context402 const fn = createActionExecutor({403 includeContext: false,404 createContext: createContext,405 execute: (ctx) => ctx.a + ctx.b406 })407 const promise = fn('bla')408 expect(promise.context).to.equal(undefined)409 await promise410 expect(promise.context).to.equal(undefined)411 })412 it('should attach context to promise (unknown action)', async () => {413 const context = { a: 10, b: 20 }414 const createContext = () => context415 const isActionSupported = () => false416 const fn = createActionExecutor({417 isActionSupported: isActionSupported,418 createContext: createContext,419 execute: (ctx) => ctx.a + ctx.b420 })421 const promise = fn('bla')422 promise.catch(() => {})423 expect(promise.context).to.equal(context)424 await promise.catch(() => {})425 expect(promise.context).to.equal(context)426 })427 it('should not attach context to promise (unknown action)', async () => {428 const context = { a: 10, b: 20 }429 const createContext = () => context430 const isActionSupported = () => false431 const fn = createActionExecutor({432 includeContext: false,433 isActionSupported: isActionSupported,434 createContext: createContext,435 execute: (ctx) => ctx.a + ctx.b436 })437 const promise = fn('bla')438 promise.catch(() => {})439 expect(promise.context).to.equal(undefined)440 await promise.catch(() => {})441 expect(promise.context).to.equal(undefined)442 })443 it('should attach context to promise (failure)', async () => {444 const context = { a: 10, b: 20 }445 const createContext = () => context446 const fn = createActionExecutor({447 createContext: createContext,448 preExecute: () => { throw new Error() },449 execute: (ctx) => ctx.a + ctx.b450 })451 const promise = fn('bla')452 promise.catch(() => {})453 expect(promise.context).to.equal(context)454 await promise.catch(() => {})455 expect(promise.context).to.equal(context)456 })457 it('should not attach context to promise (failure)', async () => {458 const context = { a: 10, b: 20 }459 const createContext = () => context460 const fn = createActionExecutor({461 includeContext: false,462 createContext: createContext,463 preExecute: () => { throw new Error() },464 execute: (ctx) => ctx.a + ctx.b465 })466 const promise = fn('bla')467 promise.catch(() => {})468 expect(promise.context).to.equal(undefined)469 await promise.catch(() => {})470 expect(promise.context).to.equal(undefined)471 })472 it('should ignore uncaught error (within emitting events)', async () => {473 const context = { a: 10, b: 20 }474 const createContext = () => context475 const fn = createActionExecutor({476 includeContext: false,477 createContext: createContext,478 onActionStateChange: () => { throw new Error('Meh.') },479 execute: (ctx) => ctx.a + ctx.b480 })481 const result = await fn('bla')482 expect(result).to.equal(30)483 })484 it('should handle uncaught error (within emitting events)', async () => {485 const context = { a: 10, b: 20 }486 const createContext = () => context487 const onUncaughtError = sinon.fake()488 const fn = createActionExecutor({489 includeContext: false,490 createContext: createContext,491 onActionStateChange: () => { throw new Error('Meh.') },492 onUncaughtError: onUncaughtError,493 execute: (ctx) => ctx.a + ctx.b494 })495 const result = await fn('bla')496 expect(result).to.equal(30)497 expect(onUncaughtError.called).to.equal(true)498 expect(onUncaughtError.lastArg instanceof Error).to.equal(true)499 expect(onUncaughtError.lastArg.message).to.equal('Meh.')500 })501 })...
lisp.test.js
Source:lisp.test.js
...11 console.log.mockRestore();12});13describe('evaluateExpression', () => {14 it('evaluates atoms', () => {15 expect(evaluateExpression(1, createContext())).toBe(1);16 expect(evaluateExpression(-101, createContext())).toBe(-101);17 expect(evaluateExpression(123.456, createContext())).toBe(123.456);18 expect(evaluateExpression(true, createContext())).toBe(true);19 expect(evaluateExpression(null, createContext())).toBe(null);20 });21 it('adds two numbers together', () => {22 expect(evaluateExpression(['+', 1, 2], createContext())).toBe(3);23 expect(evaluateExpression(['+', 0, 0], createContext())).toBe(0);24 expect(evaluateExpression(['+', 2.5, 8.6], createContext())).toBe(11.1);25 expect(evaluateExpression(['+', 2, -6], createContext())).toBe(-4);26 });27 it('adds lists of numbers together', () => {28 expect(evaluateExpression(['+', 1, 2, 3, 4], createContext())).toBe(10);29 expect(evaluateExpression(['+', 5], createContext())).toBe(5);30 expect(31 evaluateExpression(32 ['+', 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1],33 createContext(),34 ),35 ).toBe(0);36 });37 it('subtracts numbers', () => {38 expect(evaluateExpression(['-', 10, 2], createContext())).toBe(8);39 expect(evaluateExpression(['-', 10, -2], createContext())).toBe(12);40 expect(evaluateExpression(['-', 10, 2, 3, 2], createContext())).toBe(3);41 });42 it('multiplies numbers', () => {43 expect(evaluateExpression(['*', 10, 2], createContext())).toBe(20);44 expect(evaluateExpression(['*', 10, -2], createContext())).toBe(-20);45 expect(evaluateExpression(['*', 10, 2, 2], createContext())).toBe(40);46 });47 it('divides numbers', () => {48 expect(evaluateExpression(['/', 10, 2], createContext())).toBe(5);49 expect(evaluateExpression(['/', 10, -2], createContext())).toBe(-5);50 expect(evaluateExpression(['/', 10, 2, 2], createContext())).toBe(2.5);51 });52 it('evaluates nested expressions', () => {53 expect(54 evaluateExpression(['+', ['+', 1, 2], ['+', 3, 4]], createContext()),55 ).toBe(10);56 expect(57 evaluateExpression(58 ['*', ['+', 1, 2, 3, 4], ['-', 10, 4]],59 createContext(),60 ),61 ).toBe(60);62 expect(63 evaluateExpression(64 ['*', ['+', 10, ['/', 100, 10]], ['-', ['+', 10, 5], 5]],65 createContext(),66 ),67 ).toBe(200);68 });69 describe('print', () => {70 it('calls console.log', () => {71 evaluateExpression(['print', 123], createContext());72 expect(console.log).toHaveBeenCalledTimes(1);73 expect(console.log).toHaveBeenLastCalledWith(123);74 });75 it('can be called with several arguments', () => {76 evaluateExpression(['print', 1, 2, 3], createContext());77 expect(console.log).toHaveBeenCalledTimes(1);78 expect(console.log).toHaveBeenLastCalledWith(1, 2, 3);79 });80 it('evaluates nested arguments', () => {81 evaluateExpression(['print', ['+', 5, ['*', 12, 5]]], createContext());82 expect(console.log).toHaveBeenCalledTimes(1);83 expect(console.log).toHaveBeenLastCalledWith(65);84 });85 it('returns undefined', () => {86 expect(evaluateExpression(['print', 0], createContext())).toBe(undefined);87 });88 });89 describe('if', () => {90 it('returns the correct branch based on a condition', () => {91 const expr1 = ['if', true, ['+', 0, 1], ['*', 10, 2]];92 expect(evaluateExpression(expr1, createContext())).toBe(1);93 const expr2 = ['if', false, ['+', 0, 1], ['*', 10, 2]];94 expect(evaluateExpression(expr2, createContext())).toBe(20);95 });96 it('evaluates the condition as an expression', () => {97 expect(98 evaluateExpression(['if', ['+', 1, 1], 1, 2], createContext()),99 ).toBe(1);100 expect(101 evaluateExpression(['if', ['+', 1, -1], 1, 2], createContext()),102 ).toBe(2);103 });104 it('only evaluates one branch', () => {105 evaluateExpression(106 ['if', true, ['print', 1], ['print', 2]],107 createContext(),108 );109 expect(console.log).toHaveBeenCalledTimes(1);110 expect(console.log).toHaveBeenLastCalledWith(1);111 evaluateExpression(112 ['if', false, ['print', 1], ['print', 2]],113 createContext(),114 );115 expect(console.log).toHaveBeenCalledTimes(2);116 expect(console.log).toHaveBeenLastCalledWith(2);117 });118 it('returns undefined if condition is not met with no else-branch', () => {119 expect(evaluateExpression(['if', false, 1], createContext())).toBe(120 undefined,121 );122 });123 });124});125describe('evaluateProgram', () => {126 it('evaluates a sequence of expressions', () => {127 evaluateProgram(128 [129 ['print', ['+', 2, 2]],130 ['if', true, ['print', 1], ['print', 2]],131 ['print', 123, 456, 789],132 ],133 createContext(),134 );135 expect(console.log.mock.calls).toEqual([[4], [1], [123, 456, 789]]);136 });137});138describe('createContext', () => {139 it('retrieves defined variables', () => {140 const context = createContext();141 context.define('x', 13);142 context.define('myAge', 25);143 expect(context.get('x')).toBe(13);144 expect(context.get('myAge')).toBe(25);145 });146 it('overwrites pre-defined variables', () => {147 const context = createContext();148 context.define('x', 13);149 expect(context.get('x')).toBe(13);150 context.define('x', 26);151 expect(context.get('x')).toBe(26);152 });153 it('throws an error when a variable is not defined', () => {154 const context = createContext();155 expect(() => context.get('x')).toThrowError('x is not defined');156 });...
contexts.js
Source:contexts.js
1import { createContext } from 'react'2//for app.js3export const BrightThemeContext = createContext(false)4export const FirstnameContext = createContext({ firstname: null, setFirstname: _ => {} })5export const UserIdContext = createContext(null)6export const IsAuthContext = createContext(false)7export const UnseenMsgsContext = createContext({ set: _ => {}, messages: 0 })8export const IncomingReqsContext = createContext({ set: _ => {}, requests: 0 })9export const LogoutHandlerContext = createContext(_ => {})10export const LoginHandlerContext = createContext(_ => {})11export const AcceptEmailContext = createContext(_ => {})12export const ToggleThemeContext = createContext(_ => {}) 13export const SignalContext = createContext(null)14export const SetTodoToDeleteContext = createContext(_ => {})15export const YourTodoContext = createContext(null)16export const CloseModalContext = createContext(_ => {})17export const SetNewTodoContext = createContext(_ => {})18export const TodoStatsContext = createContext({})19export const SetTodoToUpdateContext = createContext({})20export const TodoToUpdateContext = createContext({value : {}, unset: _ => {}})21export const OpenModalContext = createContext(_ => {})22export const PassTodoDataContext = createContext(_ => {})23export const TodoDataContext = createContext({})24export const UserDataContext = createContext({})25export const EditUserContext = createContext('')26export const SetEditUserContext = createContext({ value: '', set: _ => {} })27export const SetUpdatedUserContext = createContext(_ => {})28export const ViewUserStatsContext = createContext({ value: '', set: _ => {} })29export const SetItemToDeleteContext = createContext(_ => {})30export const DecreaseUserStatsContext = createContext(_ => {})31export const IncreaseUserStatsContext = createContext(_ => {})32export const UnfollowUserContext = createContext(_ => {})33export const SetBlockingUserContext = createContext(_ => {})34export const FollowControlsContext = createContext(null)35export const ConversationsContext = createContext({ convs: [], total: null })36export const LoadingContext = createContext(false)37export const PageContext = createContext({ page: 1, setPage: _ => {} })38export const HasNextPageContext = createContext({ has: false, set: _ => {} })39export const SetConvToDeleteContext = createContext(_ => {})40export const SetConvToEditContext = createContext(_ => {})41export const SetConvToAddContext = createContext(_ => {})42export const CurrentlyOpenedConvContext = createContext({ value: null, set: _ => {}})43export const QuitHandlerContext = createContext(_ => {})44export const ReceiverContext = createContext('')45export const SetMessageContext = createContext({})46export const SetMessageToEditLocallyContext = createContext({ value: null, set: _ => {} })47//export...
ContextFile.js
Source:ContextFile.js
1import { createContext } from "react";2export const UserLatContext = createContext();3export const UserLngContext = createContext();4export const FormRequestContext = createContext();5const UserContext = createContext();6export default UserContext;7export const AllRequestContext = createContext();8export const FirstNameContext = createContext();9export const UserIdContext = createContext();10export const RequestOwnerContext = createContext();11export const AllVolunteerContext = createContext();12export const RequestIdContext = createContext();13export const ReqOwnerFirstNameContext = createContext();14export const ChatContext = createContext();15export const AllMessagesContext = createContext();16export const AllRoomContext = createContext();17export const SelectedRoomContext = createContext();18export const SelectedChatContext = createContext();19export const SelectedReqDescContext = createContext();20export const SelectedRequestContext = createContext();21export const ChatRoomIdContext = createContext();22export const AllUserIdContext = createContext();23export const RequestOwnerIdContext = createContext();24export const CurrentRoomContext = createContext();25export const UserClickedRequest = createContext();26export const SameUserClickCount = createContext();27export const PannedMapContext = createContext()28export const RequestFormContext = createContext();29export const CurrentVolunteerContext = createContext();30export const DeactivateContext = createContext();31export const RepublishRequestContext = createContext();32export const RoomToRepublishContext = createContext()33export const RepublishingContext = createContext()34// for chat 35export const CurrentUserContext = createContext();36export const RoomDataContext = createContext();37export const HelperTextContext = createContext();...
contextObjects.js
Source:contextObjects.js
1import React from 'react'2// INITIALIZATION OF CONTEXT OBJECTS - FOR HEADERS3export const CurrentUser = React.createContext({});4export const LoginBarToggle = React.createContext('');5export const StoreIdContext = React.createContext('');6export const StoreAddressContext = React.createContext('');7export const StorePhoneContext = React.createContext('');8export const StoreHoursContext = React.createContext('');9export const StoreExchangePolicyContext = React.createContext('');10export const InstagramContext = React.createContext('');11// INITIALIZATION OF CONTEXT OBJECTS - FOR PRICES12export const ChildrensPriceContext = React.createContext('');13export const HardcoverPriceContext = React.createContext('');14export const SoftcoverPriceContext = React.createContext('');15export const AlbumsPriceContext = React.createContext('');16export const CdsPriceContext = React.createContext('');17export const DvdsPriceContext = React.createContext('');18export const SetsPriceContext = React.createContext('');...
index.js
Source:index.js
1import { createContext } from 'react';2export const AuthUserContext = createContext();3export const ContentContext = createContext();4export const CategoryContext = createContext();5export const FirebaseContext = createContext();6export const OptFormEmailContext = createContext();7export const ProfileContext = createContext();8export const ProfileListContext = createContext();9export const SetAuthUserContext = createContext();10export const SetCategoryContext = createContext();11export const SetContentContext = createContext();12export const SetOptFormEmailContext = createContext();13export const SetProfileContext = createContext();14export const SetProfileListContext = createContext();15export const SetTermContext = createContext();...
context.js
Source:context.js
1import React from 'react';2export const AuthContext = React.createContext();3// export const DataContext = React.createContext();4export const CommandContext = React.createContext();5export const ShowDataOpen = React.createContext();6export const DataStatusContext = React.createContext();7export const ImpContext = React.createContext();8export const BoundAddress = React.createContext();9export const Loading = React.createContext();10export const PairedDs = React.createContext();11export const FoundDs = React.createContext();12export const BleOpend = React.createContext();13export const Name = React.createContext();...
state.js
Source:state.js
1import { createContext } from "react";2export const DeleteFunc = createContext();3export const EditTask = createContext();4export const AddNewTask = createContext();5export const ArrForList = createContext();6export const NewInput = createContext();7export const NewUpdate = createContext();8export const NewDoneLine = createContext();9export const ContextImportant = createContext();10export const UpdateLine = createContext();11export const DoneOnly = createContext();12export const CansleObject = createContext();13export const ArrNew = createContext();...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: 'example.png' });7 await browser.close();8})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: 'example.png' });7 await browser.close();8})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await browser.close();7})();8const { chromium } = require('playwright');9(async () => {10 const browser = await chromium.launch();11 const context = await browser.newContext();12 const page = await context.newPage();13 await browser.close();14})();15const { chromium } = require('playwright');16(async () => {17 const browser = await chromium.launch();18 const context = await browser.newContext();19 const page = await context.newPage();20 await browser.close();21})();22const { chromium } = require('playwright');23(async () => {24 const browser = await chromium.launch();25 const context = await browser.newContext();26 const page = await context.newPage();27 await browser.close();28})();29const { chromium } = require('playwright');30(async () => {31 const browser = await chromium.launch();32 const context = await browser.newContext();33 const page = await context.newPage();34 await browser.close();35})();36const { chromium } = require('playwright');37(async () => {38 const browser = await chromium.launch();39 const context = await browser.newContext();40 const page = await context.newPage();41 await browser.close();42})();43const { chromium } = require('playwright');44(async () => {
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.screenshot({ path: 'example.png' });7 await browser.close();8})();9const { chromium } = require('playwright');10(async () => {11 const browser = await chromium.launch();12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.screenshot({ path: 'example.png' });15 await browser.close();16})();17const { chromium } = require('playwright');18(async () => {19 const browser = await chromium.launch();20 const server = await browser.newServer();21 const page = await browser.newPage();22 await page.goto(server.PREFIX + '/grid.html');23 await page.screenshot({ path: 'example.png' });24 await browser.close();25})();26const { chromium } = require('playwright');27(async () => {28 const browser = await chromium.launch();29 const page = await browser.newPage();30 await page.screenshot({ path: 'example.png' });31 await browser.close();32})();33const { chromium } = require('playwright');34(async () => {35 const browser = await chromium.launch();36 const page = await browser.newPage();37 await page.screenshot({ path: 'example.png' });38 await browser.close();39})();40const { chromium } = require('playwright');41(async () => {42 const browser = await chromium.launch();43 const page = await browser.newPage();
Using AI Code Generation
1const context = await browser.newContext({2});3const page = await context.newPage();4await page.click('text=Sign in');5await page.fill('input[name="identifier"]', 'testuser');6await page.click('text=Next');7await context.close();8await browser.close();
Using AI Code Generation
1const context = await browser.newContext({2 });3 const page = await context.newPage();4 await page.fill('input[name="q"]','playwright');5 await page.click('input[value="Google Search"]');6 await page.waitForSelector('text="Playwright"');7 await page.click('text="Playwright"');8 await page.waitForSelector('text="Playwright is a Node.js library to automate Chromium, Firefox and WebKit with a single API"');9 await page.screenshot({ path: `example.png` });10 await context.close();11 await browser.close();
Using AI Code Generation
1const { chromium } = require('playwright');2const { createPlaywright } = require('playwright-core/lib/server/createPlaywright');3const playwright = createPlaywright([chromium]);4(async () => {5 const browser = await playwright.chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.screenshot({ path: 'example.png' });9 await browser.close();10})();
Using AI Code Generation
1const {chromium} = require('playwright');2const context = await chromium.createContext();3const page = await context.newPage();4await page.screenshot({ path: 'example.png' });5await context.close();6const {chromium} = require('playwright');7const server = await chromium.launchServer({ port: 3000 });8await server.stop();9const {chromium} = require('playwright');10const context = await chromium.launchPersistentContext('/tmp/my-user-data-dir');11const page = await context.newPage();12await page.screenshot({ path: 'example.png' });13await context.close();14const {chromium} = require('playwright');15const browser = await chromium.launch();16const context = await browser.newContext();17const page = await context.newPage();18await page.screenshot({ path: 'example.png' });19await browser.close();20const {chromium} = require('playwright');21const browser = await chromium.connectOverCDP({22});23const context = await browser.newContext();24const page = await context.newPage();25await page.screenshot({ path: 'example.png' });26await browser.close();27const {chromium} = require('playwright');28const browser = await chromium.connect({29});30const context = await browser.newContext();31const page = await context.newPage();32await page.screenshot({ path: 'example.png' });
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!