Best JavaScript code snippet using taiko
net.spec.js
Source:net.spec.js
...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);...
generateEnvFile.js
Source:generateEnvFile.js
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 })...
checker.js
Source:checker.js
...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...
LineSplitStream.test.js
Source:LineSplitStream.test.js
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 });...
index.test.js
Source:index.test.js
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 });...
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!!