How to use streamBuffer method in Cypress

Best JavaScript code snippet using cypress

serialize.js

Source:serialize.js Github

copy

Full Screen

1/*2 JS Binary Data3 Copyright (c) 2016 - 2021 Cédric Ronvel4 The MIT License (MIT)5 Permission is hereby granted, free of charge, to any person obtaining a copy6 of this software and associated documentation files (the "Software"), to deal7 in the Software without restriction, including without limitation the rights8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell9 copies of the Software, and to permit persons to whom the Software is10 furnished to do so, subject to the following conditions:11 The above copyright notice and this permission notice shall be included in all12 copies or substantial portions of the Software.13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE16 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,18 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE19 SOFTWARE.20*/21"use strict" ;22const StreamBuffer = require( 'stream-kit/lib/StreamBuffer.js' ) ;23const ClassMap = require( './ClassMap.js' ) ;24const common = require( './common.js' ) ;25//function noop() {}26async function serialize( stream , v , options ) {27 options = options || {} ;28 var classMap = options.classMap ;29 if ( classMap && ! ( classMap instanceof ClassMap ) ) { classMap = new ClassMap( classMap ) ; }30 var runtime = {31 streamBuffer: StreamBuffer.create( stream ) ,32 universal: options.universal ,33 classMap: classMap ,34 autoInstance: options.autoInstance ,35 prototypeChain: options.prototypeChain ,36 refCount: 0 ,37 refs: new WeakMap()38 } ;39 await serializeAnyType( v , runtime ) ;40 //console.log( "After serialize/serializeAnyType" ) ;41 await runtime.streamBuffer.flush() ;42 //console.log( "After flush" ) ;43}44module.exports = serialize ;45async function serializeAnyType( v , runtime ) {46 switch ( v ) {47 case undefined :48 await runtime.streamBuffer.writeUInt8( common.TYPE_UNDEFINED ) ;49 return ;50 case null :51 await runtime.streamBuffer.writeUInt8( common.TYPE_NULL ) ;52 return ;53 case true :54 await runtime.streamBuffer.writeUInt8( common.TYPE_TRUE ) ;55 return ;56 case false :57 await runtime.streamBuffer.writeUInt8( common.TYPE_FALSE ) ;58 return ;59 // Prototype constants60 case Object.prototype :61 await runtime.streamBuffer.writeUInt8( common.TYPE_OBJECT_PROTOTYPE ) ;62 return ;63 }64 switch ( typeof v ) {65 case 'number' :66 await serializeNumber( v , runtime ) ;67 return ;68 case 'string' :69 await serializeString( v , runtime ) ;70 return ;71 case 'object' :72 await serializeAnyObject( v , runtime ) ;73 return ;74 case 'function' :75 await serializeFunction( v , runtime ) ;76 return ;77 }78 // Unsupported data79 await runtime.streamBuffer.writeUInt8( common.TYPE_UNSUPPORTED ) ;80}81async function serializeNumber( v , runtime ) {82 // We could store anything in the "number" type, but this way it takes more space than JSON (8 bytes per number).83 // Instead, we try to detect if a number is an integer to use the appropriate binary type.84 if ( v === 0 ) {85 await runtime.streamBuffer.writeUInt8( common.TYPE_ZERO ) ;86 }87 else if ( v === 1 ) {88 await runtime.streamBuffer.writeUInt8( common.TYPE_ONE ) ;89 }90 else if ( ! isFinite( v ) || v !== Math.round( v ) ) {91 // Floating point number92 await runtime.streamBuffer.writeUInt8( common.TYPE_NUMBER ) ;93 await runtime.streamBuffer.writeNumber( v ) ;94 }95 else if ( v >= 0 ) {96 if ( v <= 255 ) {97 await runtime.streamBuffer.writeUInt8( common.TYPE_UINT8 ) ;98 await runtime.streamBuffer.writeUInt8( v ) ;99 }100 else if ( v <= 65535 ) {101 await runtime.streamBuffer.writeUInt8( common.TYPE_UINT16 ) ;102 await runtime.streamBuffer.writeUInt16( v ) ;103 }104 else if ( v <= 4294967295 ) {105 await runtime.streamBuffer.writeUInt8( common.TYPE_UINT32 ) ;106 await runtime.streamBuffer.writeUInt32( v ) ;107 }108 else {109 await runtime.streamBuffer.writeUInt8( common.TYPE_NUMBER ) ;110 await runtime.streamBuffer.writeNumber( v ) ;111 }112 }113 else if ( v >= -128 ) {114 await runtime.streamBuffer.writeUInt8( common.TYPE_INT8 ) ;115 await runtime.streamBuffer.writeInt8( v ) ;116 }117 else if ( v >= -32768 ) {118 await runtime.streamBuffer.writeUInt8( common.TYPE_INT16 ) ;119 await runtime.streamBuffer.writeInt16( v ) ;120 }121 else if ( v >= -2147483648 ) {122 await runtime.streamBuffer.writeUInt8( common.TYPE_INT32 ) ;123 await runtime.streamBuffer.writeInt32( v ) ;124 }125 else {126 await runtime.streamBuffer.writeUInt8( common.TYPE_NUMBER ) ;127 await runtime.streamBuffer.writeNumber( v ) ;128 }129}130async function serializeString( v , runtime ) {131 if ( ! v ) {132 await runtime.streamBuffer.writeUInt8( common.TYPE_EMPTY_STRING ) ;133 return ;134 }135 var byteLength = Buffer.byteLength( v ) ;136 if ( byteLength <= 255 ) {137 await runtime.streamBuffer.writeUInt8( common.TYPE_STRING_LPS8_UTF8 ) ;138 await runtime.streamBuffer.writeLps8Utf8( v , byteLength ) ;139 }140 else if ( byteLength <= 65535 ) {141 await runtime.streamBuffer.writeUInt8( common.TYPE_STRING_LPS16_UTF8 ) ;142 await runtime.streamBuffer.writeLps16Utf8( v , byteLength ) ;143 }144 else {145 await runtime.streamBuffer.writeUInt8( common.TYPE_STRING_LPS32_UTF8 ) ;146 await runtime.streamBuffer.writeLps32Utf8( v , byteLength ) ;147 }148}149async function serializeFunction( v , runtime ) {150 // Of course, it doesn't work if it contains scope variable151 var s = v.toString() ;152 await runtime.streamBuffer.writeUInt8( common.TYPE_FUNCTION ) ;153 await serializeString( s , runtime ) ;154 await runtime.streamBuffer.writeUInt8( common.TYPE_CLOSE ) ;155}156async function serializeAnyObject( v , runtime ) {157 var className , classData , objectData ,158 proto = Object.getPrototypeOf( v ) ;159 var refId = runtime.refs.get( v ) ;160 if ( refId !== undefined ) {161 await runtime.streamBuffer.writeUInt8( common.TYPE_REF ) ;162 //console.log( "Ref: " , refId ) ;163 await runtime.streamBuffer.writeUInt32( refId ) ;164 return ;165 }166 if ( Array.isArray( v ) ) {167 runtime.refs.set( v , runtime.refCount ++ ) ;168 return await serializeArray( v , runtime ) ;169 }170 if ( proto === Object.prototype || proto === null ) {171 runtime.refs.set( v , runtime.refCount ++ ) ;172 return await serializeStrictObject( v , runtime ) ;173 }174 if ( proto === Set.prototype ) {175 runtime.refs.set( v , runtime.refCount ++ ) ;176 return await serializeSet( v , runtime ) ;177 }178 if ( proto === Map.prototype ) {179 runtime.refs.set( v , runtime.refCount ++ ) ;180 return await serializeMap( v , runtime ) ;181 }182 if ( proto === Date.prototype ) {183 runtime.refs.set( v , runtime.refCount ++ ) ;184 return await serializeDate( v , runtime ) ;185 }186 if ( proto === Buffer.prototype ) {187 runtime.refs.set( v , runtime.refCount ++ ) ;188 return await serializeBuffer( v , runtime ) ;189 }190 if ( runtime.classMap && ( className = runtime.classMap.prototypeMap.get( proto ) ) ) {191 classData = runtime.classMap.classes[ className ] ;192 }193 else if ( runtime.universal ) {194 classData = runtime.universal ;195 // Default className, if not provided by the universal serializer...196 if ( typeof proto.constructor === 'function' ) { className = proto.constructor.name ; }197 }198 else if ( runtime.autoInstance && typeof proto.constructor === 'function' ) {199 className = proto.constructor.name ;200 classData = proto.constructor ;201 }202 if ( classData ) {203 if ( classData.serializer ) {204 // We let .serializeConstructedInstance() handle ref, because it is possible that args === v205 //runtime.refs.set( v , runtime.refCount ++ ) ;206 objectData = classData.serializer( v ) ;207 if ( objectData && typeof objectData === 'object' ) {208 if ( ! objectData.className ) { objectData.className = className ; }209 return await serializeConstructedInstance( v , objectData , runtime ) ;210 }211 // Else we serialize it like a regular object212 }213 else {214 runtime.refs.set( v , runtime.refCount ++ ) ;215 return await serializeInstance( v , className , runtime ) ;216 }217 }218 if ( runtime.prototypeChain ) {219 //runtime.refs.set( v , runtime.refCount ++ ) ; // Nope! the prototype should be refered first!220 return await serializePrototypedObject( v , proto , runtime ) ;221 }222 runtime.refs.set( v , runtime.refCount ++ ) ;223 return await serializeStrictObject( v , runtime ) ;224}225async function serializeArray( v , runtime ) {226 var element ;227 if ( ! v.length ) {228 await runtime.streamBuffer.writeUInt8( common.TYPE_EMPTY_ARRAY ) ;229 return ;230 }231 await runtime.streamBuffer.writeUInt8( common.TYPE_ARRAY ) ;232 for ( element of v ) {233 //console.log( "Serialize" , element ) ;234 await serializeAnyType( element , runtime ) ;235 }236 await runtime.streamBuffer.writeUInt8( common.TYPE_CLOSE ) ;237 //console.log( "after close" ) ;238}239async function serializeSet( v , runtime ) {240 var element ;241 if ( ! v.size ) {242 await runtime.streamBuffer.writeUInt8( common.TYPE_EMPTY_SET ) ;243 return ;244 }245 await runtime.streamBuffer.writeUInt8( common.TYPE_SET ) ;246 for ( element of v ) {247 await serializeAnyType( element , runtime ) ;248 }249 await runtime.streamBuffer.writeUInt8( common.TYPE_CLOSE ) ;250}251async function serializeStrictObject( v , runtime ) {252 var keys , key ;253 keys = Object.keys( v ) ;254 if ( ! keys.length ) {255 await runtime.streamBuffer.writeUInt8( common.TYPE_EMPTY_OBJECT ) ;256 return ;257 }258 await runtime.streamBuffer.writeUInt8( common.TYPE_OBJECT ) ;259 for ( key of keys ) {260 await serializeAnyType( key , runtime ) ;261 await serializeAnyType( v[ key ] , runtime ) ;262 }263 await runtime.streamBuffer.writeUInt8( common.TYPE_CLOSE ) ;264}265async function serializePrototypedObject( v , proto , runtime ) {266 var keys , key ;267 keys = Object.keys( v ) ;268 await runtime.streamBuffer.writeUInt8( common.TYPE_PROTOTYPED_OBJECT ) ;269 await serializeAnyType( proto , runtime ) ;270 // Add the ref AFTER its prototype chain!271 runtime.refs.set( v , runtime.refCount ++ ) ;272 for ( key of keys ) {273 await serializeAnyType( key , runtime ) ;274 await serializeAnyType( v[ key ] , runtime ) ;275 }276 await runtime.streamBuffer.writeUInt8( common.TYPE_CLOSE ) ;277}278async function serializeMap( v , runtime ) {279 var pair ;280 if ( ! v.size ) {281 await runtime.streamBuffer.writeUInt8( common.TYPE_EMPTY_MAP ) ;282 return ;283 }284 await runtime.streamBuffer.writeUInt8( common.TYPE_MAP ) ;285 for ( pair of v ) {286 await serializeAnyType( pair[ 0 ] , runtime ) ;287 await serializeAnyType( pair[ 1 ] , runtime ) ;288 }289 await runtime.streamBuffer.writeUInt8( common.TYPE_CLOSE ) ;290}291async function serializeInstance( v , className , runtime ) {292 var keys , key ;293 keys = Object.keys( v ) ;294 if ( ! keys.length ) {295 await runtime.streamBuffer.writeUInt8( common.TYPE_EMPTY_INSTANCE ) ;296 await serializeString( className , runtime ) ;297 return ;298 }299 await runtime.streamBuffer.writeUInt8( common.TYPE_INSTANCE ) ;300 await serializeString( className , runtime ) ;301 for ( key of keys ) {302 await serializeAnyType( key , runtime ) ;303 await serializeAnyType( v[ key ] , runtime ) ;304 }305 await runtime.streamBuffer.writeUInt8( common.TYPE_CLOSE ) ;306}307async function serializeConstructedInstance( v , objectData , runtime ) {308 var keys , key , override ,309 instanceId = runtime.refCount ++ ;310 await runtime.streamBuffer.writeUInt8( common.TYPE_CONSTRUCTED_INSTANCE ) ;311 await serializeString( objectData.className , runtime ) ;312 await serializeAnyType( Array.isArray( objectData.args ) ? objectData.args : null , runtime ) ;313 // We should set the ref ONCE the constructor args is sent, not before,314 // because it is possible that args === v315 runtime.refs.set( v , instanceId ) ;316 if ( objectData.overrideKeys ) {317 override = objectData.override && typeof objectData.override === 'object' ? objectData.override : v ;318 for ( key of objectData.overrideKeys ) {319 if ( Object.prototype.hasOwnProperty.call( override , key ) ) {320 await serializeAnyType( key , runtime ) ;321 await serializeAnyType( override[ key ] , runtime ) ;322 }323 }324 }325 else if ( objectData.override && typeof objectData.override === 'object' ) {326 keys = Object.keys( objectData.override ) ;327 for ( key of keys ) {328 await serializeAnyType( key , runtime ) ;329 await serializeAnyType( objectData.override[ key ] , runtime ) ;330 }331 }332 await runtime.streamBuffer.writeUInt8( common.TYPE_CLOSE ) ;333}334async function serializeDate( v , runtime ) {335 await runtime.streamBuffer.writeUInt8( common.TYPE_DATE ) ;336 await runtime.streamBuffer.writeNumber( v.getTime() ) ;337}338async function serializeBuffer( v , runtime ) {339 await runtime.streamBuffer.writeUInt8( common.TYPE_BUFFER ) ;340 await runtime.streamBuffer.writeUInt32( v.length ) ;341 await runtime.streamBuffer.write( v ) ;...

Full Screen

Full Screen

unserialize.js

Source:unserialize.js Github

copy

Full Screen

1/*2 JS Binary Data3 Copyright (c) 2016 - 2021 Cédric Ronvel4 The MIT License (MIT)5 Permission is hereby granted, free of charge, to any person obtaining a copy6 of this software and associated documentation files (the "Software"), to deal7 in the Software without restriction, including without limitation the rights8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell9 copies of the Software, and to permit persons to whom the Software is10 furnished to do so, subject to the following conditions:11 The above copyright notice and this permission notice shall be included in all12 copies or substantial portions of the Software.13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE16 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,18 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE19 SOFTWARE.20*/21"use strict" ;22const StreamBuffer = require( 'stream-kit/lib/StreamBuffer.js' ) ;23const ClassMap = require( './ClassMap.js' ) ;24const Unknown = require( './Unknown.js' ) ;25const common = require( './common.js' ) ;26async function unserialize( stream , options , context ) {27 options = options || {} ;28 var classMap = options.classMap ;29 if ( classMap && ! ( classMap instanceof ClassMap ) ) { classMap = new ClassMap( classMap ) ; }30 var runtime = {31 streamBuffer: StreamBuffer.create( stream ) ,32 universal: options.universal ,33 classMap: classMap ,34 context: context ,35 enableUnknown: !! options.enableUnknown ,36 enableFunction: !! options.enableFunction ,37 refCount: 0 ,38 refs: []39 } ;40 return await unserializeData( runtime ) ;41}42module.exports = unserialize ;43async function unserializeData( runtime ) {44 runtime.refCount = 0 ;45 runtime.refs.length = 0 ;46 var type = await runtime.streamBuffer.readUInt8() ;47 return await unserializeAnyType( runtime , type ) ;48}49async function unserializeAnyType( runtime , type ) {50 var object ;51 switch ( type ) {52 // Constants53 case common.TYPE_UNDEFINED :54 return undefined ;55 case common.TYPE_NULL :56 return null ;57 case common.TYPE_TRUE :58 return true ;59 case common.TYPE_FALSE :60 return false ;61 case common.TYPE_ZERO :62 return 0 ;63 case common.TYPE_ONE :64 return 1 ;65 // Prototype constants66 case common.TYPE_OBJECT_PROTOTYPE :67 return Object.prototype ;68 // Numbers69 case common.TYPE_NUMBER :70 return await runtime.streamBuffer.readNumber() ;71 case common.TYPE_UINT8 :72 return await runtime.streamBuffer.readUInt8() ;73 case common.TYPE_UINT16 :74 return await runtime.streamBuffer.readUInt16() ;75 case common.TYPE_UINT32 :76 return await runtime.streamBuffer.readUInt32() ;77 case common.TYPE_INT8 :78 return await runtime.streamBuffer.readInt8() ;79 case common.TYPE_INT16 :80 return await runtime.streamBuffer.readInt16() ;81 case common.TYPE_INT32 :82 return await runtime.streamBuffer.readInt32() ;83 // Strings84 case common.TYPE_EMPTY_STRING :85 return '' ;86 case common.TYPE_STRING_LPS8_UTF8 :87 return await runtime.streamBuffer.readLps8Utf8() ;88 case common.TYPE_STRING_LPS16_UTF8 :89 return await runtime.streamBuffer.readLps16Utf8() ;90 case common.TYPE_STRING_LPS32_UTF8 :91 return await runtime.streamBuffer.readLps32Utf8() ;92 // Arrays and the like93 case common.TYPE_EMPTY_ARRAY :94 object = [] ;95 runtime.refs[ runtime.refCount ++ ] = object ;96 return object ;97 case common.TYPE_ARRAY :98 return await unserializeArray( runtime ) ;99 case common.TYPE_EMPTY_SET :100 object = new Set() ;101 runtime.refs[ runtime.refCount ++ ] = object ;102 return object ;103 case common.TYPE_SET :104 return await unserializeSet( runtime ) ;105 // Objects and the like106 case common.TYPE_EMPTY_OBJECT :107 object = {} ;108 runtime.refs[ runtime.refCount ++ ] = object ;109 return object ;110 case common.TYPE_OBJECT :111 return await unserializeStrictObject( runtime ) ;112 case common.TYPE_EMPTY_MAP :113 object = new Map() ;114 runtime.refs[ runtime.refCount ++ ] = object ;115 return object ;116 case common.TYPE_MAP :117 return await unserializeMap( runtime ) ;118 case common.TYPE_EMPTY_INSTANCE :119 return await unserializeInstance( runtime , true ) ;120 case common.TYPE_INSTANCE :121 return await unserializeInstance( runtime ) ;122 case common.TYPE_CONSTRUCTED_INSTANCE :123 return await unserializeConstructedInstance( runtime ) ;124 case common.TYPE_PROTOTYPED_OBJECT :125 return await unserializePrototypedObject( runtime ) ;126 // Built-in Objects (Date, Buffers, ...)127 case common.TYPE_FUNCTION :128 return unserializeFunction( runtime ) ;129 // Built-in Objects (Date, Buffers, ...)130 case common.TYPE_DATE :131 return await unserializeDate( runtime ) ;132 case common.TYPE_BUFFER :133 return await unserializeBuffer( runtime ) ;134 // Misc135 case common.TYPE_REF :136 return await unserializeRef( runtime ) ;137 case common.TYPE_UNSUPPORTED :138 return undefined ;139 case common.TYPE_CLOSE :140 throw new Error( "Unexpected close" ) ;141 default :142 throw new Error( "Not supported yet: 0x" + type.toString( 16 ) ) ;143 }144}145async function unserializeFunction( runtime ) {146 var type , str ;147 type = await runtime.streamBuffer.readUInt8() ;148 str = await unserializeAnyType( runtime , type ) ;149 type = await runtime.streamBuffer.readUInt8() ;150 if ( type !== common.TYPE_CLOSE ) {151 throw new Error( 'unserializeFunction(): Missing close' ) ;152 }153 if ( ! runtime.enableFunction ) { return ; }154 // new Function need the body of a function, and argument beforehand...155 // So this trick creates a function returning our serialized function declaration and execute it right away.156 return new Function( 'return ( ' + str + ' ) ;' )() ;157}158async function unserializeArray( runtime ) {159 var type , array = [] ;160 runtime.refs[ runtime.refCount ++ ] = array ;161 while ( ( type = await runtime.streamBuffer.readUInt8() ) !== common.TYPE_CLOSE ) {162 //console.log( "Type: 0x" + type.toString( 16 ) ) ;163 array.push( await unserializeAnyType( runtime , type ) ) ;164 }165 return array ;166}167async function unserializeSet( runtime ) {168 var type , set_ = new Set() ;169 runtime.refs[ runtime.refCount ++ ] = set_ ;170 while ( ( type = await runtime.streamBuffer.readUInt8() ) !== common.TYPE_CLOSE ) {171 set_.add( await unserializeAnyType( runtime , type ) ) ;172 }173 return set_ ;174}175async function unserializeStrictObject( runtime ) {176 var object = {} ;177 runtime.refs[ runtime.refCount ++ ] = object ;178 await unserializeKV( runtime , object ) ;179 return object ;180}181async function unserializePrototypedObject( runtime ) {182 var type = await runtime.streamBuffer.readUInt8() ;183 var prototype = await unserializeAnyType( runtime , type ) ;184 var object = Object.create( prototype ) ;185 runtime.refs[ runtime.refCount ++ ] = object ;186 await unserializeKV( runtime , object ) ;187 return object ;188}189async function unserializeMap( runtime ) {190 var map = new Map() ;191 runtime.refs[ runtime.refCount ++ ] = map ;192 await unserializeMapKV( runtime , map ) ;193 return map ;194}195async function unserializeInstance( runtime , emptyInstance ) {196 var type , className , classData , object ;197 type = await runtime.streamBuffer.readUInt8() ;198 if ( type & common.STRING_MASK !== common.STRING_MASK ) {199 throw new Error( 'unserializeInstance(): Bad class name - not a string' ) ;200 }201 className = await unserializeAnyType( runtime , type ) ;202 if ( ! runtime.classMap || ! ( classData = runtime.classMap.classes[ className ] ) || ! classData.prototype ) {203 if ( runtime.enableUnknown ) {204 classData = Unknown ;205 }206 else {207 throw new Error( "unserializeInstance(): Cannot unserialize instances - class or prototype '" + className + "' not found in classMap" ) ;208 }209 }210 object = Object.create( classData.prototype ) ;211 if ( classData === Unknown ) {212 object.__className__ = className ;213 }214 runtime.refs[ runtime.refCount ++ ] = object ;215 if ( ! emptyInstance ) {216 await unserializeKV( runtime , object ) ;217 }218 return object ;219}220async function unserializeConstructedInstance( runtime ) {221 var type , className , classData , constructorFn , useNew , object , args ,222 instanceId = runtime.refCount ++ ;223 type = await runtime.streamBuffer.readUInt8() ;224 if ( type & common.STRING_MASK !== common.STRING_MASK ) {225 throw new Error( 'unserializeConstructedInstance(): Bad class name - not a string' ) ;226 }227 className = await unserializeAnyType( runtime , type ) ;228 if ( ! runtime.classMap || ! ( classData = runtime.classMap.classes[ className ] ) || ! classData.prototype ) {229 if ( runtime.universal ) {230 classData = runtime.universal ;231 }232 else if ( runtime.enableUnknown ) {233 classData = Unknown ;234 }235 else {236 throw new Error( "unserializeConstructedInstance(): Cannot unserialize instances - class or prototype '" + className + "' not found in classMap" ) ;237 }238 }239 if ( typeof classData.unserializer === 'function' ) {240 constructorFn = classData.unserializer ;241 useNew = classData.useNew !== undefined ? !! classData.useNew : false ;242 }243 else if ( typeof classData === 'function' ) {244 constructorFn = classData ;245 useNew = classData.useNew !== undefined ? !! classData.useNew : true ;246 }247 else {248 throw new Error( "unserializeConstructedInstance(): No constructor" ) ;249 }250 type = await runtime.streamBuffer.readUInt8() ;251 args = await unserializeAnyType( runtime , type ) ;252 //console.log( "Got args:" , args ) ;253 if ( ! Array.isArray( args ) ) {254 args = [] ;255 }256 if ( classData.unserializeClassName ) {257 args.unshift( className ) ;258 }259 if ( classData.unserializeContext ) {260 args.unshift( runtime.context ) ;261 }262 if ( useNew ) {263 //console.log( "@@@ With new" ) ;264 object = new constructorFn( ... args ) ;265 }266 else {267 //console.log( "@@@ Without new" ) ;268 object = constructorFn( ... args ) ;269 }270 runtime.refs[ instanceId ] = object ;271 await unserializeKV( runtime , object ) ;272 // Some class require some final operation *AFTER* override273 if ( classData.unserializeFinalizer ) {274 //classData.unserializeFinalizer( object ) ;275 classData.unserializeFinalizer( object , runtime.context , className ) ;276 }277 return object ;278}279async function unserializeKV( runtime , object ) {280 var type , key , value ;281 while ( ( type = await runtime.streamBuffer.readUInt8() ) !== common.TYPE_CLOSE ) {282 if ( type & common.STRING_MASK !== common.STRING_MASK ) {283 throw new Error( 'unserializeKV(): Bad key - not a string' ) ;284 }285 key = await unserializeAnyType( runtime , type ) ;286 type = await runtime.streamBuffer.readUInt8() ;287 if ( type === common.TYPE_CLOSE ) {288 throw new Error( 'unserializeKV(): Closing object after key/before value' ) ;289 }290 value = await unserializeAnyType( runtime , type ) ;291 //console.log( "KV:" , key , value ) ;292 object[ key ] = value ;293 }294}295async function unserializeMapKV( runtime , map ) {296 var type , key , value ;297 while ( ( type = await runtime.streamBuffer.readUInt8() ) !== common.TYPE_CLOSE ) {298 key = await unserializeAnyType( runtime , type ) ;299 type = await runtime.streamBuffer.readUInt8() ;300 if ( type === common.TYPE_CLOSE ) {301 throw new Error( 'unserializeMapKV(): Closing map after key/before value' ) ;302 }303 value = await unserializeAnyType( runtime , type ) ;304 //console.log( "KV:" , key , value ) ;305 map.set( key , value ) ;306 }307}308async function unserializeDate( runtime ) {309 var date = new Date( await runtime.streamBuffer.readNumber() ) ;310 runtime.refs[ runtime.refCount ++ ] = date ;311 return date ;312}313async function unserializeBuffer( runtime ) {314 var size = await runtime.streamBuffer.readUInt32() ;315 var buffer = await runtime.streamBuffer.read( size ) ;316 runtime.refs[ runtime.refCount ++ ] = buffer ;317 return buffer ;318}319async function unserializeRef( runtime ) {320 var index = await runtime.streamBuffer.readUInt32() ;321 if ( index >= runtime.refs.length ) {322 throw new Error( "unserializeRef(): Bad ref - index out of range" ) ;323 }324 return runtime.refs[ index ] ;...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

1const test = require('aqa');2const StreamBuffer = require('./streambuf');3test('initializers', t => {4 var sb1 = new StreamBuffer(Buffer.from([1])); 5 t.true(sb1 instanceof StreamBuffer);6 7 var sb2 = StreamBuffer(Buffer.from([2])); 8 t.true(sb2 instanceof StreamBuffer);9 10 var buffer = Buffer.from([0,1]);11 var sb3 = StreamBuffer(buffer);12 var sb4 = StreamBuffer(sb3);13 14 t.false(sb3 == sb4);15 t.true(sb3.buffer == sb4.buffer);16});17test('buffer access', t => {18 var source = [0, 1, 2, 3, 4, 5, 6, 7];19 var buffer = Buffer.from(source);20 var sb = StreamBuffer(buffer);21 22 // The buffer isn't copied23 t.is(sb.buffer, buffer); 24 25 // The 'buffer' property should be read-only 26 sb.buffer = Buffer.from([1,2,3]);27 28 t.true(sb.buffer.equals(Buffer.from(source))); 29});30test('buffer access - strict', t => {31 'use strict';32 var buffer = Buffer.from([0, 1, 2, 3, 4, 5, 6, 7]);33 var sb = StreamBuffer(buffer);34 35 // The buffer isn't copied36 t.is(sb.buffer, buffer); 37 38 // The 'buffer' property should be read-only39 t.throws(() => {40 sb.buffer = Buffer.from([1,2,3]);41 }, {instanceOf: TypeError});42 43});44test('read part of the buffer', t => {45 var buffer = Buffer.from([1,2,3,4,5,6,7,8]);46 var sb = StreamBuffer(buffer); 47 48 var ssb = sb.read(3);49 t.true(ssb instanceof StreamBuffer); // the read sub buffer should also be a StreamBuffer instance50 ssb.seek(1);51 t.is(ssb.readByte(), 2);52 53 t.true(sb.read(4).buffer.equals(Buffer.from([4,5,6,7])) );54 t.true(sb.read(2).buffer.equals(Buffer.from([8])) ); // read beyond the length55}); 56test('write', t => {57 var buffer = Buffer.from([0, 0, 0, 0]);58 var sb = StreamBuffer(buffer); 59 60 sb.write(Buffer.from([1, 2]));61 sb.write(Buffer.from([3, 4]));62 t.true(sb.buffer.equals(Buffer.from([1, 2, 3, 4])));63});64test('skip', t => {65 var buffer = Buffer.from([0x68, 0x65, 0x6c, 0x6c, 0x6f]); // h, e, l, l, o66 var sb = StreamBuffer(buffer);67 sb.skip(1);68 t.is(sb.readChar(), 'e');69 sb.skip(2);70 t.is(sb.readChar(), 'o');71 sb.skip(20);72 t.is(sb.readChar(), '');73});74test('skip - skip to before 0', t => {75 var buffer = Buffer.from([0x68, 0x65, 0x6c, 0x6c, 0x6f]); // h, e, l, l, o76 var sb = StreamBuffer(buffer);77 sb.skip(-1);78 t.is(sb.readString(5), 'hello');79 80});81test('read string (unknown length)', t => {82 var buffer = Buffer.from([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0, 0x68, 0x69, 0x21]); // h, e, l, l, o, (zero), h, i, !83 var sb = StreamBuffer(buffer);84 t.is(sb.readString(), 'hello'); // read until a 0 is encountered85 t.is(sb.tell(), 6); // position should point to 0x68, the 0 should have been gobbled86 t.is(sb.readString(), 'hi!'); 87});88test('read string (known length)', t => {89 var buffer = Buffer.from([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0, 0x68, 0x69, 0x21]); // h, e, l, l, o, (zero), h, i, !90 var sb = StreamBuffer(buffer);91 t.is(sb.readString(5), 'hello');92 t.is(sb.tell(), 5); // position should point to the 0 entry93 sb.skip(1);94 t.is(sb.readString(2), 'hi');95 96});97test('read strings (mixed encodings)', t => {98 var buffer = Buffer.from([0x9a,0x03, 0x91,0x03, 0xa3,0x03, 0xa3,0x03, 0x95,0x03, 0, 0x68, 0x69, 0x21 ]); 99 var sb = StreamBuffer(buffer);100 101 t.is(sb.readString(null, 'ucs2'), 'ΚΑΣΣΕ');102 t.is(sb.tell(), 11);103 t.is(sb.readString(), 'hi!');104});105test('read strings (multibyte utf8)', t => {106 var buffer = Buffer.from([0xF0, 0x9F, 0x98, 0x83, 0, 0x68, 0x69, 0x21 ]); 107 var sb = StreamBuffer(buffer);108 109 t.is(sb.readString(), '😃');110 t.is(sb.tell(), 5);111 t.is(sb.readString(), 'hi!');112});113test('readString7', t => {114 var buffer = Buffer.from([3, 0x68, 0x69, 0x21]);115 var sb = StreamBuffer(buffer);116 117 t.is(sb.readString7(), 'hi!');118});119test('writeString7', t => {120 var buffer = Buffer.alloc(4);121 var sb = StreamBuffer(buffer);122 123 sb.writeString7('hi!');124 t.deepEqual(buffer, Buffer.from([3, 0x68, 0x69, 0x21]));125});126 127test('read unsigned integers', t => {128 var buffer = Buffer.from([0x01, 0x02, 0x03, 0x04]);129 var sb = StreamBuffer(buffer);130 131 t.is(sb.readUInt8(), buffer.readUInt8());132 t.is(sb.readUInt8(), buffer.readUInt8(1));133 t.is(sb.readUInt8(), buffer.readUInt8(2));134 t.is(sb.readUInt8(), buffer.readUInt8(3));135 sb.rewind();136 137 t.is(sb.readByte(), buffer.readUInt8());138 t.is(sb.readByte(), buffer.readUInt8(1));139 t.is(sb.readByte(), buffer.readUInt8(2));140 t.is(sb.readByte(), buffer.readUInt8(3));141 sb.rewind();142 143 t.is(sb.readUInt16LE(), buffer.readUInt16LE());144 t.is(sb.readUInt16LE(), buffer.readUInt16LE(2));145 sb.rewind();146 147 t.is(sb.readUInt16BE(), buffer.readUInt16BE()); 148 t.is(sb.readUInt16BE(), buffer.readUInt16BE(2)); 149 sb.rewind();150 151 t.is(sb.readUInt32LE(), buffer.readUInt32LE());152 sb.rewind(); 153 t.is(sb.readUInt32BE(), buffer.readUInt32BE()); 154 sb.rewind();155}); 156test('read signed integers', t => {157 var buffer = Buffer.from([0xff, 0x01, 0x7f, 0x80]);158 var sb = StreamBuffer(buffer);159 160 t.is(sb.readInt8(), buffer.readInt8());161 t.is(sb.readInt8(), buffer.readInt8(1));162 t.is(sb.readInt8(), buffer.readInt8(2));163 t.is(sb.readInt8(), buffer.readInt8(3));164 sb.rewind();165 166 t.is(sb.readInt16LE(), buffer.readInt16LE()); 167 t.is(sb.readInt16LE(), buffer.readInt16LE(2)); 168 sb.rewind();169 170 t.is(sb.readInt16BE(), buffer.readInt16BE()); 171 t.is(sb.readInt16BE(), buffer.readInt16BE(2)); 172 sb.rewind();173 174 t.is(sb.readInt32LE(), buffer.readInt32LE());175 sb.rewind();176 177 t.is(sb.readInt32BE(), buffer.readInt32BE());178 sb.rewind();179}); 180test('read floating point numbers', t => {181 var buffer = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);182 var sb = StreamBuffer(buffer);183 184 t.is(sb.readFloatLE(), buffer.readFloatLE());185 t.is(sb.readFloatLE(), buffer.readFloatLE(4));186 sb.rewind();187 188 t.is(sb.readFloatBE(), buffer.readFloatBE());189 t.is(sb.readFloatBE(), buffer.readFloatBE(4));190 sb.rewind();191 192 t.is(sb.readDoubleLE(), buffer.readDoubleLE());193 sb.rewind();194 195 t.is(sb.readDoubleBE(), buffer.readDoubleBE());196 sb.rewind();197 198});199test('read 7bit encoded ints (like those used by .NET)', t => {200 var buffer = Buffer.from([2, 0x80,2, 0x80,0x80,2, 1|0x80, 2]);201 var sb = StreamBuffer(buffer);202 203 t.is(sb.read7BitInt(), 2);204 t.is(sb.read7BitInt(), 256); // 2 << 7205 t.is(sb.read7BitInt(), 32768); // 2 << 14206 t.is(sb.read7BitInt(), 257); // 1 + (2 << 7)207});208test('correct position increase (numeric read methods)', t => {209 var buffer = Buffer.from([0, 1, 2, 3, 4, 5, 6, 7]);210 var sb = StreamBuffer(buffer);211 212 var methods = [213 [sb.readInt8, 1],214 [sb.readInt16LE, 2],215 [sb.readInt16BE, 2],216 [sb.readInt32LE, 4],217 [sb.readInt32BE, 4],218 [sb.readUInt8, 1],219 [sb.readByte, 1],220 [sb.readUInt16LE, 2],221 [sb.readUInt16BE, 2],222 [sb.readUInt32LE, 4],223 [sb.readUInt32BE, 4],224 [sb.readFloatLE, 4],225 [sb.readFloatBE, 4],226 [sb.readDoubleLE, 8],227 [sb.readDoubleBE, 8],228 ];229 230 methods.forEach(m => {231 let [method, len] = m;232 method();233 234 t.is(sb.getPos(), len);235 sb.rewind();236 })237 238});239test('write numbers', t => {240 var buffer = Buffer.alloc(8);241 var sb = StreamBuffer(buffer);242 243 sb.writeUInt8(1);244 sb.writeUInt8(2);245 sb.writeUInt8(3);246 sb.writeUInt8(255);247 sb.writeUInt32BE(0xaabbccdd);248 249 t.true(buffer.equals(Buffer.from([1,2,3,255, 0xaa, 0xbb, 0xcc, 0xdd])));250});251test('write floating point numbers', t => {252 var buffer = Buffer.alloc(8);253 var sb = StreamBuffer(buffer);254 255 sb.writeFloatLE(123); // Why not test it with something like 123.4? Because it gets read back as 123.4000015258789256 sb.writeFloatLE(456);257 sb.rewind(); 258 259 t.is(sb.readFloatLE(), 123);260 t.is(sb.readFloatLE(), 456);261 sb.rewind();262 263 sb.writeDoubleLE(58008.80085);264 sb.rewind(); 265 266 t.is(sb.readDoubleLE(), 58008.80085);267});268test('write 7bit encoded ints (like those used by .NET)', t => {269 var buffer = Buffer.alloc(8); 270 var sb = StreamBuffer(buffer);271 272 sb.write7BitInt(2);273 sb.write7BitInt(256);274 sb.write7BitInt(32768);275 sb.write7BitInt(257);276 sb.rewind();277 278 t.is(sb.readByte(), 2);279 t.is(sb.readByte(), 0x80);280 t.is(sb.readByte(), 2);281 t.is(sb.readByte(), 0x80);282 t.is(sb.readByte(), 0x80);283 t.is(sb.readByte(), 2);284 t.is(sb.readByte(), 0x81);285 t.is(sb.readByte(), 2);286 sb.rewind();287 288 t.is(sb.read7BitInt(), 2);289 t.is(sb.read7BitInt(), 256); // 2 << 7290 t.is(sb.read7BitInt(), 32768); // 2 << 14291 t.is(sb.read7BitInt(), 257); // 1 + (2 << 7)292});293test('write strings', t => {294 var buffer = Buffer.alloc(6);295 var sb = StreamBuffer(buffer);296 297 sb.writeString('hel');298 sb.writeString('lo');299 t.is(sb.isEOF(), false);300 t.true(buffer.equals(Buffer.from([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0])));301});302test('write multibyte utf8 strings', t => {303 var buffer = Buffer.alloc(4);304 var sb = StreamBuffer(buffer);305 306 sb.writeString('😃');307 t.is(sb.tell(), 4);308 t.is(sb.isEOF(), true);309 310 t.true(buffer.equals(Buffer.from([0xF0, 0x9F, 0x98, 0x83])));311});312test('write mixed encoded strings', t => {313 var buffer = Buffer.alloc(14);314 var sb = StreamBuffer(buffer);315 316 sb.writeString('ΚΑΣΣΕ', 'ucs2'); 317 t.is(sb.tell(), 10);318 sb.writeByte(0);319 320 sb.writeString('hi!');321 sb.rewind();322 323 t.is(sb.readString(null, 'ucs2'), 'ΚΑΣΣΕ');324 t.is(sb.readString(null, 'utf8'), 'hi!'); 325});326test('sbyte', t => {327 var buffer = Buffer.alloc(1);328 var sb = StreamBuffer(buffer);329 330 sb.writeByte(128)331 sb.rewind();332 t.is(sb.readSByte(), -128)333});334test('writeChar', t => {335 var buffer = Buffer.alloc(2);336 var sb = StreamBuffer(buffer);337 338 sb.writeChar('h');339 sb.writeChar('i');340 t.deepEqual(buffer, Buffer.from([0x68, 0x69]));341});342test('writeChar - multibyte utf8 strings', t => {343 var buffer = Buffer.alloc(4);344 var sb = StreamBuffer(buffer);345 346 sb.writeChar('ë');347 t.deepEqual(buffer, Buffer.from([0, 0, 0, 0]));348});349test('isEOF tests', t => {350 var buffer = Buffer.from([0, 1, 2]);351 var sb = StreamBuffer(buffer);352 353 t.is(sb.tell(), 0);354 t.false(sb.isEOF());355 356 sb.readByte();357 t.is(sb.tell(), 1);358 t.false(sb.isEOF());359 360 sb.readByte();361 t.is(sb.tell(), 2);362 t.false(sb.isEOF());363 364 sb.readByte();365 t.is(sb.tell(), 3);366 t.true(sb.isEOF());367 368});369test('README example', t => {370 var name1 = 'abc';371 const hiscoreFile = Buffer.alloc(7);372 const hiscoreFileSb = new StreamBuffer(hiscoreFile);373 hiscoreFileSb.writeUInt32LE(name1.length);374 hiscoreFileSb.writeString(name1);375 376 // README example start377 var file = Buffer.from(hiscoreFile); // "Read" hiscore.dat378 var buffer = StreamBuffer(file); 379 let nameLength = buffer.readUInt32LE();380 let name = buffer.readString(nameLength);381 buffer.skip(-nameLength); // go back to the beginning of the name382 buffer.writeString(name.toUpperCase()); // overwrite the name in the buffer with something else 383 // README example end384 t.is(hiscoreFile.toString('utf8', 4), 'abc') // original file385 t.is(file.toString('utf8', 4), 'ABC') 386});387// Abandoned for now. 64-bit ints do not offer the wanted precision388// Math.pow(2, 63) yields 9223372036854776000, but is in fact 9223372036854775808389/*390test('read 64 bit unsigned integers', t => {391 var buffer = Buffer.from([1, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 2]);392 var sb = StreamBuffer(buffer);393 394 var a = sb.readUInt32LE();395 var b = sb.readUInt32LE();396 var uint64 = a + (b * Math.pow(2, 32));397 398 //t.is(uint64, 18446744073709552000);399 t.is(uint64, 0x02ffffffffffff01);400 sb.rewind();401 402 a = sb.readUInt32BE();403 b = sb.readUInt32BE();404 uint64 = b + (a * Math.pow(2, 32));405 406 //t.is(uint64, 18446744073709552000);407 t.is(uint64, 0x01ffffffffffff02);408 sb.rewind();409 410}); 411test('read 64 bit signed integers', t => {412 var buffer = Buffer.from([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f]);413 var sb = StreamBuffer(buffer);414 415 var a,b,int64; 416 417 a = sb.readUInt32LE();418 b = sb.readInt32LE();419 var int64 = a + (b * Math.pow(2, 32));420 421 console.log(`a=${a} b=${b} int64=${int64}`)422 423 t.is(int64, Math.pow(2, 63));424 //t.is(int64, 0x02ffffffffffff01);425}); ...

Full Screen

Full Screen

msg.js

Source:msg.js Github

copy

Full Screen

1/**2 * Copyright (C) 2015 Swift Navigation Inc.3 * Contact: Joshua Gross <josh@swift-nav.com>4 * This source is subject to the license found in the file 'LICENSE' which must5 * be distributed together with this source. All other rights reserved.6 *7 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,8 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED9 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.10 */11var Parser = require('binary-parser').Parser;12var path = require('path');13var streams = require('stream');14var SBP = require('./sbp');15var SBP_PREAMBLE = 0x55;16// Default sender ID. Intended for messages sent from the host to the device.17var SENDER_ID = 0x42;18var crc16tab = [0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,19 0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,20 0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,21 0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,22 0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,23 0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d,24 0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4,25 0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,26 0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,27 0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b,28 0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,29 0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,30 0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,31 0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49,32 0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,33 0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,34 0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f,35 0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067,36 0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,37 0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,38 0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d,39 0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,40 0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,41 0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634,42 0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab,43 0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,44 0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,45 0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92,46 0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9,47 0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,48 0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,49 0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0]50// TODO: CRC implementation and verify CRC51var mergeDict = function (dest, src) {52 for (var prop in src) {53 if (src.hasOwnProperty(prop)) {54 dest[prop] = src[prop];55 }56 }57 return dest;58};59function BufferTooShortError (message) {60 this.name = 'BufferTooShortError';61 this.message = message;62 this.stack = (new Error()).stack;63}64BufferTooShortError.prototype = Object.create(Error.prototype);65BufferTooShortError.prototype.constructor = BufferTooShortError;66function BufferCorruptError (message) {67 this.name = 'BufferCorruptError';68 this.message = message;69 this.stack = (new Error()).stack;70}71BufferCorruptError.prototype = Object.create(Error.prototype);72BufferCorruptError.prototype.constructor = BufferCorruptError;73var packages = ["acquisition", "bootload", "ext_events", "file_io", "flash", "logging", "navigation", "observation", "piksi", "settings", "system", "tracking"];74var sbpTable = packages.map(function (pkg) {75 return require(path.resolve(__dirname, "./" + pkg + ".js"));76}).reduce(function (prev, curr) {77 var numericKeysDict = {};78 Object.keys(curr).map(function (key) {79 if (parseInt(key) == key) {80 numericKeysDict[key] = curr[key];81 }82 });83 return mergeDict(prev, numericKeysDict);84}, {});85var parser = new Parser()86 .endianess('little')87 .uint8('preamble')88 .uint16('msg_type')89 .uint16('sender')90 .uint8('length')91 .buffer('payload', { length: 'length' })92 .uint16('crc');93/**94 * CRC16 implementation according to CCITT standards.95 * Based on msg.py implementation.96 */97function crc16 (buf, crc) {98 crc = crc || 0;99 for (var i = 0; i < buf.length; i++) {100 var ch = buf[i];101 crc = ((crc<<8)&0xFFFF) ^ (crc16tab[((crc>>8)&0xFF) ^ (ch&0xFF)]);102 crc &= 0xFFFF;103 }104 return crc;105}106module.exports = {107 decode: function decode (msg) {108 var sbp = parser.parse(msg);109 var msgTypeDecoder = sbpTable[sbp['msg_type']];110 if (typeof msgTypeDecoder === 'undefined') {111 console.log("Unknown message type: ", sbp['msg_type']);112 return new SBP(sbp);113 }114 return new msgTypeDecoder(sbp);115 },116 /**117 * Look for the beginning of a framed message in a stream, and parse it until the end. Verify118 * that the CRC matches the message. If the framed message is good, invoke callback. Otherwise throw message away.119 * Repeats until the stream has ended.120 *121 * Callback will be called with valid framed messages. Will not currently be called with errors.122 *123 * This corresponds to the logic in `framer.py`.124 *125 * @param stream: A Readable stream of bytes.126 * @param callback: a callback function invoked when a framed message is found and decoded in the stream.127 * @returns [parsed SBP object, Buffer]128 */129 dispatch: function dispatch (stream, callback) {130 var offset = 0;131 var streamBuffer = new Buffer(0);132 var getFramedMessage = function () {133 var headerBuf, payloadBuf;134 var preamble, msgType, sender, length, crc;135 var payloadCrc;136 // Find preamble byte137 var preamblePos;138 for (preamblePos = 0; preamblePos < streamBuffer.length; preamblePos++) {139 preamble = streamBuffer.readUInt8(preamblePos);140 if (preamble == SBP_PREAMBLE) {141 break;142 }143 }144 if (preamble != SBP_PREAMBLE) {145 throw new BufferTooShortError();146 }147 // Get msg_type, sender, length next148 if (preamblePos+6 > streamBuffer.length) {149 throw new BufferTooShortError();150 }151 headerBuf = streamBuffer.slice(preamblePos+1, preamblePos+6);152 msgType = streamBuffer.readUInt16LE(preamblePos+1);153 sender = streamBuffer.readUInt16LE(preamblePos+3);154 length = streamBuffer.readUInt8(preamblePos+5);155 // Get full payload156 // First, check payload length + CRC157 if (preamblePos+8+length > streamBuffer.length) {158 throw new BufferTooShortError();159 }160 payloadBuf = streamBuffer.slice(preamblePos+6, preamblePos+6+length);161 payloadCrc = crc16(payloadBuf, crc16(headerBuf));162 // Finally, get and verify CRC163 crc = streamBuffer.readUInt16LE(preamblePos+6+length);164 // Pull out full buffer165 var fullBuffer = streamBuffer.slice(preamblePos, preamblePos+6+length+2);166 // If the CRC looks correct, decode the full payload167 if (crc === payloadCrc) {168 // remove this chunk from the stream buffer169 streamBuffer = streamBuffer.slice(preamblePos+6+length+2);170 return [module.exports.decode(fullBuffer), fullBuffer];171 } else {172 // remove bad preamble from the stream buffer173 streamBuffer = streamBuffer.slice(preamblePos+1);174 throw new BufferCorruptError();175 }176 };177 var processData = function (data) {178 stream.pause();179 try {180 streamBuffer = Buffer.concat([streamBuffer, data]);181 if (streamBuffer.length < 2) {182 return;183 }184 var pair = getFramedMessage();185 var framedMessage = pair[0];186 var fullBuffer = pair[1];187 // If there is data left to process after a successful parse, process again188 if (streamBuffer.length > 0) {189 setTimeout(function () {190 processData(new Buffer(0));191 }, 0);192 }193 callback(null, framedMessage, fullBuffer);194 } catch (e) {195 // If the buffer was corrupt but there's more in the stream, try again immediately196 if (e instanceof BufferCorruptError && streamBuffer.length > 0) {197 setTimeout(function () {198 processData(new Buffer(0));199 }, 0);200 }201 } finally {202 offset = 0;203 stream.resume();204 }205 };206 stream.on('data', processData);207 }...

Full Screen

Full Screen

chain-spec.js

Source:chain-spec.js Github

copy

Full Screen

1const assert = require('assert');2const modulePath = './../src/index';3const logtify = require('./../src/index');4const ConsoleSubscriber = require('./../src/subscribers/console-link');5const WinstonAdapter = require('./../src/adapters/winston');6describe('Logger stream ', () => {7 beforeEach(() => {8 delete require.cache[require.resolve(modulePath)];9 });10 afterEach(() => {11 delete require.cache[require.resolve(modulePath)];12 const { streamBuffer } = logtify;13 streamBuffer.adapters = {};14 streamBuffer.subscribers = [];15 });16 before(() => {17 assert.equal(typeof logtify, 'function');18 this.NODE_ENV = process.env.NODE_ENV;19 this.CONSOLE_LOGGING = process.env.CONSOLE_LOGGING;20 this.BUGSNAG_LOGGING = process.env.BUGSNAG_LOGGING;21 this.LOGENTRIES_LOGGING = process.env.LOGENTRIES_LOGGING;22 });23 after(() => {24 process.env.NODE_ENV = this.NODE_ENV;25 process.env.CONSOLE_LOGGING = this.CONSOLE_LOGGING;26 process.env.BUGSNAG_LOGGING = this.BUGSNAG_LOGGING;27 process.env.LOGENTRIES_LOGGING = this.LOGENTRIES_LOGGING;28 });29 it('should initialize when undefined config is given ', () => {30 const logtifyInstance = logtify(undefined);31 assert(logtifyInstance);32 const { stream } = logtifyInstance;33 assert.equal(typeof stream, 'object');34 assert.equal(typeof stream.settings, 'object');35 assert.equal(typeof stream.Message, 'function');36 assert.equal(typeof stream.Subscriber, 'function');37 assert.equal(typeof stream.log, 'function');38 assert.equal(typeof stream.subscribe, 'function');39 });40 it('should initialize when null config is given ', () => {41 const logtifyInstance = logtify(null);42 assert(logtifyInstance);43 const { stream } = logtifyInstance;44 assert.equal(typeof stream, 'object');45 assert.equal(typeof stream.settings, 'object');46 assert.equal(typeof stream.Message, 'function');47 assert.equal(typeof stream.Subscriber, 'function');48 assert.equal(typeof stream.log, 'function');49 assert.equal(typeof stream.subscribe, 'function');50 });51 it('should initialize when empty config is given', () => {52 const logtifyInstance = logtify({});53 const { stream } = logtifyInstance;54 assert.equal(typeof stream, 'object');55 assert.equal(typeof stream.settings, 'object');56 assert.equal(typeof stream.Message, 'function');57 assert.equal(typeof stream.Subscriber, 'function');58 assert.equal(typeof stream.log, 'function');59 assert.equal(typeof stream.subscribe, 'function');60 });61 it('should allow user to reconfigure the module', () => {62 let logtifyInstance = logtify({ hello: 'world' });63 assert(logtifyInstance);64 assert.equal(logtifyInstance.stream.settings.hello, 'world');65 logtifyInstance = logtify({ hello: 'everyone' });66 assert.equal(logtifyInstance.stream.settings.hello, 'everyone');67 });68 it('should behave as a singleton if config was not provided', () => {69 let logtifyInstance = logtify({ hello: 'world' });70 assert(logtifyInstance);71 assert.equal(logtifyInstance.stream.settings.hello, 'world');72 logtifyInstance = logtify();73 assert(logtifyInstance);74 assert.equal(logtifyInstance.stream.settings.hello, 'world');75 });76 it('should support custom subscribers', () => {77 const { streamBuffer } = logtify;78 streamBuffer.addAdapter({79 name: 'unicorn',80 class: WinstonAdapter81 });82 streamBuffer.addSubscriber(ConsoleSubscriber);83 streamBuffer.addSubscriber(ConsoleSubscriber);84 streamBuffer.addSubscriber(ConsoleSubscriber);85 const { stream, logger, unicorn } = logtify({});86 assert(stream);87 assert(logger);88 assert(unicorn);89 assert.equal(stream.subscribersCount, 4);90 });91 it('should not let adapters override existing ones', () => {92 const { streamBuffer } = logtify;93 streamBuffer.addAdapter({94 name: 'stream',95 class: WinstonAdapter96 });97 streamBuffer.addAdapter({98 name: 'unicorn',99 class: WinstonAdapter100 });101 const { stream, logger, unicorn } = logtify({});102 assert(stream);103 assert(logger);104 assert(unicorn);105 });106 it('should be able to unbind adapter', () => {107 const { streamBuffer } = logtify;108 streamBuffer.addAdapter({109 name: 'stream',110 class: WinstonAdapter111 });112 streamBuffer.addAdapter({113 name: 'unicorn',114 class: WinstonAdapter115 });116 let { stream, unicorn } = logtify({});117 assert(stream);118 assert(unicorn);119 stream.unbindAdapter('unicorn');120 unicorn = logtify().unicorn; // eslint-disable-line121 stream = logtify().stream; // eslint-disable-line122 assert.equal(unicorn, undefined);123 assert.notEqual(stream, undefined);124 });125 it('should not be able to unbind non adapter object', () => {126 const { stream } = logtify({});127 assert(stream);128 stream.unbindAdapter('stream');129 assert(stream);130 });131 it('should skip null undefined or empty object subscriber', () => {132 const { streamBuffer } = logtify;133 streamBuffer.addSubscriber(null);134 streamBuffer.addSubscriber(undefined);135 const { stream } = logtify({});136 assert.equal(stream.subscribersCount, 1);137 });138 it('should throw if subscriber is not valid', () => {139 try {140 const { streamBuffer } = logtify;141 streamBuffer.addSubscriber({ handle: () => {} });142 logtify({});143 } catch (e) {144 assert(e instanceof Error);145 }146 });147 it('should change prototype of pre-configured subscribers', () => {148 class MySubscriber {149 constructor(settings, utility) {150 this.settings = settings;151 this.utility = utility;152 }153 handle(message) { this.next(message); }154 next() {}155 link(next) { this.nextLink = next; }156 }157 const settings = { SOME_SECRET: 'powerpuffgirls' };158 const { streamBuffer } = logtify;159 streamBuffer.addSubscriber({ config: settings, class: MySubscriber });160 const { stream } = logtify({});161 assert.equal(stream.subscribersCount, 2);162 });163 it('should not break down if null is logged (console logging is on)', () => {164 const { stream, logger } = logtify({});165 stream.log(null, null);166 assert(logger);167 });168 it('should be configured according to the preset', () => {169 const stream1 = logtify({ presets: ['dial-once'] }).stream;170 assert.equal(stream1.settings.CONSOLE_LOGGING, true);171 assert.equal(stream1.settings.BUGSNAG_LOGGING, false);172 assert.equal(stream1.settings.LOGENTRIES_LOGGING, false);173 process.env.NODE_ENV = 'staging';174 const { stream, logger } = logtify({ presets: ['dial-once'] });175 assert.equal(stream.settings.CONSOLE_LOGGING, false);176 assert.equal(stream.settings.BUGSNAG_LOGGING, true);177 assert.equal(stream.settings.LOGENTRIES_LOGGING, true);178 assert.equal(stream.subscribersCount, 1);179 assert(logger);180 assert(logger.info);181 stream.log(null, null);182 });...

Full Screen

Full Screen

stream_buffer.js

Source:stream_buffer.js Github

copy

Full Screen

...19var lodash_1 = __importDefault(require("lodash"));20var debug_1 = __importDefault(require("debug"));21var stream_1 = __importDefault(require("stream"));22var debug = debug_1.default('cypress:server:stream_buffer');23function streamBuffer(initialSize) {24 if (initialSize === void 0) { initialSize = 2048; }25 var buffer = Buffer.allocUnsafe(initialSize);26 var bytesWritten = 0;27 var finished = false;28 var onWrite = function (chunk, enc, cb) {29 if (finished || !chunk || !buffer) {30 debug('received write after deleting buffer, ignoring %o', { chunkLength: chunk && chunk.length, enc: enc });31 return cb();32 }33 if (chunk.length + bytesWritten > buffer.length) {34 var newBufferLength = buffer.length;35 while (newBufferLength < chunk.length + bytesWritten) {36 newBufferLength *= 2;37 }...

Full Screen

Full Screen

xviz-loader-interface.spec.js

Source:xviz-loader-interface.spec.js Github

copy

Full Screen

1// Copyright (c) 2019 Uber Technologies, Inc.2//3// Permission is hereby granted, free of charge, to any person obtaining a copy4// of this software and associated documentation files (the "Software"), to deal5// in the Software without restriction, including without limitation the rights6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell7// copies of the Software, and to permit persons to whom the Software is8// furnished to do so, subject to the following conditions:9//10// The above copyright notice and this permission notice shall be included in11// all copies or substantial portions of the Software.12//13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN19// THE SOFTWARE.20/* eslint-disable camelcase */21import test from 'tape-catch';22import {LOG_STREAM_MESSAGE} from '@xviz/parser';23import {_XVIZLoaderInterface} from 'streetscape.gl';24class TestStreamBuffer {25 constructor() {26 this.setCurrentTimeValue = 0;27 this.data = [];28 }29 // called on Loader.seek()30 setCurrentTime(time) {31 this.setCurrentTimeValue = time;32 }33 // called with parsed XVIZ via Loader.onXVIZMessage() with a timeslice34 insert(timeslice) {35 this.data.push(timeslice);36 }37}38class TestLoaderInterface extends _XVIZLoaderInterface {39 constructor({streamBuffer}) {40 super();41 this.streamBuffer = streamBuffer;42 }43 connect() {44 return Promise.resolve();45 }46 close() {}47}48test('XVIZLoaderInterface#loader.seek() propagates to streamBuffer', t => {49 const streamBuffer = new TestStreamBuffer();50 const loader = new TestLoaderInterface({streamBuffer});51 loader.seek(1001.1);52 t.equal(53 1001.1,54 streamBuffer.setCurrentTimeValue,55 'streamBuffer received time from seek() on loader'56 );57 t.end();58});59test('XVIZLoaderInterface#streamBuffer.insert() called on timeslice', t => {60 const streamBuffer = new TestStreamBuffer();61 const loader = new TestLoaderInterface({streamBuffer});62 loader.onXVIZMessage({type: LOG_STREAM_MESSAGE.TIMESLICE, timestamp: 1007});63 loader.onXVIZMessage({type: LOG_STREAM_MESSAGE.TIMESLICE, timestamp: 1008});64 loader.onXVIZMessage({type: LOG_STREAM_MESSAGE.TIMESLICE, timestamp: 1009});65 loader.onXVIZMessage({type: LOG_STREAM_MESSAGE.TIMESLICE, timestamp: 1010});66 t.equal(streamBuffer.data.length, 4, 'streamBuffer was populated with timeslices');67 t.end();...

Full Screen

Full Screen

StreamBuffer.js

Source:StreamBuffer.js Github

copy

Full Screen

1const assert = require('assert');2const sinon = require('sinon');3const StreamBuffer = require('../../../../kinesis/src/StreamBuffer');4describe('Stream Buffer', () => {5 it('Should emit "putBatch" event when buffer has reached maximum capacity for some stream', () => {6 const config = {7 timeout: 60000,8 maxSize: 29 };10 const data = {11 command: 'command name'12 };13 const streamBuffer = new StreamBuffer(config);14 streamBuffer.emit = sinon.spy();15 streamBuffer.put(data, 'test-stream');16 streamBuffer.put(data, 'test-stream');17 assert(streamBuffer.emit.calledOnce);18 assert(streamBuffer.emit.calledWith('putBatch', [ data, data ], 'test-stream'));19 });20 it('Should emit "putBatch" event when buffer timeout takes place', done => {21 const config = {22 timeout: 1,23 maxSize: 100024 };25 const data = {26 command: 'command name'27 };28 const streamBuffer = new StreamBuffer(config);29 streamBuffer.emit = sinon.spy();30 streamBuffer.put(data, 'test-stream');31 streamBuffer.put(data, 'test-stream');32 asyncAssertion(() => {33 assert(streamBuffer.emit.calledOnce);34 assert(streamBuffer.emit.calledWith('putBatch', [ data, data ], 'test-stream'));35 done();36 });37 });38});39function asyncAssertion(callback) {40 setTimeout(callback, 0);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const streamBuffer = require('stream-buffers')2Cypress.Commands.add('streamBuffer', () => {3 const myWritableStreamBuffer = new streamBuffer.WritableStreamBuffer({4 initialSize: (100 * 1024),5 incrementAmount: (10 * 1024)6 })7})8Cypress.Commands.add('streamBuffer', () => {9 const myWritableStreamBuffer = new streamBuffer.WritableStreamBuffer({10 initialSize: (100 * 1024),11 incrementAmount: (10 * 1024)12 })13})14Cypress.Commands.add('streamBuffer', () => {15 const myWritableStreamBuffer = new streamBuffer.WritableStreamBuffer({16 initialSize: (100 * 1024),17 incrementAmount: (10 * 1024)18 })19})20Cypress.Commands.add('streamBuffer', () => {21 const myWritableStreamBuffer = new streamBuffer.WritableStreamBuffer({22 initialSize: (100 * 1024),23 incrementAmount: (10 * 1024)24 })25})26Cypress.Commands.add('streamBuffer', () => {27 const myWritableStreamBuffer = new streamBuffer.WritableStreamBuffer({28 initialSize: (100 * 1024),29 incrementAmount: (10 * 1024)30 })31})32const streamBuffer = require('stream-buffers')33Cypress.Commands.add('streamBuffer', () => {34 const myWritableStreamBuffer = new streamBuffer.WritableStreamBuffer({35 initialSize: (100 * 1024),36 incrementAmount: (10 * 1024)37 })38})39Cypress.Commands.add('

Full Screen

Using AI Code Generation

copy

Full Screen

1import { streamBuffer } from "cypress/types/lodash";2describe('My First Test', function() {3 it('Visits the Kitchen Sink', function() {4 cy.contains('type').click()5 cy.url().should('include', '/commands/actions')6 cy.get('.action-email')7 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1import { streamBuffer } from 'cypress-file-upload';2describe('Test', () => {3 it('Upload', () => {4 const file = streamBuffer('test.pdf');5 cy.get('input[type="file"]').attachFile(file);6 });7});8import 'cypress-file-upload';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { streamBuffer } from 'cypress-stream-buffer';2describe('test', () => {3 it('test', () => {4 cy.get('input[name="q"]').type('Cypress');5 cy.get('input[value="Google Search"]').click();6 cy.get('input[name="q"]')7 .invoke('val')8 .then((val) => {9 cy.writeFile('test.txt', val);10 });11 cy.readFile('test.txt').then((val) => {12 expect(val).to.equal('Cypress');13 });14 cy.get('input[name="q"]').clear();15 cy.get('input[name="q"]').type('Cypress');16 cy.get('input[name="q"]')17 .invoke('val')18 .then((val) => {19 cy.writeFile('test.txt', val);20 });21 cy.readFile('test.txt').then((val) => {22 expect(val).to.equal('Cypress');23 });24 cy.get('input[name="q"]').clear();25 cy.get('input[name="q"]').type('Cypress');26 cy.get('input[name="q"]')27 .invoke('val')28 .then((val) => {29 cy.writeFile('test.txt', val);30 });31 cy.readFile('test.txt').then((val) => {32 expect(val).to.equal('Cypress');33 });34 });35});36import { streamBuffer } from 'cypress-stream-buffer';37Cypress.Commands.add('streamBuffer', streamBuffer);38import 'cypress-file-upload';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { streamBuffer } from "cypress-stream-buffer";2describe("test", () => {3 beforeEach(() => {4 });5 it("test", () => {6 const audio = cy.get("audio");7 audio.then((audio) => {8 const audioStream = audio[0].captureStream();9 const audioRecorder = new MediaRecorder(audioStream);10 audioRecorder.addEventListener("dataavailable", (e) => {11 streamBuffer(e.data).then((buffer) => {12 });13 });14 audioRecorder.start();15 });16 });17});

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs');2const stream = fs.createWriteStream('test.txt');3stream.write('Hello World!');4stream.end();5describe('Test', () => {6 it('test', () => {7 cy.streamBuffer('test.txt').then((buffer) => {8 });9 });10});11cy.readFile('test.txt', { encoding: 'utf8' }).then((text) => {12});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test', () => {2 it('should get the response and write it to a file', () => {3 .its('body')4 .then((body) => {5 cy.writeFile('cypress/fixtures/test.json', body);6 });7 });8});9{10}11{12}13{14}15{16}17{18}19{20}21{22}23{

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('stream buffer test', () => {2 it('stream buffer', () => {3 cy.streamBuffer({4 })5 })6})

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress 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