Best JavaScript code snippet using cypress
gta5settingsparser.js
Source:gta5settingsparser.js
1// GTA 5 settings.xml parser by Jeroen Baert2// https://github.com/Forceflow/gta5settingsparser3var $xml;4// define value -> setting translation5var DX_VERSION_SETTINGS = {};6DX_VERSION_SETTINGS["0"] = "DirectX 10";7DX_VERSION_SETTINGS["1"] = "DirectX 10.1";8DX_VERSION_SETTINGS["2"] = "DirectX 11";9var TESSELLATION_SETTINGS = {};10TESSELLATION_SETTINGS["0"] = "Off";11TESSELLATION_SETTINGS["1"] = "Normal";12TESSELLATION_SETTINGS["2"] = "High";13TESSELLATION_SETTINGS["3"] = "Very High";14var TEXTURE_QUALITY_SETTINGS = {};15TEXTURE_QUALITY_SETTINGS["0"] = "Normal";16TEXTURE_QUALITY_SETTINGS["1"] = "High";17TEXTURE_QUALITY_SETTINGS["2"] = "Very High";18var SHADER_QUALITY_SETTINGS = {};19SHADER_QUALITY_SETTINGS["0"] = "Normal";20SHADER_QUALITY_SETTINGS["1"] = "High";21SHADER_QUALITY_SETTINGS["2"] = "Very High";22var SHADOW_QUALITY_SETTINGS = {};23SHADOW_QUALITY_SETTINGS["0"] = "Low";24SHADOW_QUALITY_SETTINGS["1"] = "Normal";25SHADOW_QUALITY_SETTINGS["2"] = "High";26SHADOW_QUALITY_SETTINGS["3"] = "Very High";27var GRASS_QUALITY_SETTINGS = {};28GRASS_QUALITY_SETTINGS["0"] = "Normal";29GRASS_QUALITY_SETTINGS["1"] = "High";30GRASS_QUALITY_SETTINGS["2"] = "Very High";31GRASS_QUALITY_SETTINGS["3"] = "Ultra"; // unsure if it actually goes this far32var WATER_QUALITY_SETTINGS = {};33WATER_QUALITY_SETTINGS["0"] = "Normal";34WATER_QUALITY_SETTINGS["1"] = "High";35WATER_QUALITY_SETTINGS["2"] = "Very High";36WATER_QUALITY_SETTINGS["3"] = "Ultra"; // unsure if it actually goes this far37var PARTICLE_QUALITY_SETTINGS = {};38PARTICLE_QUALITY_SETTINGS["0"] = "Normal";39PARTICLE_QUALITY_SETTINGS["1"] = "High";40PARTICLE_QUALITY_SETTINGS["2"] = "Very High";41PARTICLE_QUALITY_SETTINGS["3"] = "Ultra"; // unsure if it actually goes this far42var REFLECTION_QUALITY_SETTINGS = {};43REFLECTION_QUALITY_SETTINGS["0"] = "Normal";44REFLECTION_QUALITY_SETTINGS["1"] = "High";45REFLECTION_QUALITY_SETTINGS["2"] = "Very High";46REFLECTION_QUALITY_SETTINGS["3"] = "Ultra"; 47var SHADOW_SHOFTSHADOWS_SETTINGS = {};48SHADOW_SHOFTSHADOWS_SETTINGS["0"] = "Sharp";49SHADOW_SHOFTSHADOWS_SETTINGS["1"] = "Soft";50SHADOW_SHOFTSHADOWS_SETTINGS["2"] = "Softer";51SHADOW_SHOFTSHADOWS_SETTINGS["3"] = "Softest";52SHADOW_SHOFTSHADOWS_SETTINGS["4"] = "AMD CHS";53SHADOW_SHOFTSHADOWS_SETTINGS["5"] = "Nvidia PCSS";54var POSTFX_SETTINGS = {};55POSTFX_SETTINGS["0"] = "Normal";56POSTFX_SETTINGS["1"] = "High";57POSTFX_SETTINGS["2"] = "Very High";58POSTFX_SETTINGS["3"] = "Ultra";59var AO_SETTINGS = {};60AO_SETTINGS["0"] = "Off";61AO_SETTINGS["1"] = "Normal";62AO_SETTINGS["2"] = "High";63var valid_xml = true;64$( document ).ready(function() {65 watcharea();66});67function watcharea(){68 $('textarea#inifile').on('change',function(){69 parse();70 });71 $('textarea#inifile').keyup(function(){72 parse();73 });74}75function parseXML() {76 valid_xml = true;77 var inifile = $('textarea#inifile').val();78 if(inifile == ""){79 valid_xml = false;80 return;81 }82 try {83 var xmlDoc = $.parseXML( inifile );84 }85 catch(err) {86 valid_xml = false;87 return;88 }89 $xml = $( xmlDoc );90}91function writeLine(line){92 $("#parsed").val($("#parsed").val() + line + " \n");93}94function writeSettings(){95 // Video card and DirectX version96 var videocard = $xml.find("VideoCardDescription").text();97 var dx_version = $xml.find("DX_Version").attr("value");98 if(dx_version in DX_VERSION_SETTINGS){99 writeLine(videocard + " - "+ DX_VERSION_SETTINGS[dx_version]);100 }101 102 // Basics: screen width and height, refresh rate, windowed mode and vsync103 var width = $xml.find("ScreenWidth").attr("value");104 var height = $xml.find("ScreenHeight").attr("value");105 var refreshrate = $xml.find("RefreshRate").attr("value");106 var windowed = $xml.find("Windowed").attr("value");107 if(windowed == 0){windowed = "Fullscreen";}else{windowed = "Windowed";}108 var vsync = $xml.find("Vsync").attr("value");109 if(vsync == 0){vsync = "No V-sync";}else{vsync = "V-sync on";}110 writeLine(width + " x " + height + ", " + refreshrate + " hz, " + windowed + ", " + vsync);111 112 // Anti-aliasing: FXAA, MSAA, TXAA113 var FXAA = $xml.find("FXAA_Enabled").attr("value");114 if(FXAA == "false" || FXAA == "0" ){FXAA = "FXAA off";}else{FXAA = "FXAA on";}115 var MSAA = $xml.find("MSAA").attr("value");116 if(MSAA != 0){ // you can only have TXAA when you have MSAA117 MSAA = "MSAA " + MSAA + "x";118 var TXAA = $xml.find("TXAA_Enabled").attr("value");119 if(TXAA == "false" || TXAA == "0"){TXAA = "TXAA off";}else{TXAA = "TXAA on";}120 writeLine(FXAA + ", " + MSAA + ", " + TXAA);121 } else {122 writeLine(FXAA + ", MSAA off");123 }124 125 // Population and distance scaling/variety126 var population_density = $xml.find("CityDensity").attr("value");127 population_density = (parseFloat(population_density) * 100).toFixed(0);128 var population_variety = $xml.find("PedVarietyMultiplier").attr("value");129 population_variety = (parseFloat(population_variety) * 100).toFixed(0);130 var distance_scaling = $xml.find("LodScale").attr("value");131 distance_scaling = (parseFloat(distance_scaling) * 100).toFixed(0);132 writeLine("Population density: " + population_density + "%");133 writeLine("Population variety: " + population_variety+ "%");134 writeLine("Distance scaling: " + distance_scaling+ "%");135 136 // Texture quality137 var texture_quality = $xml.find("TextureQuality").attr("value");138 if(texture_quality in TEXTURE_QUALITY_SETTINGS){139 writeLine("Texture quality: " + TEXTURE_QUALITY_SETTINGS[texture_quality]);140 } else {writeLine("UNKNOWN TEXTURE QUALITY");}141 142 // Shader quality143 var shader_quality = $xml.find("ShaderQuality").attr("value");144 if(shader_quality in SHADER_QUALITY_SETTINGS){145 writeLine("Shader quality: " + SHADER_QUALITY_SETTINGS[shader_quality]);146 } else {writeLine("UNKNOWN SHADER QUALITY");}147 // Shadow quality148 var shadow_quality = $xml.find("ShadowQuality").attr("value");149 if(shadow_quality in SHADOW_QUALITY_SETTINGS){150 writeLine("Shadow quality: " + SHADOW_QUALITY_SETTINGS[shadow_quality]);151 } else {writeLine("UNKNOWN SHADOW QUALITY");}152 // Reflection quality153 var reflection_quality = $xml.find("ReflectionQuality").attr("value");154 if(reflection_quality in REFLECTION_QUALITY_SETTINGS){155 writeLine("Reflection quality: " + REFLECTION_QUALITY_SETTINGS[reflection_quality]);156 } else {writeLine("UNKNOWN REFLECTION QUALITY");}157 // Reflection MSAA158 var reflection_msaa = $xml.find("ReflectionMSAA").attr("value");159 if(reflection_msaa == 0){160 writeLine("Reflection MSAA: Off");161 } else {162 writeLine("Reflection MSAA: " + reflection_msaa + "x");163 }164 // Water quality165 var water_quality = $xml.find("WaterQuality").attr("value");166 if(water_quality in WATER_QUALITY_SETTINGS){167 writeLine("Water quality: " + WATER_QUALITY_SETTINGS[water_quality]);168 } else {writeLine("UNKNOWN WATER QUALITY");}169 // Particle quality170 var particle_quality = $xml.find("ParticleQuality").attr("value");171 if(particle_quality in PARTICLE_QUALITY_SETTINGS){172 writeLine("Particle quality: " + PARTICLE_QUALITY_SETTINGS[particle_quality]);173 } else {writeLine("UNKNOWN PARTICLE QUALITY");}174 // Grass quality175 var grass_quality = $xml.find("GrassQuality").attr("value");176 if(grass_quality in GRASS_QUALITY_SETTINGS){177 writeLine("Grass quality: " + GRASS_QUALITY_SETTINGS[grass_quality]);178 } else {writeLine("UNKNOWN GRASS QUALITY");}179 // Soft shadows180 var shadow_softshadows = $xml.find("Shadow_SoftShadows").attr("value");181 if(shadow_softshadows in SHADOW_SHOFTSHADOWS_SETTINGS){182 writeLine("Soft shadows: " + SHADOW_SHOFTSHADOWS_SETTINGS[shadow_softshadows]);183 } else {writeLine("UNKNOWN SOFT SHADOW QUALITY");}184 185 // Post FX186 var postfx = $xml.find("PostFX").attr("value");187 if(postfx in POSTFX_SETTINGS){188 writeLine("Post FX: " + POSTFX_SETTINGS[postfx]);189 } else {writeLine("UNKNOWN POST FX SETTING");}190 191 // Motion Blur strength192 var motion_blur_strength = $xml.find("MotionBlurStrength").attr("value");193 motion_blur_strength = (parseFloat(motion_blur_strength) * 100).toFixed(0);194 writeLine("Motion Blur: " + motion_blur_strength + "%");195 196 // Depth Of Field197 var dof = $xml.find("DoF").attr("value");198 if(dof == "false" || dof == "0" ){writeLine("Depth of Field: Off");}else{writeLine("Depth of Field: On");}199 200 // Anisotropic Filtering201 var anisotropic_filtering = $xml.find("AnisotropicFiltering").attr("value");202 if(anisotropic_filtering == 0){203 writeLine("Anisotropic Filtering: Off");204 } else {205 writeLine("Anisotropic Filtering: " + anisotropic_filtering + "x");206 }207 208 // Ambient Occlusion209 var ao = $xml.find("SSAO").attr("value");210 if(ao in AO_SETTINGS){211 writeLine("Ambient Occlusion: " + AO_SETTINGS[ao]);212 } else {writeLine("UNKNOWN AMBIENT OCCLUSION SETTING");}213 214 // Tessellation215 var tessellation = $xml.find("Tessellation").attr("value");216 if(tessellation in TESSELLATION_SETTINGS){217 writeLine("Tessellation: " + TESSELLATION_SETTINGS[tessellation]);218 } else {writeLine("UNKNOWN TESSELLATION SETTING");}219 // Advanced graphics options220 var longshadows = $xml.find("Shadow_LongShadows").attr("value");221 if(longshadows == "true" || longshadows == 1){222 writeLine("Long Shadows: On"); 223 } else {224 writeLine("Long Shadows: Off");225 }226 227 // High resolution shadows228 var ultrashadows = $xml.find("UltraShadows_Enabled").attr("value");229 if(ultrashadows =="true" || ultrashadows == 1){230 writeLine("High Resolution Shadows: On"); 231 } else {232 writeLine("High Resolution Shadows: Off");233 }234 // High detail streaming while flying235 var flying_streaming = $xml.find("HdStreamingInFlight").attr("value");236 if(flying_streaming =="true" || flying_streaming == 1){237 writeLine("HD Streaming while Flying: On"); 238 } else {239 writeLine("HD Streaming while Flying: Off");240 }241 242 // Extended Distance Scaling243 var extended_distance_scaling = $xml.find("MaxLodScale").attr("value");244 extended_distance_scaling = (parseFloat(extended_distance_scaling) * 100).toFixed(0);245 writeLine("Extended Distance Scaling: " + extended_distance_scaling + "%");246 247 // Extended shadow distance248 var extended_shadow_distance = $xml.find("Shadow_Distance").attr("value");249 extended_shadow_distance = (parseFloat(extended_shadow_distance - 1) * 100).toFixed(0);250 writeLine("Extended Shadow Distance: " + extended_shadow_distance + "%");251 252}253function parse(){254 $("#parsed").val('');255 parseXML();256 if(!valid_xml){257 writeLine("No XML or invalid XML pasted. Make sure you paste the full contents of your settings.xml file in the area on the left!");258 return;259 }260 writeSettings();261 writeLine("Generated with Forceflow's GTA 5 settings parser");...
framer.js
Source:framer.js
1var framer = exports;2var spdy = require('../../../spdy'),3 Buffer = require('buffer').Buffer,4 protocol = require('./');5//6// ### function Framer (deflate, inflate)7// #### @deflate {zlib.Deflate} Deflate stream8// #### @inflate {zlib.Inflate} Inflate stream9// Framer constructor10//11function Framer(deflate, inflate) {12 this.version = 3;13 this.deflate = deflate;14 this.inflate = inflate;15}16exports.Framer = Framer;17//18// ### function execute (header, body, callback)19// #### @header {Object} Frame headers20// #### @body {Buffer} Frame's body21// #### @callback {Function} Continuation callback22// Parse frame (decompress data and create streams)23//24Framer.prototype.execute = function execute(header, body, callback) {25 // SYN_STREAM or SYN_REPLY26 if (header.type === 0x01 || header.type === 0x02) {27 var frame = protocol.parseSynHead(header.type, header.flags, body);28 body = body.slice(frame._offset);29 this.inflate(body, function(err, chunks, length) {30 if (err) return callback(err);31 var pairs = new Buffer(length);32 for (var i = 0, offset = 0; i < chunks.length; i++) {33 chunks[i].copy(pairs, offset);34 offset += chunks[i].length;35 }36 frame.headers = protocol.parseHeaders(pairs);37 frame.url = frame.headers.path || '';38 callback(null, frame);39 });40 // RST_STREAM41 } else if (header.type === 0x03) {42 callback(null, protocol.parseRst(body));43 // SETTINGS44 } else if (header.type === 0x04) {45 callback(null, protocol.parseSettings(body));46 } else if (header.type === 0x05) {47 callback(null, { type: 'NOOP' });48 // PING49 } else if (header.type === 0x06) {50 callback(null, { type: 'PING', pingId: body });51 // GOAWAY52 } else if (header.type === 0x07) {53 callback(null, protocol.parseGoaway(body));54 } else if (header.type === 0x09) {55 callback(null, protocol.parseWindowUpdate(body));56 } else {57 callback(null, { type: 'unknown: ' + header.type, body: body });58 }59};60//61// internal, converts object into spdy dictionary62//63function headersToDict(headers, preprocess) {64 function stringify(value) {65 if (value !== undefined) {66 if (Array.isArray(value)) {67 return value.join('\x00');68 } else if (typeof value === 'string') {69 return value;70 } else {71 return value.toString();72 }73 } else {74 return '';75 }76 }77 // Lower case of all headers keys78 var loweredHeaders = {};79 Object.keys(headers || {}).map(function(key) {80 loweredHeaders[key.toLowerCase()] = headers[key];81 });82 // Allow outer code to add custom headers or remove something83 if (preprocess) preprocess(loweredHeaders);84 // Transform object into kv pairs85 var len = 4,86 pairs = Object.keys(loweredHeaders).filter(function(key) {87 var lkey = key.toLowerCase();88 return lkey !== 'connection' && lkey !== 'keep-alive' &&89 lkey !== 'proxy-connection' && lkey !== 'transfer-encoding';90 }).map(function(key) {91 var klen = Buffer.byteLength(key),92 value = stringify(loweredHeaders[key]),93 vlen = Buffer.byteLength(value);94 len += 8 + klen + vlen;95 return [klen, key, vlen, value];96 }),97 result = new Buffer(len);98 result.writeUInt32BE(pairs.length, 0, true);99 var offset = 4;100 pairs.forEach(function(pair) {101 // Write key length102 result.writeUInt32BE(pair[0], offset, true);103 // Write key104 result.write(pair[1], offset + 4);105 offset += pair[0] + 4;106 // Write value length107 result.writeUInt32BE(pair[2], offset, true);108 // Write value109 result.write(pair[3], offset + 4);110 offset += pair[2] + 4;111 });112 return result;113};114Framer.prototype._synFrame = function _synFrame(type, id, assoc, priority, dict,115 callback) {116 // Compress headers117 this.deflate(dict, function (err, chunks, size) {118 if (err) return callback(err);119 var offset = type === 'SYN_STREAM' ? 18 : 12,120 total = (type === 'SYN_STREAM' ? 10 : 4) + size,121 frame = new Buffer(offset + size);;122 frame.writeUInt16BE(0x8003, 0, true); // Control + Version123 frame.writeUInt16BE(type === 'SYN_STREAM' ? 1 : 2, 2, true); // type124 frame.writeUInt32BE(total & 0x00ffffff, 4, true); // No flag support125 frame.writeUInt32BE(id & 0x7fffffff, 8, true); // Stream-ID126 if (type === 'SYN_STREAM') {127 frame[4] = 2;128 frame.writeUInt32BE(assoc & 0x7fffffff, 12, true); // Stream-ID129 }130 frame.writeUInt8(priority & 0x7, 16, true); // Priority131 for (var i = 0; i < chunks.length; i++) {132 chunks[i].copy(frame, offset);133 offset += chunks[i].length;134 }135 callback(null, frame);136 });137};138//139// ### function replyFrame (id, code, reason, headers, callback)140// #### @id {Number} Stream ID141// #### @code {Number} HTTP Status Code142// #### @reason {String} (optional)143// #### @headers {Object|Array} (optional) HTTP headers144// #### @callback {Function} Continuation function145// Sends SYN_REPLY frame146//147Framer.prototype.replyFrame = function replyFrame(id, code, reason, headers,148 callback) {149 var dict = headersToDict(headers, function(headers) {150 headers[':status'] = code + ' ' + reason;151 headers[':version'] = 'HTTP/1.1';152 });153 this._synFrame('SYN_REPLY', id, null, 0, dict, callback);154};155//156// ### function streamFrame (id, assoc, headers, callback)157// #### @id {Number} stream id158// #### @assoc {Number} associated stream id159// #### @meta {Object} meta headers ( method, scheme, url, version )160// #### @headers {Object} stream headers161// #### @callback {Function} continuation callback162// Create SYN_STREAM frame163// (needed for server push and testing)164//165Framer.prototype.streamFrame = function streamFrame(id, assoc, meta, headers,166 callback) {167 var dict = headersToDict(headers, function(headers) {168 headers[':status'] = 200;169 headers[':version'] = meta.version || 'HTTP/1.1';170 headers[':path'] = meta.path;171 headers[':scheme'] = meta.scheme || 'https';172 headers[':host'] = meta.host;173 });174 this._synFrame('SYN_STREAM', id, assoc, meta.priority, dict, callback);175};176//177// ### function dataFrame (id, fin, data)178// #### @id {Number} Stream id179// #### @fin {Bool} Is this data frame last frame180// #### @data {Buffer} Response data181// Sends DATA frame182//183Framer.prototype.dataFrame = function dataFrame(id, fin, data) {184 if (!fin && !data.length) return [];185 var frame = new Buffer(8 + data.length);186 frame.writeUInt32BE(id & 0x7fffffff, 0, true);187 frame.writeUInt32BE(data.length & 0x00ffffff, 4, true);188 frame.writeUInt8(fin ? 0x01 : 0x0, 4, true);189 if (data.length) data.copy(frame, 8);190 return frame;191};192//193// ### function pingFrame (id)194// #### @id {Buffer} Ping ID195// Sends PING frame196//197Framer.prototype.pingFrame = function pingFrame(id) {198 var header = new Buffer(12);199 header.writeUInt32BE(0x80030006, 0, true); // Version and type200 header.writeUInt32BE(0x00000004, 4, true); // Length201 id.copy(header, 8, 0, 4); // ID202 return header;203};204//205// ### function rstFrame (id, code)206// #### @id {Number} Stream ID207// #### @code {NUmber} RST Code208// Sends PING frame209//210Framer.prototype.rstFrame = function rstFrame(id, code) {211 var header;212 if (!(header = Framer.rstCache[code])) {213 header = new Buffer(16);214 header.writeUInt32BE(0x80030003, 0, true); // Version and type215 header.writeUInt32BE(0x00000008, 4, true); // Length216 header.writeUInt32BE(id & 0x7fffffff, 8, true); // Stream ID217 header.writeUInt32BE(code, 12, true); // Status Code218 Framer.rstCache[code] = header;219 }220 return header;221};222Framer.rstCache = {};223//224// ### function settingsFrame (options)225// #### @options {Object} settings frame options226// Sends SETTINGS frame with MAX_CONCURRENT_STREAMS and initial window227//228Framer.prototype.settingsFrame = function settingsFrame(options) {229 var settings,230 key = options.maxStreams + ':' + options.windowSize;231 if (!(settings = Framer.settingsCache[key])) {232 settings = new Buffer(28);233 settings.writeUInt32BE(0x80030004, 0, true); // Version and type234 settings.writeUInt32BE((4 + 8 * 2) & 0x00FFFFFF, 4, true); // length235 settings.writeUInt32BE(0x00000002, 8, true); // Count of entries236 settings.writeUInt32BE(0x01000004, 12, true); // Entry ID and Persist flag237 settings.writeUInt32BE(options.maxStreams & 0x7fffffff, 16, true);238 settings.writeUInt32BE(0x01000007, 20, true); // Entry ID and Persist flag239 settings.writeUInt32BE(options.windowSize & 0x7fffffff, 24, true);240 Framer.settingsCache[key] = settings;241 }242 return settings;243};244Framer.settingsCache = {};245//246// ### function windowSizeFrame (size)247// #### @size {Number} data transfer window size248// Sends SETTINGS frame with window size249//250Framer.prototype.windowSizeFrame = function windowSizeFrame(size) {251 var settings;252 if (!(settings = Framer.windowSizeCache[size])) {253 settings = new Buffer(20);254 settings.writeUInt32BE(0x80030004, 0, true); // Version and type255 settings.writeUInt32BE((4 + 8) & 0x00FFFFFF, 4, true); // length256 settings.writeUInt32BE(0x00000001, 8, true); // Count of entries257 settings.writeUInt32BE(0x01000007, 12, true); // Entry ID and Persist flag258 settings.writeUInt32BE(size & 0x7fffffff, 16, true); // Window Size (KB)259 Framer.windowSizeCache[size] = settings;260 }261 return settings;262};263Framer.windowSizeCache = {};264//265// ### function windowUpdateFrame (id)266// #### @id {Buffer} WindowUpdate ID267// Sends WINDOW_UPDATE frame268//269Framer.prototype.windowUpdateFrame = function windowUpdateFrame(id, delta) {270 var header = new Buffer(16);271 header.writeUInt32BE(0x80030009, 0, true); // Version and type272 header.writeUInt32BE(0x00000008, 4, true); // Length273 header.writeUInt32BE(id & 0x7fffffff, 8, true); // ID274 header.writeUInt32BE(delta & 0x7fffffff, 12, true); // delta275 return header;...
index.js
Source:index.js
1'use strict';2var KeenIO = require('..');3var Test = require('segmentio-integration-tester');4var helpers = require('./helpers');5describe('Keen IO', function() {6 var keen;7 var settings;8 var test;9 beforeEach(function() {10 settings = {11 projectId: '5181bcd23843312d87000000',12 writeKey: '6d5c9e2365324fa4a631e88cd4ce7df3ca4bf41e5a9a29e48c2dfb57408bb978f5d2e6d77424fa14c9d167c72d8e1d618c7eea178ecf5934dc8d456e0114ec81112f81e8df9507a31b7bfee9cbd00944f59d54f199f046263578ded79b62c33a435f17907bffae8fd8e109086eb53f1b',13 trackNamedPages: true14 };15 keen = new KeenIO(settings);16 test = Test(keen, __dirname);17 });18 it('should have the correct settings', function() {19 test20 .name('Keen IO')21 .endpoint('https://api.keen.io/3.0')22 .ensure('settings.projectId')23 .ensure('settings.writeKey')24 .channels(['server']);25 });26 describe('.validate()', function() {27 it('should be invalid when .projectId is missing', function() {28 delete settings.projectId;29 test.invalid({}, settings);30 });31 it('should be invalid when .writeKey is missing', function() {32 delete settings.writeKey;33 test.invalid({}, settings);34 });35 it('should be valid when .writeKey and .projectId are given', function() {36 test.valid({}, settings);37 });38 });39 describe('mapper', function() {40 describe('track', function() {41 it('should map basic track message', function() {42 test.maps('basic');43 });44 it('should fallback to .anonymousId', function() {45 test.maps('anonymous-id');46 });47 it('should respect .integrations["Keen IO"].traits', function() {48 test.maps('traits');49 });50 it('should respect props.keen object', function() {51 test.maps('keen-props');52 });53 it('should add ip addon when .ipAddon is `true`', function() {54 test.maps('ip-addon');55 });56 57 it('should add referrer addon when .referrerAddon is `true`', function() {58 test.maps('referrer-addon');59 });60 it('should add user-agent addon when .uaAddon is `true`', function() {61 test.maps('user-agent-addon');62 });63 it('should add url-parser addon when `.urlAddon` is `true`', function() {64 test.maps('url-addon');65 });66 it('should not respect addons when the input is not included', function() {67 test.maps('addons-without-input');68 });69 it('should respect addon options', function() {70 test.maps('addons');71 });72 });73 });74 describe('.track()', function() {75 it('should track correctly', function(done) {76 test77 .set(settings)78 .track(helpers.track())79 .expects(200)80 .end(done);81 });82 it('should error on invalid creds', function(done) {83 test84 .set({ writeKey: 'x' })85 .track(helpers.track())86 .error(done);87 });88 });89 describe('.page()', function() {90 it('should be able to track all pages', function(done) {91 var json = test.fixture('page-all');92 json.output['Loaded a Page'][0].keen.timestamp = new Date(json.output['Loaded a Page'][0].keen.timestamp);93 test94 .set(settings)95 .set(json.settings)96 .page(json.input)97 .query('api_key', settings.writeKey)98 .sends(json.output)99 .expects(200)100 .end(done);101 });102 it('should be able to track named pages', function(done) {103 var json = test.fixture('page-named');104 json.output['Viewed Home Page'][0].keen.timestamp = new Date(json.output['Viewed Home Page'][0].keen.timestamp);105 test106 .set(settings)107 .set(json.settings)108 .page(json.input)109 .query('api_key', settings.writeKey)110 .sends(json.output)111 .expects(200)112 .end(done);113 });114 it('should be able to track categorized pages', function(done) {115 var json = test.fixture('page-categorized');116 json.output['Viewed Docs Page'][0].keen.timestamp = new Date(json.output['Viewed Docs Page'][0].keen.timestamp);117 test118 .set(settings)119 .set(json.settings)120 .page(json.input)121 .query('api_key', settings.writeKey)122 .sends(json.output)123 .expects(200)124 .end(done);125 });126 it('should error on invalid creds', function(done) {127 test128 .set({ writeKey: 'x' })129 .page(helpers.page())130 .error(done);131 });132 });133 describe('.screen()', function() {134 it('should be able to track all screens', function(done) {135 var json = test.fixture('screen-all');136 json.output['Loaded a Screen'][0].keen.timestamp = new Date(json.output['Loaded a Screen'][0].keen.timestamp);137 test138 .set(settings)139 .set(json.settings)140 .screen(json.input)141 .query('api_key', settings.writeKey)142 .sends(json.output)143 .expects(200)144 .end(done);145 });146 it('should be able to track named screens', function(done) {147 var json = test.fixture('screen-named');148 json.output['Viewed Home Screen'][0].keen.timestamp = new Date(json.output['Viewed Home Screen'][0].keen.timestamp);149 test150 .set(settings)151 .set(json.settings)152 .screen(json.input)153 .query('api_key', settings.writeKey)154 .sends(json.output)155 .expects(200)156 .end(done);157 });158 it('should error on invalid creds', function(done) {159 test160 .set({ writeKey: 'x' })161 .screen(helpers.screen())162 .error(done);163 });164 });...
settings.js
Source:settings.js
1function onShow()2{3 System.Debug.outputString("onShow()");4 System.Debug.outputString(System.Gadget.Settings.readString("url1"));5 System.Debug.outputString(System.Gadget.Settings.readString("url2"));6 System.Debug.outputString(System.Gadget.Settings.readString("url3"));7 System.Debug.outputString(System.Gadget.Settings.readString("url4"));8 System.Debug.outputString(System.Gadget.Settings.readString("url5"));910 document.settingForm.baseUrl1.value = System.Gadget.Settings.readString("url1");11 document.settingForm.baseUrl2.value = System.Gadget.Settings.readString("url2");12 document.settingForm.baseUrl3.value = System.Gadget.Settings.readString("url3");13 document.settingForm.baseUrl4.value = System.Gadget.Settings.readString("url4");14 document.settingForm.baseUrl5.value = System.Gadget.Settings.readString("url5");15 document.settingForm.intervalBox.value = parseInt(System.Gadget.Settings.readString("interval"));16 document.settingForm.isFade.checked = System.Gadget.Settings.read("isUseFade");17}1819System.Gadget.onSettingsClosing = onSettingsClosing;20function onSettingsClosing(e)21{22 if (e.closeAction == e.Action.commit)23 {24 var isVailed = true;25 var HTTP = "http://" /* CONST!!! */2627 if (parseInt(document.settingForm.intervalBox.value) < 10 ||28 !isFinite(parseInt(document.settingForm.intervalBox.value)))29 {30 document.settingForm.intervalBox.value = "10";31 AbortCloseWindow(new Array(e), new Array(isVailed));32 }33 if (document.settingForm.baseUrl1.value != "" &&34 document.settingForm.baseUrl1.value.indexOf(HTTP) == -1)35 {36 SetMessageCorrectUrl(document.settingForm.baseUrl1);37 AbortCloseWindow(new Array(e), new Array(isVailed));38 }39 if (document.settingForm.baseUrl2.value != "" &&40 document.settingForm.baseUrl2.value.indexOf(HTTP) == -1)41 {42 SetMessageCorrectUrl(document.settingForm.baseUrl2);43 AbortCloseWindow(new Array(e), new Array(isVailed));44 }45 if (document.settingForm.baseUrl3.value != "" &&46 document.settingForm.baseUrl3.value.indexOf(HTTP) == -1)47 {48 SetMessageCorrectUrl(document.settingForm.baseUrl3);49 AbortCloseWindow(new Array(e), new Array(isVailed));50 }51 if (document.settingForm.baseUrl4.value != "" &&52 document.settingForm.baseUrl4.value.indexOf(HTTP) == -1)53 {54 SetMessageCorrectUrl(document.settingForm.baseUrl4);55 AbortCloseWindow(new Array(e), new Array(isVailed));56 }57 if (document.settingForm.baseUrl5.value != "" && 58 document.settingForm.baseUrl5.value.indexOf(HTTP) == -1)59 {60 SetMessageCorrectUrl(document.settingForm.baseUrl5);61 AbortCloseWindow(new Array(e), new Array(isVailed));62 }6364 if (isVailed)65 {66 WriteSettings();67 }68 }69}7071function WriteSettings()72{73 System.Gadget.Settings.writeString("interval", document.settingForm.intervalBox.value);74 System.Gadget.Settings.write("isUseFade", document.settingForm.isFade.checked);75 System.Gadget.Settings.writeString("url1", document.settingForm.baseUrl1.value);76 System.Gadget.Settings.writeString("url2", document.settingForm.baseUrl2.value);77 System.Gadget.Settings.writeString("url3", document.settingForm.baseUrl3.value);78 System.Gadget.Settings.writeString("url4", document.settingForm.baseUrl4.value);79 System.Gadget.Settings.writeString("url5", document.settingForm.baseUrl5.value);80}8182function SetMessageCorrectUrl(input)83{84 input.value = "ããã«æ£ããURLãããã¦ãã ãã";85}8687function AbortCloseWindow(e, isVailed)88{89 e[0].cancel = true;90 isVailed[0] = false;
...
gadget.js
Source:gadget.js
1// ------------------------------------------------------2// Copyright (C) 2007 Oekosoft3// ------------------------------------------------------4// ------------------------------------------------------5// Gadget6// ------------------------------------------------------7function pageLoad() {8 System.Gadget.settingsUI = 'settings.html';9 System.Gadget.onSettingsClosed = settingsClosed; 10 11 var myurl = System.Gadget.Settings.readString("webCamUrl");12 if (myurl == "") {13 myurl = 'http://meteoinfo.by/radar/UMMN/UMMN_latest.png';14 System.Gadget.Settings.writeString("webCamUrl", myurl);15 }16 myurl = myurl+"?"+new Date().getTime();17 var mydiv = document.getElementById('gadget');18 mydiv.innerHTML = "<a href='"+myurl+"'><img id='photo' src='"+myurl+"' class='layer' border=0></a>";19 startTimeout();20 }21function settingsClosed(p_event) {22 pageLoad();23}24function eraseTimeout() {25 clearTimeout (isTiming);26 isTiming = false;27}28function startTimeout() {29 var myrefresh = System.Gadget.Settings.readString("refreshTime");30 if (myrefresh == "") {31 myrefresh = '300';32 System.Gadget.Settings.writeString("refreshTime", myrefresh);33 }34 isTiming = setTimeout("refresh()", myrefresh*1000);35}36function refresh() {37 eraseTimeout();38 pageLoad();39}40// ------------------------------------------------------41// Settings42// ------------------------------------------------------43function loadSettings()44{45 System.Gadget.onSettingsClosing = settingsClosing; 46 var currentSetting = System.Gadget.Settings.readString("webCamUrl");47 if (currentSetting != "") {48 webUrl.innerText = currentSetting;49 }50 currentSetting = System.Gadget.Settings.readString("refreshTime");51 if (currentSetting != "") {52 refreshTime.innerText = currentSetting;53 }54}55function settingsClosing(event)56{57 if (event.closeAction == event.Action.commit) {58 System.Gadget.Settings.writeString("webCamUrl", webUrl.value);59 System.Gadget.Settings.writeString("refreshTime", refreshTime.value);60 }...
action-types.js
Source:action-types.js
1export const STORAGE_READ = 'STORAGE_READ'2export const STORAGE_WRITE = 'STORAGE_WRITE'3export const STORAGE_DELETE = 'STORAGE_DELETE'4export const STORAGE_CHANGED = 'STORAGE_CHANGED'5export const SETTINGS_READ = 'SETTINGS_READ'6// export const SETTINGS_WRITE = 'SETTINGS_WRITE'7export const SETTINGS_READ_ALL = 'SETTINGS_READ_ALL'8export const SETTINGS_WRITE_ALL = 'SETTINGS_WRITE_ALL'9export const SETTINGS_CHANGED = 'SETTINGS_CHANGED'10export const GET_OPTION_DEFS = 'GET_OPTION_DEFS'11export const PROXIED_FETCH_GET = 'PROXIED_FETCH_GET'12export const PROXIED_AUDIO = 'PROXIED_AUDIO'...
Using AI Code Generation
1Cypress.Commands.add("writeSettings", (key, value) => {2 cy.writeFile("cypress/support/settings.json", { [key]: value }, { flag: "a+" });3});4Cypress.Commands.add("readSettings", key => {5 return cy.readFile("cypress/support/settings.json").its(key);6});7Cypress.Commands.add("clearSettings", () => {8 cy.writeFile("cypress/support/settings.json", {});9});10Cypress.Commands.add("clearSettings", () => {11 cy.writeFile("cypress/support/settings.json", {});12});13Cypress.Commands.add("clearSettings", () => {14 cy.writeFile("cypress/support/settings.json", {});15});16Cypress.Commands.add("clearSettings", () => {17 cy.writeFile("cypress/support/settings.json", {});18});19Cypress.Commands.add("clearSettings", () => {20 cy.writeFile("cypress/support/settings.json", {});21});22Cypress.Commands.add("clearSettings", () => {23 cy.writeFile("cypress/support/settings.json", {});24});25Cypress.Commands.add("clearSettings", () => {26 cy.writeFile("cypress/support/settings.json", {});27});28Cypress.Commands.add("clearSettings", () => {29 cy.writeFile("cypress/support/settings.json", {});30});31Cypress.Commands.add("clearSettings", () => {32 cy.writeFile("cypress/support/settings.json", {});33});34Cypress.Commands.add("clearSettings
Using AI Code Generation
1cy . writeSettings ( 'settings.json' , { 2 } ) ;3cy . readSettings ( 'settings.json' ) . should ( 'have.property' , 'foo' , 'bar' ) ;4cy . clearSettings ( 'settings.json' ) ;5cy . clearAllSettings ( ) ;6cy . clearAllSettings ( ) ;7cy . getFilePath ( 'settings.json' ) . should ( 'eq' , '/Users/username/Library/Application Support/Cypress/cy/production/projects/project-id/browsers/chrome/83.0.4103.61/settings.json' ) ;8cy . getFilePath ( 'settings.json' ) . should ( 'eq' , '/Users/username/Library/Application Support/Cypress/cy/production/projects/project-id/browsers/chrome/83.0.4103.61/settings.json' ) ;9cy . getFilePath ( 'settings.json' ) . should ( 'eq' , '/Users/username/Library/Application Support/Cypress/cy/production/projects/project-id/browsers/chrome/83.0.4103.61/settings.json' ) ;10cy . getFilePath ( 'settings.json' ) . should ( 'eq' , '/Users/username/Library/Application Support/Cypress/cy/production/projects/project-id/browsers/chrome/83.0.4103.61/settings.json' ) ;11cy . getFilePath ( 'settings.json' ) . should ( 'eq' , '/Users/username/Library/Application Support/Cypress/cy/production/projects/project-id/browsers/chrome/83.0.4103.61/settings.json' ) ;12cy . getFilePath ( 'settings.json' ) . should ( 'eq' , '/Users/username/Library/Application Support/Cypress/cy/production/projects/project-id/browsers/chrome/83.0.4103.61/settings.json'
Using AI Code Generation
1describe('Test', () => {2 it('write to JSON file', () => {3 cy.writeFile('cypress/fixtures/test.json', {4 })5 })6 it('read from JSON file', () => {7 cy.readFile('cypress/fixtures/test.json').then((data) => {8 cy.log(data)9 })10 })11})12describe('Test', () => {13 it('read from JSON file', () => {14 cy.readFile('cypress/fixtures/test.json').then((data) => {15 cy.log(data)16 })17 })18 it('write to JSON file', () => {19 cy.writeFile('cypress/fixtures/test.json', {20 })21 })22})
Using AI Code Generation
1describe('write data to cypress.json file', function(){2it('write data to cypress.json file', function(){3cy.log('write data to cypress.json file')4cy.writeFile('cypress.json', { "key": "value" })5})6})7{8}9describe('read data from cypress.json file', function(){10it('read data from cypress.json file', function(){11cy.log('read data from cypress.json file')12cy.readFile('cypress.json').then((data) => {13cy.log(data.key)14})15})16})17{18"env": {19}20}21describe('use environment variables in test cases', function(){22it('use environment variables in test cases', function(){23cy.log('use environment variables in test cases')24cy.log(Cypress.env('username'))25cy.log(Cypress.env('password'))26})27})28{29}30describe('use configuration in test cases', function(){31it('use configuration in test cases', function(){32cy.log('use configuration in test cases')33cy.log(Cypress.config('defaultCommandTimeout'))34})35})
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.
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.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!