Best JavaScript code snippet using wpt
index.js
Source:index.js
1'use strict'2const tman = require('tman')3const assert = require('assert')4const Stream = require('stream')5const thunk = require('thunks').thunk6const through = require('through2')7const toThrough = require('to-through')8test(require('..'))9function test (merge2) {10 tman.suite('merge2', function () {11 tman.it('merge2(read1, read2, through3)', function (done) {12 const options = { objectMode: true }13 const result = []14 const read1 = fakeReadStream(options)15 const read2 = fakeReadStream(options)16 const through3 = through.obj()17 const mergeStream = merge2(read1, read2, through3)18 read1.push(1)19 thunk.delay(100)(function () {20 read1.push(2)21 read1.push(null)22 })23 read2.push(3)24 thunk.delay(10)(function () {25 read2.push(4)26 read2.push(null)27 })28 through3.push(5)29 thunk.delay(200)(function () {30 through3.push(6)31 through3.end()32 })33 mergeStream34 .on('data', function (chunk) {35 result.push(chunk)36 })37 .on('error', done)38 .on('end', function () {39 assert.deepStrictEqual(result, [1, 2, 3, 4, 5, 6])40 done()41 })42 })43 tman.it('merge2 - error handling', function (done) {44 const ts = through.obj()45 const mergeStream = merge2(toThrough(ts), { pipeError: true })46 const expectedError = new Error('error')47 thunk.delay(100)(function () {48 ts.destroy(expectedError)49 })50 mergeStream51 .on('error', function (error) {52 assert.strictEqual(error, expectedError)53 done()54 })55 .on('end', function () {56 throw Error('error expected')57 })58 })59 tman.it('merge2(TransformStream)', function (done) {60 const result = []61 const ts = through.obj()62 const mergeStream = merge2(toThrough(ts))63 ts.push(1)64 thunk.delay(100)(function () {65 ts.push(2)66 ts.push(null)67 })68 mergeStream69 .on('data', function (chunk) {70 result.push(chunk)71 })72 .on('error', done)73 .on('end', function () {74 assert.deepStrictEqual(result, [1, 2])75 done()76 })77 })78 tman.it('merge2(read1, [read2, through3], through4, [through5, read6])', function (done) {79 const options = { objectMode: true }80 const result = []81 const read1 = fakeReadStream(options)82 const read2 = fakeReadStream(options)83 const through3 = through.obj()84 const through4 = through.obj()85 const through5 = through.obj()86 const read6 = fakeReadStream(options)87 read1.push(1)88 read1.push(null)89 thunk.delay(100)(function () {90 read2.push(2)91 read2.push(null)92 })93 through3.push(3)94 through3.end()95 through4.push(4)96 through4.push(null)97 through5.push(5)98 through5.push(null)99 thunk.delay(200)(function () {100 read6.push(6)101 read6.push(null)102 })103 const mergeStream = merge2(read1, [read2, through3], through4, [through5, read6])104 mergeStream105 .on('data', function (chunk) {106 result.push(chunk)107 })108 .on('error', done)109 .on('end', function () {110 assert.deepStrictEqual(result, [1, 3, 2, 4, 5, 6])111 done()112 })113 })114 tman.it('merge2().add(read1, [read2, through3], through4, [through5, read6])', function (done) {115 const options = { objectMode: true }116 const result = []117 const read1 = fakeReadStream(options)118 const read2 = fakeReadStream(options)119 const through3 = through.obj()120 const through4 = through.obj()121 const through5 = through.obj()122 const read6 = fakeReadStream(options)123 const mergeStream = merge2()124 read1.push(1)125 read1.push(null)126 thunk.delay(100)(function () {127 read2.push(2)128 read2.push(null)129 })130 through3.push(3)131 through3.end()132 through4.push(4)133 through4.push(null)134 through5.push(5)135 through5.push(null)136 thunk.delay(200)(function () {137 read6.push(6)138 read6.push(null)139 })140 mergeStream141 .add(read1, [read2, through3], through4)142 .on('data', function (chunk) {143 result.push(chunk)144 })145 .add([through5, read6])146 .on('error', done)147 .on('end', function () {148 assert.deepStrictEqual(result, [1, 3, 2, 4, 5, 6])149 done()150 })151 })152 tman.it('merge2(read1, read2, through3, {objectMode: false})', function (done) {153 const options = { objectMode: false }154 let result = ''155 const read1 = fakeReadStream(options)156 const read2 = fakeReadStream(options)157 const through3 = through(options)158 const mergeStream = merge2(read1, read2, through3, options)159 read1.push('1')160 thunk.delay(100)(function () {161 read1.push('2')162 read1.push(null)163 })164 read2.push('3')165 thunk.delay(10)(function () {166 read2.push('4')167 read2.push(null)168 })169 through3.push('5')170 thunk.delay(200)(function () {171 through3.push('6')172 through3.end()173 })174 mergeStream175 .on('data', function (chunk) {176 result += chunk.toString()177 })178 .on('error', done)179 .on('end', function () {180 assert.strictEqual(result, '123456')181 done()182 })183 })184 tman.it('merge2([read1, read2]) with classic style streams', function (done) {185 const result = []186 const read1 = fakeReadClassicStream()187 const read2 = fakeReadClassicStream()188 const mergeStream = merge2([read1, read2])189 read1.push(1)190 read1.push(null)191 thunk.delay(100)(function () {192 read2.push(2)193 read2.push(null)194 })195 mergeStream196 .on('data', function (chunk) {197 result.push(chunk)198 })199 .on('error', done)200 .on('end', function () {201 assert.deepStrictEqual(result, [1, 2])202 done()203 })204 })205 tman.it('merge2(read1, read2, {end: false})', function (done) {206 const options = { objectMode: true }207 const result = []208 const read1 = fakeReadStream(options)209 const read2 = fakeReadStream(options)210 const through3 = through.obj()211 const mergeStream = merge2(read1, read2, { end: false })212 read1.push(1)213 read1.push(2)214 read1.push(null)215 read2.push(3)216 read2.push(4)217 read2.push(null)218 through3.push(5)219 through3.push(6)220 through3.end()221 thunk.delay(500)(function () {222 assert.deepStrictEqual(result, [1, 2, 3, 4])223 mergeStream.add(through3)224 return thunk.delay(100)225 })(function () {226 mergeStream.end()227 })228 mergeStream229 .on('data', function (chunk) {230 result.push(chunk)231 })232 .on('error', done)233 .on('end', function () {234 assert.deepStrictEqual(result, [1, 2, 3, 4, 5, 6])235 done()236 })237 })238 tman.it('merge2(merge2(through4, [through5, read6]), read1, [read2, through3])', function (done) {239 const options = { objectMode: true }240 const result1 = []241 const result2 = []242 const read1 = fakeReadStream(options)243 const read2 = fakeReadStream(options)244 const through3 = through.obj()245 const through4 = through.obj()246 const through5 = through.obj()247 const read6 = fakeReadStream(options)248 read1.push(1)249 read1.push(null)250 thunk.delay(100)(function () {251 read2.push(2)252 read2.push(null)253 })254 through3.push(3)255 through3.end()256 through4.push(4)257 through4.push(null)258 through5.push(5)259 through5.push(null)260 thunk.delay(10)(function () {261 read6.push(6)262 read6.push(null)263 })264 const mergeStream1 = merge2(through4, [through5, read6])265 mergeStream1.on('data', function (chunk) {266 result1.push(chunk)267 })268 const mergeStream = merge2(mergeStream1, read1, [read2, through3])269 mergeStream270 .on('data', function (chunk) {271 result2.push(chunk)272 if (result2.length <= 3) assert.deepStrictEqual(result1, result2)273 else assert.deepStrictEqual(result1, [4, 5, 6])274 })275 .on('error', done)276 .on('end', function () {277 assert.deepStrictEqual(result2, [4, 5, 6, 1, 3, 2])278 done()279 })280 })281 })282}283function fakeReadStream (options) {284 const readStream = new Stream.Readable(options)285 readStream._read = function () {}286 return readStream287}288function fakeReadClassicStream () {289 const readStream = new Stream()290 readStream.readable = true291 readStream.push = function (data) {292 if (data === null) {293 this.emit('end')294 readStream.readable = false295 }296 this.emit('data', data)297 }298 return readStream...
read.spec.js
Source:read.spec.js
1'use strict';2var _expect = require('expect');3var _expect2 = _interopRequireDefault(_expect);4var _read = require('../read');5var _read2 = _interopRequireDefault(_read);6function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }7describe('read', function () {8 it('should get simple values', function () {9 (0, _expect2.default)((0, _read2.default)('foo', { foo: 'bar' })).toBe('bar');10 (0, _expect2.default)((0, _read2.default)('foo', { foo: 7 })).toBe(7);11 (0, _expect2.default)((0, _read2.default)('bar', { bar: true })).toBe(true);12 });13 it('should get arbitrarily deep dotted values', function () {14 var data = {15 foo: {16 bar: {17 baz: 4218 }19 }20 };21 (0, _expect2.default)((0, _read2.default)('foo', data)).toBe(data.foo);22 (0, _expect2.default)((0, _read2.default)('foo.bar', data)).toBe(data.foo.bar);23 (0, _expect2.default)((0, _read2.default)('foo.bar.baz', data)).toBe(42);24 });25 it('should return undefined if structure is incomplete', function () {26 var data = {27 foo: {}28 };29 (0, _expect2.default)((0, _read2.default)('foo', data)).toBe(data.foo);30 (0, _expect2.default)((0, _read2.default)('foo.bar', data)).toBe(undefined);31 (0, _expect2.default)((0, _read2.default)('foo.bar.baz', data)).toBe(undefined);32 });33 it('should throw an error when array syntax is broken', function () {34 (0, _expect2.default)(function () {35 (0, _read2.default)('foo[dog', {});36 }).toThrow(/found/);37 });38 it('should get simple array values', function () {39 var data = {40 cat: ['foo', 'bar', 'baz']41 };42 (0, _expect2.default)((0, _read2.default)('cat[0]', data)).toBe('foo');43 (0, _expect2.default)((0, _read2.default)('cat[1]', data)).toBe('bar');44 (0, _expect2.default)((0, _read2.default)('cat[2]', data)).toBe('baz');45 });46 it('should get return undefined when array is not there', function () {47 var data = {48 cat: undefined49 };50 (0, _expect2.default)((0, _read2.default)('cat[0]', data)).toBe(undefined);51 });52 it('should get complex array values', function () {53 var data = {54 rat: {55 cat: [{ name: 'foo' }, { name: 'bar' }, { name: 'baz' }]56 }57 };58 (0, _expect2.default)((0, _read2.default)('rat.cat[0].name', data)).toBe('foo');59 (0, _expect2.default)((0, _read2.default)('rat.cat[0][name]', data)).toBe('foo');60 (0, _expect2.default)((0, _read2.default)('rat.cat[1].name', data)).toBe('bar');61 (0, _expect2.default)((0, _read2.default)('rat.cat[1][name]', data)).toBe('bar');62 (0, _expect2.default)((0, _read2.default)('rat.cat[2].name', data)).toBe('baz');63 (0, _expect2.default)((0, _read2.default)('rat.cat[2][name]', data)).toBe('baz');64 });...
urlConfig.ts
Source:urlConfig.ts
1import { environment } from "../../environments/environment.prod";2const read2 = environment.URL + '/api/read2'3export const urlConfig = {4 getPageSubReadLikeStartsWith: read2 + '/sub-read/starts-with',5 getPageSubRead: read2 + '/sub-read',6 getSubReadById: read2 + '/sub-read',7 createSubRead: read2 + '/sub-read',8 vote: read2 + '/vote',9 getAllPosts: read2 + '/post',10 createPost: read2 + '/post',11 getPostById: read2 + '/post/',12 getPagePostByUsername: read2 + '/post/by-user/',13 getPagePostBySubReadId: read2 + '/post/by-sub-read/',14 createComment: read2 + '/comment',15 getSliceCommentsForPost: read2 + '/comment/by-post/',16 getSliceCommentsByUser: read2 + '/comment/by-user/',17 refreshToken: read2 + '/auth/refresh/token',18 signUp: read2 + '/auth/sign-up',19 login: read2 + '/auth/sign-in',20 logout: read2 + '/auth/sign-out',21 property: read2 + '/property',...
Using AI Code Generation
1var wptools = require('wptools');2var wiki = wptools('Albert Einstein');3wiki.getRead2(function(err, resp) {4 console.log(err || resp);5});6var wptools = require('wptools');7var wiki = wptools('Albert Einstein');8wiki.getRead(function(err, resp) {9 console.log(err || resp);10});11var wptools = require('wptools');12var wiki = wptools('Albert Einstein');13wiki.getRead3(function(err, resp) {14 console.log(err || resp);15});16var wptools = require('wptools');17var wiki = wptools('Albert Einstein');18wiki.getRead4(function(err, resp) {19 console.log(err || resp);20});21var wptools = require('wptools');22var wiki = wptools('Albert Einstein');23wiki.getRead5(function(err, resp) {24 console.log(err || resp);25});26var wptools = require('wptools');27var wiki = wptools('Albert Einstein');28wiki.getRead6(function(err, resp) {29 console.log(err || resp);30});31var wptools = require('wptools');32var wiki = wptools('Albert Einstein');33wiki.getRead7(function(err, resp) {34 console.log(err || resp);35});36var wptools = require('wptools');37var wiki = wptools('Albert Einstein');38wiki.getRead8(function(err, resp) {39 console.log(err || resp);40});41var wptools = require('wptools');42var wiki = wptools('Albert Einstein');43wiki.getRead9(function(err, resp) {44 console.log(err || resp);45});
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.read2('160610_1H_1d7e6d0e6e8a6c1f6a9a9a0a6b7f8a3d', function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10{ statusCode: 200,11 { testId: '160610_1H_1d7e6d0e6e8a6c1f6a9a9a0a6b7f8a3d',
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.0d3b0e9b6c9e6f1d6e0d6e1b6f0d6e0');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10var wpt = new WebPageTest('www.webpagetest.org', 'A.0d3b0e9b6c9e6f1d6e0d6e1b6f0d6e0');11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('wpt');18var wpt = new WebPageTest('www.webpagetest.org', 'A.0d3b0e9b6c9e6f1d6e0d6e1b6f0d6e0');19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wpt = require('wpt');26var wpt = new WebPageTest('www.webpagetest.org', 'A.0d3b0e9b6c9e6f1d6e0d6e1b6f0d6e0');27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wpt = require('wpt');34var wpt = new WebPageTest('www.webpagetest.org', 'A.0d3b0e9b6c9e6f1d6e0d6e
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!!