Best JavaScript code snippet using wpt
forks.ts
Source:forks.ts
1import ava from 'ava'2import { setupTwo } from './util/util.js'3ava('conflicting and merging writes to individual file', async t => {4 const VALUES = [5 Buffer.from('writer1', 'utf-8'),6 Buffer.from('writer2', 'utf-8')7 ]8 const {sim, ws1, ws2, writer1, writer2} = await setupTwo(t)9 // conflicting writes10 // HACK sync state prior to disconnect, works around https://github.com/hypercore-protocol/autobase/issues/711 await ws1.indexCore.update()12 await ws2.indexCore.update()13 console.log('\nDISCONNECT\n')14 sim.disconnect(sim.stores[0], sim.stores[1])15 await ws1.writeFile('/test.txt', VALUES[0])16 await ws2.writeFile('/test.txt', VALUES[1])17 // not yet synced18 t.deepEqual(await ws1.readFile('/test.txt'), VALUES[0])19 t.deepEqual(await ws2.readFile('/test.txt'), VALUES[1])20 // synced but in conflict state21 console.log('\nCONNECT\n')22 sim.connect(sim.stores[0], sim.stores[1])23 t.deepEqual(24 await ws1.readFile('/test.txt'),25 await ws2.readFile('/test.txt')26 )27 {28 const info1 = await ws1.statFile('/test.txt')29 t.truthy(info1)30 const info2 = await ws2.statFile('/test.txt')31 t.truthy(info2)32 if (info1 && info2) {33 t.deepEqual(info1, info2)34 }35 if (info1) {36 t.is(info1.conflict, true)37 t.is(info1.otherChanges?.length, 1)38 }39 }40 // merging write41 await ws1.writeFile('/test.txt', VALUES[0])42 t.deepEqual(43 await ws1.readFile('/test.txt'),44 await ws2.readFile('/test.txt')45 )46 {47 const info1 = await ws1.statFile('/test.txt')48 t.truthy(info1)49 const info2 = await ws2.statFile('/test.txt')50 t.truthy(info2)51 if (info1 && info2) {52 t.deepEqual(info1, info2)53 }54 if (info1) {55 t.is(info1.conflict, false)56 t.is(info1.otherChanges?.length, 0) // no conflicts57 }58 }59})60ava('conflicting and merging writes & deletes to individual file', async t => {61 const VALUES = [62 Buffer.from('first write', 'utf-8'),63 Buffer.from('second write', 'utf-8'),64 Buffer.from('third write', 'utf-8')65 ]66 const {sim, ws1, ws2, writer1, writer2} = await setupTwo(t)67 // create a file68 await ws1.writeFile('/test.txt', VALUES[0])69 // conflicting write & delete70 // HACK sync state prior to disconnect, works around https://github.com/hypercore-protocol/autobase/issues/771 await ws1.indexCore.update()72 await ws2.indexCore.update()73 console.log('\nDISCONNECT\n')74 sim.disconnect(sim.stores[0], sim.stores[1])75 await ws1.deleteFile('/test.txt')76 await ws2.writeFile('/test.txt', VALUES[1])77 // not yet synced78 t.deepEqual(await ws1.readFile('/test.txt'), undefined)79 t.deepEqual(await ws2.readFile('/test.txt'), VALUES[1])80 // synced but in conflict state81 console.log('\nCONNECT\n')82 sim.connect(sim.stores[0], sim.stores[1])83 t.deepEqual(84 await ws1.readFile('/test.txt'),85 await ws2.readFile('/test.txt')86 )87 {88 const info1 = await ws1.statFile('/test.txt')89 t.truthy(info1)90 const info2 = await ws2.statFile('/test.txt')91 t.truthy(info2)92 if (info1 && info2) {93 t.deepEqual(info1, info2)94 }95 if (info1) {96 t.is(info1.conflict, true)97 t.is(info1.otherChanges?.length, 1)98 }99 }100 // file is still present in listing even though it may be in a "deleted" state101 t.is((await ws1.listFiles('/')).length, 1)102 t.is((await ws2.listFiles('/')).length, 1)103 // merging write104 await ws1.writeFile('/test.txt', VALUES[2])105 t.deepEqual(106 await ws1.readFile('/test.txt'),107 await ws2.readFile('/test.txt')108 )109 {110 const info1 = await ws1.statFile('/test.txt')111 t.truthy(info1)112 const info2 = await ws2.statFile('/test.txt')113 t.truthy(info2)114 if (info1 && info2) {115 t.deepEqual(info1, info2)116 }117 if (info1){118 t.is(info1.conflict, false)119 t.is(info1.otherChanges?.length, 0) // no conflicts120 }121 }122})123ava('conflicting and merging writes & moves to individual file', async t => {124 const VALUES = [125 Buffer.from('first write', 'utf-8'),126 Buffer.from('second write', 'utf-8'),127 Buffer.from('third write', 'utf-8')128 ]129 const {sim, ws1, ws2, writer1, writer2} = await setupTwo(t)130 // create a file131 await ws1.writeFile('/test.txt', VALUES[0])132 // conflicting write & delete133 // HACK sync state prior to disconnect, works around https://github.com/hypercore-protocol/autobase/issues/7134 await ws1.indexCore.update()135 await ws2.indexCore.update()136 console.log('\nDISCONNECT\n')137 sim.disconnect(sim.stores[0], sim.stores[1])138 await ws1.moveFile('/test.txt', '/test2.txt')139 await ws2.writeFile('/test.txt', VALUES[1])140 // not yet synced141 t.deepEqual(await ws1.readFile('/test.txt'), undefined)142 t.deepEqual(await ws1.readFile('/test2.txt'), VALUES[0])143 t.deepEqual(await ws2.readFile('/test.txt'), VALUES[1])144 // synced but in conflict state145 console.log('\nCONNECT\n')146 sim.connect(sim.stores[0], sim.stores[1])147 t.deepEqual(148 await ws1.readFile('/test.txt'),149 await ws2.readFile('/test.txt')150 )151 {152 const info1 = await ws1.statFile('/test.txt')153 t.truthy(info1)154 const info2 = await ws2.statFile('/test.txt')155 t.truthy(info2)156 if (info1 && info2) {157 t.deepEqual(info1, info2)158 }159 if (info1){160 t.is(info1.conflict, true)161 t.is(info1.otherChanges?.length, 1)162 }163 }164 t.deepEqual(165 await ws1.readFile('/test2.txt'),166 await ws2.readFile('/test2.txt')167 )168 {169 const info1 = await ws1.statFile('/test2.txt')170 t.truthy(info1)171 const info2 = await ws2.statFile('/test2.txt')172 t.truthy(info2)173 if (info1 && info2) {174 t.deepEqual(info1, info2)175 }176 if (info1){177 t.is(info1.conflict, false)178 t.is(info1.otherChanges?.length, 0)179 }180 }181 // file is still present in listing even though it may be in a "deleted" state182 t.is((await ws1.listFiles('/')).length, 2)183 t.is((await ws2.listFiles('/')).length, 2)184})185ava('conflicting and merging writes & copies to individual file', async t => {186 const VALUES = [187 Buffer.from('first write', 'utf-8'),188 Buffer.from('second write', 'utf-8'),189 Buffer.from('third write', 'utf-8')190 ]191 const {sim, ws1, ws2, writer1, writer2} = await setupTwo(t)192 // create two file193 await ws1.writeFile('/test.txt', VALUES[0])194 await ws1.writeFile('/test2.txt', VALUES[1])195 // conflicting write & delete196 // HACK sync state prior to disconnect, works around https://github.com/hypercore-protocol/autobase/issues/7197 await ws1.indexCore.update()198 await ws2.indexCore.update()199 console.log('\nDISCONNECT\n')200 sim.disconnect(sim.stores[0], sim.stores[1])201 await ws1.copyFile('/test2.txt', '/test.txt')202 await ws2.writeFile('/test.txt', VALUES[2])203 // not yet synced204 t.deepEqual(await ws1.readFile('/test.txt'), VALUES[1])205 t.deepEqual(await ws1.readFile('/test2.txt'), VALUES[1])206 t.deepEqual(await ws2.readFile('/test.txt'), VALUES[2])207 // synced but in conflict state208 console.log('\nCONNECT\n')209 sim.connect(sim.stores[0], sim.stores[1])210 t.deepEqual(211 await ws1.readFile('/test.txt'),212 await ws2.readFile('/test.txt')213 )214 {215 const info1 = await ws1.statFile('/test.txt')216 t.truthy(info1)217 const info2 = await ws2.statFile('/test.txt')218 t.truthy(info2)219 if (info1 && info2) {220 t.deepEqual(info1, info2)221 }222 if (info1){223 t.is(info1.conflict, true)224 t.is(info1.otherChanges?.length, 1)225 }226 }227 t.deepEqual(228 await ws1.readFile('/test2.txt'),229 await ws2.readFile('/test2.txt')230 )231 {232 const info1 = await ws1.statFile('/test2.txt')233 t.truthy(info1)234 const info2 = await ws2.statFile('/test2.txt')235 t.truthy(info2)236 if (info1 && info2) {237 t.deepEqual(info1, info2)238 }239 if (info1){240 t.is(info1.conflict, false)241 t.is(info1.otherChanges?.length, 0)242 }243 }244 // file is still present in listing even though it may be in a "deleted" state245 t.is((await ws1.listFiles('/')).length, 2)246 t.is((await ws2.listFiles('/')).length, 2)...
about.js
Source:about.js
1/**2 * Created by qingyuan.hou on 2017/10/31.3 */4var photoSource = {5 'situ': {6 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o13u50j30b40b4757.jpg',7 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o58m16g307i0a0e13.jpg'8 },9 'mengchao': {10 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o0zre4j30b40b4myd.jpg',11 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o4bq79j30qo0zktck.jpg'12 },13 'changquan': {14 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o0zkjgj30b40b4ab5.jpg',15 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o3x6s7j30qo0zkadh.jpg'16 },17 'hanyang': {18 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o0zfaqj30b40b4755.jpg',19 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o2h6nig305k05k0ud.jpg'20 },21 'hongqi': {22 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o0zm9lj30b40b4dgq.jpg',23 },24 // 'lifang': {25 // src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o118htj30b40b4gmq.jpg'26 // },27 'liuwenbo': {28 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o0zoiaj30b40b4wfa.jpg'29 },30 'naiwang': {31 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o13c29j30b40b4wfx.jpg',32 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o49alfg305k05kn0x.jpg'33 },34 'qingguo': {35 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o13kb7j30b40b475a.jpg',36 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o2yxy8g305k05k41h.jpg'37 },38 'qingyuan': {39 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o13wdoj30b40b4aau.jpg'40 },41 'tianqi': {42 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o16f84j30b40b4wfn.jpg',43 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o15s51j308c08cq3w.jpg'44 },45 'tianjun': {46 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o14njgj30b40b4t9j.jpg'47 },48 'wenbo': {49 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o17kgzj30b40b4dgg.jpg',50 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o17hg9j308c08cjsr.jpg'51 },52 'wengai': {53 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o189wbj30b40b4759.jpg'54 },55 'wenjie': {56 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o1alxzj30b40b43zb.jpg'57 },58 'wenxiong': {59 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o1bkruj30b40b4jsa.jpg'60 },61 'xiaolin': {62 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o1hzxhj30b40b4q3r.jpg'63 },64 'xiaoxiao': {65 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o1ucsyj30b40b4wft.jpg',66 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o3gy12j30jg0p0q6h.jpg'67 },68 // 'xili': {69 // src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o1vu9aj30b40b4t9m.jpg'70 // },71 'xinben': {72 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o1v1sgj30b40b4js3.jpg',73 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp66fln9gg305k05kju1.jpg'74 },75 'xinyue': {76 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o1mvnqj30b40b4ab7.jpg',77 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o1xvhbg305k05kt9f.jpg'78 },79 'xujie': {80 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o1xmpnj30b40b4gmv.jpg',81 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o3bhq3g305k05kjup.jpg'82 },83 'yangzai': {84 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o1x8m8j30b40b43ze.jpg',85 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o4a79cg304g03c42z.jpg'86 },87 'yaojie': {88 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o25793j30b40b4q3p.jpg',89 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o2oe8kj30b40b4405.jpg'90 },91 'yuhao': {92 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o2q9rtj30b40b4wfd.jpg',93 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o2qakpj30e80iyabd.jpg'94 },95 'zhaojun': {96 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o2f8msj30b40b4dgx.jpg'97 },98 'zhenying': {99 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o26p2aj30b40b4756.jpg',100 kuso: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o4bikag305k05kae0.jpg'101 },102 'zixiang': {103 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o2pizdj30b40b4gmg.jpg'104 },105 'zhigang': {106 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o2e3yej30b40b4gmd.jpg'107 },108 'wangliang': {109 src: 'https://ws1.sinaimg.cn/large/006cGJIjly1fkp5o1cq9zj30b40b4aax.jpg'110 }111};112var photos = [113 // 'ymfe',114 'situ',115 'mengchao',116 'naiwang',117 'yaojie',118 'yangzai',119 'xiaoxiao',120 'xujie',121 'xinyue',122 'yuhao',123 'wenjie',124 'changquan',125 'qingguo',126 'zhenying',127 'wenbo',128 'tianqi',129 'wenxiong',130 'zixiang',131 'hongqi',132 'hanyang',133 'wengai',134 // 'lifang',135 // 'xili',136 'zhigang',137 'xiaolin',138 'xinben',139 'liuwenbo',140 'tianjun',141 'wangliang',142 'qingyuan',143 'zhaojun'144];145var kusosMap = {};146kusos = ['yaojie', 'situ', 'yangzai', 'yuhao', 'xiaoxiao', 'mengchao', 'changquan', 'naiwang', 'qingguo', 'xujie', 'hanyang', 'xinben', 'tianqi', 'xinyue', 'zhenying', 'wenbo'];147for (var i = 0; i < kusos.length; i++) {148 // kusosMap['images/photos/' + kusos[i] + '.jpg'] = 'images/photos/' + kusos[i] + '_kuso.jpg';149 kusosMap[photoSource[kusos[i]].src] = photoSource[kusos[i]].kuso;150}151var photosArr = photos.map(function (item, index) {152 return photoSource[item].src;153});154// main155$(function () {156 var $window = $(window)157 var $header = $('.js-header');158 var $photoWall = $('.js-photo-wall');159 function startPhotoWall() {160 if ($photoWall.css('display') !== 'none') {161 $photoWall.tqPhotoWall(photosArr, kusosMap);162 }163 }164 function setHeader() {165 var scrollTop = $window.scrollTop();166 if (scrollTop <= 0) {167 $header.removeClass('header-not-top').addClass('header-top');168 } else {169 $header.removeClass('header-top').addClass('header-not-top');170 }171 }172 $window.resize(startPhotoWall);173 $window.scroll(setHeader);174 startPhotoWall();175 setHeader();176 var dpr = window.devicePixelRatio;177 if (dpr >= 2) {178 $('.m-our-style .photo').css({179 backgroundImage: 'url(https://ws1.sinaimg.cn/large/006cGJIjly1fkntt27e9vj30m80ojaj5.jpg)'180 });181 }...
Using AI Code Generation
1var wptest = require('wptest');2wptest.ws1();3var wptest = require('wptest');4wptest.ws2();5var wptest = require('wptest');6wptest.ws3();7var wptest = require('wptest');8wptest.ws4();9var wptest = require('wptest');10wptest.ws5();11var wptest = require('wptest');12wptest.ws6();13var wptest = require('wptest');14wptest.ws7();15var wptest = require('wptest');16wptest.ws8();17var wptest = require('wptest');18wptest.ws9();19var wptest = require('wptest');20wptest.ws10();21var wptest = require('wptest');22wptest.ws11();23var wptest = require('wptest');24wptest.ws12();25var wptest = require('wptest');26wptest.ws13();27var wptest = require('wptest');28wptest.ws14();29var wptest = require('wptest');30wptest.ws15();31var wptest = require('wptest');32wptest.ws16();
Using AI Code Generation
1var wptest = require('wptest');2wptest.ws1();3var wptest = require('wptest');4wptest.ws2();5var wptest = require('wptest');6wptest.ws3();7var wptest = require('wptest');8wptest.ws4();9var wptest = require('wptest');10wptest.ws5();11var wptest = require('wptest');12wptest.ws6();13var wptest = require('wptest');14wptest.ws7();15var wptest = require('wptest');16wptest.ws8();17var wptest = require('wptest');18wptest.ws9();19var wptest = require('wptest');20wptest.ws10();21var wptest = require('wptest');22wptest.ws11();23var wptest = require('wptest');24wptest.ws12();25var wptest = require('wptest');26wptest.ws13();27var wptest = require('wptest');28wptest.ws14();29var wptest = require('wptest');30wptest.ws15();31var wptest = require('wptest');32wptest.ws16();
Using AI Code Generation
1var wptest1 = require('./wptest1');2wptest1.ws1();3exports.ws1 = function() {4 console.log('ws1');5}6exports.ws2 = function() {7 console.log('ws2');8}
Using AI Code Generation
1var wptools = require('wptools');2var wp = new wptools('Albert Einstein');3wp.get(function(err, response) {4 if (err) {5 console.log(err);6 } else {7 console.log(response);8 }9});
Using AI Code Generation
1const wptools = require('wptools');2const wp = wptools.page('Albert Einstein');3wp.get((err, info) => {4 console.log(info);5});6const wptools = require('wptools');7const wp = wptools.page('Albert Einstein');8wp.get((err, info) => {9 console.log(info);10});
Using AI Code Generation
1var ws1 = require('ws1');2ws1('www.google.com', function(err, data){3});4var ws2 = require('ws2');5ws2('www.google.com', function(err, data){6});7var ws3 = require('ws3');8ws3('www.google.com', function(err, data){9});10var ws4 = require('ws4');11ws4('www.google.com', function(err, data){12});13MIT © [Aishwarya](
Using AI Code Generation
1var wp = require('./wptest.js');2wp.ws1();3wp.ws2();4module.exports = function() {5 this.ws1 = function() {6 console.log('ws1');7 }8 this.ws2 = function() {9 console.log('ws2');10 }11}12var wp = require('./wptest.js');13var w = new wp();14w.ws1();15w.ws2();16module.exports = function() {17 this.ws1 = function() {18 console.log('ws1');19 }20 this.ws2 = function() {21 console.log('ws2');22 }23}24module.exports.prototype.ws3 = function() {25 console.log('ws3');26}27var wp = require('./wptest.js');28var w = new wp();29w.ws1();30w.ws2();31w.ws3();32module.exports = function() {33 this.ws1 = function() {34 console.log('ws1');35 }36 this.ws2 = function() {37 console.log('ws2');38 }39}40module.exports.prototype.ws3 = function() {41 console.log('ws3');42}43module.exports.ws4 = function() {44 console.log('ws4');45}46var wp = require('./wptest.js');47var w = new wp();48w.ws1();49w.ws2();50w.ws3();51wp.ws4();52module.exports = function() {53 this.ws1 = function() {54 console.log('ws1');55 }56 this.ws2 = function() {57 console.log('ws2');58 }59}60module.exports.prototype.ws3 = function() {61 console.log('
Using AI Code Generation
1var ws1 = require('./wptest.js').ws1;2ws1();3(function (exports, require, module, __filename, __dirname) {4});5To include the File System module, use the require() method:6var fs = require('fs');7fs.readFile('filename', callback);8var fs = require('fs');9fs.readFile('demofile1.html', function(err, data) {10 if (err) throw err;11 console.log(data);12});
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!!