How to use onData method in Playwright Internal

Best JavaScript code snippet using playwright-internal

net.spec.js

Source:net.spec.js Github

copy

Full Screen

...166 it("update(testData) -> local:testData", function()167 {168 var dp = makeDocProxy();169 var onData = jasmine.createSpy('onData');170 remoteMock.read = function(onData, e) { onData(getTestData()); };171 remoteMock.update = function(d, c, e) {};172 173 dp.read();174 dp.onData(onData);175 dp.update(getTestData());176 177 verifyStorage("mine", getTestData());178 expect(onData).not.toHaveBeenCalled(); 179 });180 181 it("update(testData), remote conflict(modifiedData) -> modifiedData, local:modifiedData", function()182 {183 var m = makeModel();184 m.updatePaymentValue([999,999], 1, 1);185 186 var dp = makeDocProxy();187 var onData = jasmine.createSpy('onData');188 remoteMock.read = function(onData, e) { onData(getTestData()); };189 var updateCalls = 0;190 remoteMock.update = function(d, success, conflict, e) { (updateCalls++ == 0) ? conflict(localData) : success(); };191 192 dp.read();193 dp.onData(onData);194 dp.update(getTestData());195 196 verifyStorage("mine", localData);197 expect(onData).toHaveBeenCalledWith(jasmine.objectContaining(localData));198 });199 200 it("(MERGE) update(modifiedData1), remote conflict(modifiedData2) -> merge, local:merge", function()201 {202 var m = makeModel();203 m.addRow();204 m.updatePaymentText("local row", 3);205 var modifiedData1 = localData;206 207 m = makeModel();208 m.updatePaymentValue([999, 999], 1, 1);209 m.addRow();210 m.updatePaymentText("server row", 3);211 var modifiedData2 = localData;212 m = makeModel();213 m.updatePaymentValue([999, 999], 1, 1);214 m.addRow();215 m.addRow();216 m.updatePaymentText("server row", 3);217 m.updatePaymentText("local row", 4);218 var merged = localData;219 220 var dp = makeDocProxy();221 var onData = jasmine.createSpy('onData');222 remoteMock.read = function(onData, e) { onData(getTestData()); };223 dp.read();224 225 var updateCalls = 0;226 remoteMock.read = function(onData, e) { onData(modifiedData2); }; // Needed?227 remoteMock.update = function(d, success, conflict, e) { 228 (updateCalls++ == 0) ? conflict(modifiedData2) : success(); 229 };230 231 dp.onData(onData);232 dp.update(modifiedData1);233 234 verifyStorage("mine", merged);235 expect(onData).toHaveBeenCalledWith(jasmine.objectContaining(merged));236 });237 238 // TODO: some local changes should be accepted!239 it("local:testData, update(modifiedData), remote error -> testData, local:testData", function()240 {241 var m = makeModel();242 243 var dp = makeDocProxy();244 remoteMock.read = function(onData, e) { onData(getTestData()); };245 remoteMock.update = function(d, s, c, error) { error(); };246 247 // Arrange to get local:testData248 dp.read(); 249 verifyStorage("mine", getTestData());250 251 // Make some modification, write to 'localData' variable252 m.updatePaymentValue([999, 999], 1, 1);253 254 var onData = jasmine.createSpy('onData');255 dp.onData(onData);256 dp.update(localData);257 258 verifyStorage("mine", getTestData());259 expect(onData).toHaveBeenCalledWith(jasmine.objectContaining(getTestData()));260 });261 262 it("local:testData, update(extendedData), remote error -> extendedData, local:extendedData", function()263 {264 var m = makeModel();265 m.addRow();266 m.updatePaymentText("mama", 3);267 268 var dp = makeDocProxy();269 remoteMock.read = function(onData, e) { onData(getTestData()); };270 remoteMock.update = function(d, s, c, error) { error(); };271 272 var onData = jasmine.createSpy('onData');273 dp.read(); 274 dp.onData(onData);275 dp.update(localData);276 277 verifyStorage("mine", localData);278 expect(onData).not.toHaveBeenCalled();279 });280 281 it("offline: an unacceptable change to rollback to last acceptable data", function()282 {283 var m = makeModel();284 m.addRow();285 m.updatePaymentText("mama", 3);286 287 var dp = makeDocProxy();288 remoteMock.read = function(onData, e) { onData(getTestData()); };289 remoteMock.update = function(d, s, c, error) { error(); };290 var onData = jasmine.createSpy('onData');291 292 // Read gets testData293 dp.read(); 294 dp.onData(onData); 295 // try to update localData (with "mama" payment) but fail due to offline296 dp.update(localData);297 var acceptedData = localData;298 299 // local changes in mine storage300 verifyStorage("mine", acceptedData);301 expect(onData).not.toHaveBeenCalled();302 303 m = makeModel();304 m.addRow();305 m.updatePaymentText("mama", 3);306 m.updatePaymentValue([999, 999], 1, 1);307 dp.update(localData);308 309 verifyStorage("mine", acceptedData);310 expect(onData).toHaveBeenCalledWith(jasmine.objectContaining(acceptedData));311 });312 });313 314 describe("read function", function() 315 {316 it("local:null, remote:error -> fatal error", function()317 {318 var dp = makeDocProxy();319 remoteMock.read = function(a,onError) { onError(); };320 321 var onData = jasmine.createSpy('onData');322 dp.onData(onData);323 dp.read();324 325 expect(onData).not.toHaveBeenCalled();326 expect(errorHandler.info).not.toHaveBeenCalled();327 expect(errorHandler.fatal).toHaveBeenCalled();328 });329 330 it("local:null, remote:42 -> 42", function()331 {332 var dp = makeDocProxy();333 remoteMock.read = function(onData,a) { onData(42); };334 335 var onData = jasmine.createSpy('onData');336 dp.onData(onData);337 dp.read();338 339 expect(onData).toHaveBeenCalledWith(42);340 expect(onData.calls.count()).toBe(1);341 expect(errorHandler.info).not.toHaveBeenCalled();342 expect(errorHandler.fatal).not.toHaveBeenCalled();343 });344 345 it("local:42, remote:error -> 42", function()346 {347 var dp = makeDocProxy();348 setStorage("mine", 42);349 setStorage("theirs", 42);350 remoteMock.read = function(a,onError) { onError(); };351 352 var handler = jasmine.createSpy('h');353 dp.onData(handler);354 dp.read();355 356 expect(handler).toHaveBeenCalledWith(42);357 expect(handler.calls.count()).toBe(1);358 expect(errorHandler.info).not.toHaveBeenCalled(); // should be called by net code though359 expect(errorHandler.fatal).not.toHaveBeenCalled();360 });361 362 it("local:testData, remote:modifiedData -> testData and then modifiedData", function()363 {364 var m = makeModel();365 m.addRow();366 m.updatePaymentText("mama", 3);367 368 var dp = makeDocProxy();369 370 setStorage("mine", getTestData());371 setStorage("theirs", getTestData());372 remoteMock.read = function(onData,a) { onData(localData); };373 374 var handler = jasmine.createSpy('h');375 dp.onData(handler);376 dp.read();377 378 expect(handler.calls.argsFor(0)[0]).toEqual(jasmine.objectContaining(getTestData()));379 expect(handler.calls.argsFor(1)[0]).toEqual(jasmine.objectContaining(localData));380 expect(handler.calls.count()).toBe(2);381 expect(errorHandler.info).not.toHaveBeenCalled();382 expect(errorHandler.fatal).not.toHaveBeenCalled();383 });384 385 it("local:testData, remote:testData -> testData only once", function()386 {387 var dp = makeDocProxy();388 setStorage("mine", getTestData());389 remoteMock.read = function(onData,a) { onData(getTestData()); };390 391 var handler = jasmine.createSpy('h');392 dp.onData(handler);393 dp.read();394 395 expect(handler.calls.mostRecent().args[0]).toEqual(jasmine.objectContaining(getTestData()));396 expect(handler.calls.count()).toBe(1);397 expect(errorHandler.info).not.toHaveBeenCalled(); 398 expect(errorHandler.fatal).not.toHaveBeenCalled();399 });400 401 it("offline, local:null -> fatal error", function()402 {403 var dp = makeDocProxy(); 404 online(false);405 var handler = jasmine.createSpy('h');406 remoteMock.read = function(onData,a) { onData(42); }; // should not matter407 408 dp.read(handler);409 410 expect(handler).not.toHaveBeenCalled();411 expect(errorHandler.info).not.toHaveBeenCalled(); 412 expect(errorHandler.fatal).toHaveBeenCalled();413 });414 415 it("merges data (no server change)", function()416 {417 var m = makeModel();418 m.addRow();419 m.updatePaymentText("mama", 3);420 421 var dp = makeDocProxy();422 remoteMock.read = function(onData,a) { onData(getTestData()); };423 424 dp.read();425 426 // Some local offline changes427 online(false);428 setStorage("mine", localData);429 430 var handler = jasmine.createSpy('h');431 dp.onData(handler);432 433 // Reconnect and merge (trivially)434 online(true);435 dp.read();436 437 verifyStorage("mine", localData);438 expect(handler.calls.count()).toBe(1);439 expect(handler).toHaveBeenCalledWith(jasmine.objectContaining(localData));440 });441 442 it("merges data (with server change)", function()443 {444 var m = makeModel();445 m.addRow();446 m.updatePaymentText("mama", 3);447 448 var dp = makeDocProxy();449 remoteMock.read = function(onData,a) { onData(getTestData()); };450 451 dp.read();452 453 // Some local offline changes454 online(false);455 setStorage("mine", localData);456 457 var handler = jasmine.createSpy('h');458 dp.onData(handler);459 460 // server changes461 var m2 = makeModel();462 m2.addRow();463 m2.updatePaymentText("mama-server", 3);464 remoteMock.read = function(onData,a) { onData(localData); };465 466 // Reconnect and merge (trivially)467 online(true);468 dp.read();469 470 // expected merged data471 var m3 = makeModel();472 m3.addRow();473 m3.addRow();474 m3.updatePaymentText("mama-server", 3);475 m3.updatePaymentText("mama", 4);476 477 verifyStorage("mine", localData);478 expect(handler.calls.count()).toBe(1);...

Full Screen

Full Screen

generateEnvFile.js

Source:generateEnvFile.js Github

copy

Full Screen

1const fs = require('fs')2const stdin = process.openStdin();3function token({env = "mode=development\n", envVals = []}) {4 return new Promise(resolve => {5 console.log("\x1b[32m%s\x1b[0m", 'Ingresa el token del bot:')6 const onData = (data) => {7 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')8 stdin.removeListener('data', onData)9 return resolve({10 env: `${env}token=${data || envVals.find(i=>i.prop === 'token')?.value || ''}\n`,11 envVals12 })13 }14 stdin.addListener('data',onData)15 })16}17function lang({env, envVals = []}) {18 return new Promise(resolve => {19 console.log("\x1b[32m%s\x1b[0m", 'Escoge un lenguaje:')20 console.log('1 - Es (default)')21 console.log('2 - En')22 const onData = (data) => {23 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')24 stdin.removeListener('data', onData)25 if (['2', 'en', 'en_us'].includes(data.toLowerCase())) return resolve({26 env: `${env}lang=en_US\n`,27 envVals28 })29 return resolve({30 env: `${env}lang=${envVals.find(i=>i.prop === 'lang')?.value || 'es_ES'}\n`,31 envVals32 })33 }34 stdin.addListener('data',onData)35 })36}37function prefix({env, envVals = []}) {38 return new Promise(resolve => {39 console.log("\x1b[32m%s\x1b[0m",'Establece un prefijo por defecto:')40 console.log('! (por default)')41 const onData = (data) => {42 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')43 stdin.removeListener('data', onData)44 if (data.length > 0) return resolve({45 env: `${env}prefix=${data}\n`,46 envVals47 })48 return resolve({49 env: `${env}prefix=${envVals.find(i=>i.prop === 'prefix')?.value || '!'}\n`,50 envVals51 })52 }53 stdin.addListener('data',onData)54 })55}56function botId({env, envVals = []}) {57 return new Promise(resolve => {58 console.log("\x1b[32m%s\x1b[0m",'Ingresa el id del bot:')59 const onData = (data) => {60 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')61 stdin.removeListener('data', onData)62 return resolve({63 env: `${env}botID=${data || envVals.find(i=>i.prop === 'botID')?.value || ''}\n`,64 envVals65 })66 }67 stdin.addListener('data',onData)68 })69}70function mongoURL({env, envVals = []}) {71 return new Promise(resolve => {72 console.log("\x1b[32m%s\x1b[0m",'Ingresa la URL de tu MongoDB:')73 const onData = (data) => {74 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')75 stdin.removeListener('data', onData)76 return resolve({77 env: `${env}MONGO_URL=${data || envVals.find(i=>i.prop === 'MONGO_URL')?.value || ''}\n`,78 envVals79 })80 }81 stdin.addListener('data',onData)82 })83}84function embedColor({env, envVals = []}) {85 return new Promise(resolve => {86 console.log("\x1b[32m%s\x1b[0m",'Establece un color preferido para los embeds:')87 const onData = (data) => {88 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')89 stdin.removeListener('data', onData)90 return resolve({91 env: `${env}EMBED_COLOR=${data || envVals.find(i=>i.prop === 'EMBED_COLOR')?.value || ''}\n`,92 envVals93 })94 }95 stdin.addListener('data',onData)96 })97}98function errorWebhookID({env, envVals = []}) {99 return new Promise(resolve => {100 console.log("\x1b[32m%s\x1b[0m",'Ingresa el ID del WebHook de errores:')101 const onData = (data) => {102 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')103 stdin.removeListener('data', onData)104 return resolve({105 env: `${env}errorWebhookID=${data || envVals.find(i=>i.prop === 'errorWebhookID')?.value || ''}\n`,106 envVals107 })108 }109 stdin.addListener('data',onData)110 })111}112function errorWebhookToken({env, envVals = []}) {113 return new Promise(resolve => {114 console.log("\x1b[32m%s\x1b[0m",'Ingresa el token del WebHook de errores:')115 const onData = (data) => {116 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')117 stdin.removeListener('data', onData)118 return resolve({119 env: `${env}errorWebhookToken=${data || envVals.find(i=>i.prop === 'errorWebhookToken')?.value || ''}\n`,120 envVals121 })122 }123 stdin.addListener('data',onData)124 })125}126function errorChannel({env, envVals = []}) {127 return new Promise(resolve => {128 console.log("\x1b[32m%s\x1b[0m",'Ingresa el ID del canal de errores:')129 const onData = (data) => {130 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')131 stdin.removeListener('data', onData)132 return resolve({133 env: `${env}errorChannel=${data || envVals.find(i=>i.prop === 'errorChannel')?.value || ''}\n`,134 envVals135 })136 }137 stdin.addListener('data',onData)138 })139}140function topggToken({env, envVals = []}) {141 return new Promise(resolve => {142 console.log("\x1b[32m%s\x1b[0m",'Ingresa tu token de topGG:')143 const onData = (data) => {144 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')145 stdin.removeListener('data', onData)146 return resolve({147 env: `${env}topggToken=${data || envVals.find(i=>i.prop === 'topggToken')?.value || ''}\n`,148 envVals149 })150 }151 stdin.addListener('data',onData)152 })153}154function clientIDSpotify({env, envVals = []}) {155 return new Promise(resolve => {156 console.log("\x1b[32m%s\x1b[0m",'Ingresa el ID del cliente de Spotify:')157 const onData = (data) => {158 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')159 stdin.removeListener('data', onData)160 return resolve({161 env: `${env}clientIDSpotify=${data || envVals.find(i=>i.prop === 'clientIDSpotify')?.value || ''}\n`,162 envVals163 })164 }165 stdin.addListener('data',onData)166 })167}168function clientSecretSpotify({env, envVals = []}) {169 return new Promise(resolve => {170 console.log("\x1b[32m%s\x1b[0m",'Ingresa el token del cliente de Spotify:')171 const onData = (data) => {172 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')173 stdin.removeListener('data', onData)174 return resolve({175 env: `${env}clientSecretSpotify=${data || envVals.find(i=>i.prop === 'clientSecretSpotify')?.value || ''}\n`,176 envVals177 })178 }179 stdin.addListener('data',onData)180 })181}182function guildAddWebhookID({env, envVals = []}) {183 return new Promise(resolve => {184 console.log("\x1b[32m%s\x1b[0m",'Ingresa el ID del webhook donde se enviarán las notificaciones para nuevos servidores:')185 const onData = (data) => {186 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')187 stdin.removeListener('data', onData)188 return resolve({189 env: `${env}guildAddWebhookID=${data || envVals.find(i=>i.prop === 'guildAddWebhookID')?.value || ''}\n`,190 envVals191 })192 }193 stdin.addListener('data',onData)194 })195}196function guildAddWebhookToken({env, envVals = []}) {197 return new Promise(resolve => {198 console.log("\x1b[32m%s\x1b[0m",'Ingresa el token del webhook donde se enviarán las notificaciones para nuevos servidores:')199 const onData = (data) => {200 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')201 stdin.removeListener('data', onData)202 return resolve({203 env: `${env}guildAddWebhookToken=${data || envVals.find(i=>i.prop === 'guildAddWebhookToken')?.value || ''}\n`,204 envVals205 })206 }207 stdin.addListener('data',onData)208 })209}210function OsuSecret({env, envVals = []}) {211 return new Promise(resolve => {212 console.log("\x1b[32m%s\x1b[0m",'Ingresa la clave API para OSU:')213 const onData = (data) => {214 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')215 stdin.removeListener('data', onData)216 return resolve({217 env: `${env}OsuSecret=${data || envVals.find(i=>i.prop === 'OsuSecret')?.value || ''}\n`,218 envVals219 })220 }221 stdin.addListener('data',onData)222 })223}224function trnAPIKey({env, envVals = []}) {225 return new Promise(resolve => {226 console.log("\x1b[32m%s\x1b[0m",'Ingresa la clave API para TRN (comando de fnprofile):')227 const onData = (data) => {228 data = data.toString().replaceAll('\n', '').replaceAll('\r', '')229 stdin.removeListener('data', onData)230 return resolve({231 env: `${env}trnAPIKey=${data || envVals.find(i=>i.prop === 'trnAPIKey')?.value || ''}\n`,232 envVals233 })234 }235 stdin.addListener('data',onData)236 })237}238fs.readFile('./.env', (err, data) => {239 if (err && err.code !== 'ENOENT') return console.log(err)240 const envVals = (data ?? '').toString().split('\n').filter(Boolean).map(i => ({241 prop: i.split('=')[0],242 value: i.split('=')[1]243 }))244 token({envVals}).then(lang).then(prefix).then(botId).then(mongoURL).then(embedColor)245 .then(errorWebhookID).then(errorWebhookToken).then(errorChannel).then(topggToken)246 .then(clientIDSpotify).then(clientSecretSpotify).then(guildAddWebhookID)247 .then(guildAddWebhookToken).then(OsuSecret).then(trnAPIKey).then(({env}) => {248 fs.writeFile('./.env', env, (err) => {249 if(err) return console.error(err)250 console.log("\x1b[35m%s\x1b[0m",'.env creado')251 console.log("\x1b[31m%s\x1b[0m", 'Importante:')252 console.log("\x1b[33mEl .env es un fichero privado,\nno lo compartas ni subas a ningun repositorio\x1b[0m");253 process.exit(0)254 })255 })...

Full Screen

Full Screen

checker.js

Source:checker.js Github

copy

Full Screen

...29 start(onData, onChild) {30 const c = this[kState].first;31 this[kOnData] = onData;32 this[kOnChild] = onChild;33 return (c !== undefined && onData) ? onData(c) : c;34 }35 /**36 * Close the checker37 */38 _close() {39 this[kOnData] = undefined;40 this[kOnChild] = undefined;41 const state = this[kState];42 state.context.checker = state.parent;43 state.parent = undefined;44 state.done = true;45 }46 /**47 * Abstract check...

Full Screen

Full Screen

LineSplitStream.test.js

Source:LineSplitStream.test.js Github

copy

Full Screen

1const LineSplitStream = require('../LineSplitStream');2const expect = require('chai').expect;3const sinon = require('sinon');4const os = require('os');5describe('streams/line-split-stream', () => {6 describe('LineSplitStream', () => {7 it('стрим разбивает данные по строкам', (done) => {8 const lines = new LineSplitStream({encoding: 'utf-8'});9 const onData = sinon.spy();10 lines.on('data', onData);11 lines.on('end', () => {12 expect(onData.calledTwice, 'событие data должно быть вызвано 2 раза').to.be.true;13 expect(onData.firstCall.args[0]).to.equal('a');14 expect(onData.secondCall.args[0]).to.equal('b');15 done();16 });17 lines.write(`a${os.EOL}b`);18 lines.end();19 });20 it('стрим корректно передает данные даже если чанк не завершается переводом строки', (done) => {21 const lines = new LineSplitStream({encoding: 'utf-8'});22 const onData = sinon.spy();23 lines.on('data', onData);24 lines.on('end', () => {25 expect(onData.calledThrice, 'событие data должно быть вызвано 3 раза').to.be.true;26 expect(onData.firstCall.args[0]).to.equal('ab');27 expect(onData.secondCall.args[0]).to.equal('cd');28 expect(onData.thirdCall.args[0]).to.equal('ef');29 done();30 });31 lines.write('a');32 lines.write(`b${os.EOL}c`);33 lines.write(`d${os.EOL}e`);34 lines.write('f');35 lines.end();36 });37 it('событие onData срабатывает для всех строк, которые есть в чанке', (done) => {38 const lines = new LineSplitStream({encoding: 'utf-8'});39 const onData = sinon.spy();40 lines.on('data', onData);41 lines.on('end', () => {42 expect(onData.callCount, 'событие data должно быть вызвано 6 раз').to.be.equal(6);43 expect(onData.firstCall.args[0]).to.equal('a');44 expect(onData.secondCall.args[0]).to.equal('b');45 expect(onData.thirdCall.args[0]).to.equal('c');46 expect(onData.getCall(3).args[0]).to.equal('d');47 expect(onData.getCall(4).args[0]).to.equal('e');48 expect(onData.getCall(5).args[0]).to.equal('f');49 done();50 });51 lines.write(['a', 'b', 'c', 'd', 'e', 'f'].join(os.EOL));52 lines.end();53 });54 it('стрим не должен накапливать данные', function (done) {55 this.timeout(0);56 const lines = new LineSplitStream({encoding: 'utf-8'});57 const timeout = setTimeout(function () {58 done(new Error('стрим должен предавать данные дальше как только есть вся строка, а не накапливать данные'))59 }, 500)60 const onData = sinon.spy(() => {61 lines.end();62 });63 lines.on('data', onData);64 lines.on('end', () => {65 expect(onData.firstCall.args[0]).to.equal('a');66 clearTimeout(timeout)67 done();68 });69 lines.write(`a${os.EOL}`)70 })71 });...

Full Screen

Full Screen

index.test.js

Source:index.test.js Github

copy

Full Screen

1const LineSplitStream = require('../LineSplitStream');2const expect = require('chai').expect;3const sinon = require('sinon');4const os = require('os');5describe('streams/line-split-stream', () => {6 describe('LineSplitStream', () => {7 it('стрим разбивает данные по строкам', (done) => {8 const lines = new LineSplitStream({encoding: 'utf-8'});9 const onData = sinon.spy();10 lines.on('data', onData);11 lines.on('end', () => {12 expect(onData.calledTwice, 'событие data должно быть вызвано 2 раза').to.be.true;13 expect(onData.firstCall.args[0]).to.equal('a');14 expect(onData.secondCall.args[0]).to.equal('b');15 done();16 });17 lines.write(`a${os.EOL}b`);18 lines.end();19 });20 it('стрим корректно передает данные даже если чанк не завершается переводом строки', (done) => {21 const lines = new LineSplitStream({encoding: 'utf-8'});22 const onData = sinon.spy();23 lines.on('data', onData);24 lines.on('end', () => {25 expect(onData.calledThrice, 'событие data должно быть вызвано 3 раза').to.be.true;26 expect(onData.firstCall.args[0]).to.equal('ab');27 expect(onData.secondCall.args[0]).to.equal('cd');28 expect(onData.thirdCall.args[0]).to.equal('ef');29 done();30 });31 lines.write('a');32 lines.write(`b${os.EOL}c`);33 lines.write(`d${os.EOL}e`);34 lines.write('f');35 lines.end();36 });37 it('событие onData срабатывает для всех строк, которые есть в чанке', (done) => {38 const lines = new LineSplitStream({encoding: 'utf-8'});39 const onData = sinon.spy();40 lines.on('data', onData);41 lines.on('end', () => {42 expect(onData.callCount, 'событие data должно быть вызвано 6 раз').to.be.equal(6);43 expect(onData.firstCall.args[0]).to.equal('a');44 expect(onData.secondCall.args[0]).to.equal('b');45 expect(onData.thirdCall.args[0]).to.equal('c');46 expect(onData.getCall(3).args[0]).to.equal('d');47 expect(onData.getCall(4).args[0]).to.equal('e');48 expect(onData.getCall(5).args[0]).to.equal('f');49 done();50 });51 lines.write(['a', 'b', 'c', 'd', 'e', 'f'].join(os.EOL));52 lines.end();53 });54 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

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.evaluate(() => {7 window.onData = (data) => {8 console.log('got data: ' + data);9 };10 });11 await browser.close();12})();13const { chromium } = require('playwright');14(async () => {15 const browser = await chromium.launch();16 const context = await browser.newContext();17 const page = await context.newPage();18 await page.exposeBinding('onData', (source, data) => {19 console.log('got data: ' + data);20 });21 await browser.close();22})();23const { chromium } = require('playwright');24(async () => {25 const browser = await chromium.launch();26 const context = await browser.newContext();27 const page = await context.newPage();28 await page.exposeBinding('onData', (source, data) => {29 console.log('got data: ' + data);30 });31 await page.evaluate(() => {32 window.onData('test');33 });34 await browser.close();35})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2const fs = require('fs');3(async () => {4 const browser = await chromium.launch({headless: false});5 const context = await browser.newContext();6 const page = await context.newPage();7 const client = await page.context().newCDPSession(page);8 client.on('Network.dataReceived', (params) => {9 fs.appendFile('test.txt', JSON.stringify(params), function (err) {10 if (err) throw err;11 });12 });13 await page.click('input[name="q"]');14 await page.type('input[name="q"]', 'Playwright');15 await page.keyboard.press('Enter');16 await page.waitForSelector('text=Playwright is a Node library to automate');17 await browser.close();18})();19{"requestId":"D6C9FDB3B3B0C3E2D0F1F3C1E7C5B0C9","timestamp":1602112946.411,"dataLength":100,"encodedDataLength":0}20{"requestId":"D6C9FDB3B3B0C3E2D0F1F3C1E7C5B0C9","timestamp":1602112946.411,"dataLength":100,"encodedDataLength":0}21{"requestId":"D6C9FDB3B3B0C3E2D0F1F3C1E7C5B0C9","timestamp":1602112946.411,"dataLength":100,"encodedDataLength":0}22{"requestId":"D6C9FDB3B3B0C3E2D0F1F3C1E7C5B0C9","timestamp":1602112946.411,"dataLength":100,"encodedDataLength":0}23{"requestId":"D6C9FDB3B3B0C3E2D0F1F3C1E7C5B0C9","timestamp":1602112946.411,"dataLength":100,"encodedDataLength":0}24{"requestId":"D6C9FDB3B3B0C3E2D0F1

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright-chromium');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.on('request', request => console.log(request.url()));7 await page.on('response', response => console.log(response.status()));8 await browser.close();9})();10const { chromium } = require('playwright-chromium');11(async () => {12 const browser = await chromium.launch();13 const context = await browser.newContext();14 const page = await context.newPage();15 await page.on('request', request => console.log(request.url()));16 await page.on('response', response => console.log(response.status()));17 await browser.close();18})();19const { chromium } = require('playwright-chromium');20(async () => {21 const browser = await chromium.launch();22 const context = await browser.newContext();23 const page = await context.newPage();24 await page.on('request', request => console.log(request.url()));25 await page.on('response', response => console.log(response.status()));26 await browser.close();27})();28const { chromium } = require('playwright-chromium');29(async () => {30 const browser = await chromium.launch();31 const context = await browser.newContext();32 const page = await context.newPage();33 await page.on('request', request => console.log(request.url()));34 await page.on('response', response => console.log(response.status()));35 await browser.close();36})();37const { chromium } = require('playwright-chromium');

Full Screen

Using AI Code Generation

copy

Full Screen

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._client.send('Network.enable');7 page.on('request', (request) => {8 console.log(request.url());9 });10 await browser.close();11})();12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 await page._client.send('Network.enable');18 page.on('request', (request) => {19 console.log(request.url());20 });21 await browser.close();22})();23const { chromium } = require('playwright');24(async () => {25 const browser = await chromium.launch();26 const context = await browser.newContext();27 const page = await context.newPage();28 await page._client.send('Network.enable');29 page.on('request', (request) => {30 console.log(request.url());31 });32 await browser.close();33})();34const { chromium } = require('playwright');35(async () => {36 const browser = await chromium.launch();37 const context = await browser.newContext();38 const page = await context.newPage();39 await page._client.send('Network.enable');40 page.on('request', (request) => {41 console.log(request.url());42 });43 await browser.close();44})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const client = await page.context().newCDPSession(page);2await client.send('Network.enable');3await client.on('Network.dataReceived', (data) => {4 console.log('dataReceived: ', data);5});6await page.screenshot({ path: 'google.png' });7await browser.close();8#### constructor(page)9#### async send(method, params)10#### async on(method, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { on } = require('playwright/lib/client/transport');2on('data', (data) => { console.log(data); });3const { setData } = require('playwright/lib/client/transport');4setData('hello');5const { getData } = require('playwright/lib/client/transport');6console.log(getData());7const { clearData } = require('playwright/lib/client/transport');8clearData();9const { on } = require('playwright/lib/client/transport');10on('data', (data) => { console.log(data); });11const { off } = require('playwright/lib/client/transport');12off('data', (data) => { console.log(data); });13const { offAll } = require('playwright/lib/client/transport');14offAll();15const { addListener } = require('playwright/lib/client/transport');16addListener('data', (data) => { console.log(data); });17const { removeListener } = require('playwright/lib/client/transport');18removeListener('data', (data) => { console.log(data); });19const { removeAllListeners } = require('playwright/lib/client/transport');20removeAllListeners();21const { listeners } = require('playwright/lib/client/transport');22console.log(listeners());23const { once } = require('

Full Screen

Playwright tutorial

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.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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