How to use parseIndex method in backstopjs

Best JavaScript code snippet using backstopjs

vaTxtToIntObj.js

Source:vaTxtToIntObj.js Github

copy

Full Screen

1'use strict';2var Transform = require("stream").Transform;3var util = require("util");4var parseObject = require('./parseObject');5var async = require('async');6var _ = require('lodash');7var parseIndex = [];8function VaParserStream() {9 Transform.call(this, {10 "objectMode": true11 }); // invoke Transform's constructor, expected result is object12 this.rowCount = 1;13 this.emptyRows = 0;14 this.error = null;15}16util.inherits(VaParserStream, Transform); // inherit Transform17/**18 * @Function _transform19 * Define standart Transform Stream's function _transform20 * @param (String) line - input line21 * @param (String) encoding - encoding (not used now)22 * @param cb - callback to notify that we are done with a row23 */24VaParserStream.prototype._transform = function (line, encoding, cb) {25 if (line) {26 line = line.trim();27 }28 //Ignore the rest of input in case of error29 if (!this.error) {30 //Don't propagate empty rows, just count31 ++this.rowCount;32 if ('' === line) {33 ++this.emptyRows;34 cb();35 } else {36 var wasSetThisLine = false;37 async.series([function (cb1) { //major sections38 var match;39 async.eachSeries(parseObject, function (parseItem, cb2) {40 if (!match) {41 if (parseItem.multiple || !parseItem.found) {42 match = parseItem.pattern.exec(line);43 if (match) {44 parseItem.found = true;45 if (parseIndex.length > 0) {46 for (var i = 0; i < parseIndex.length; i++) {47 parseIndex.pop();48 }49 }50 if (parseItem.model.length > 0) {51 parseIndex = [parseItem];52 }53 parseItem.raw.push(line);54 wasSetThisLine = true;55 cb2();56 } else {57 cb2();58 }59 } else {60 cb2();61 }62 } else {63 cb2();64 }65 }, function (err) {66 cb1();67 });68 }, function (cb1) { //nested data 1 (primary fields in section)69 if (parseIndex.length > 0 && !wasSetThisLine) {70 var match;71 async.eachSeries(parseIndex[0].model, function (parseItem2, cb3) {72 if (!match) {73 if (parseItem2.multiple || !parseItem2.found) {74 match = parseItem2.pattern.exec(line);75 if (match) {76 parseItem2.found = true;77 if (parseIndex.length > 1) {78 for (var i = 1; i < parseIndex.length; i++) {79 parseIndex.pop();80 }81 }82 if (parseItem2.model.length > 0) {83 parseIndex.push(parseItem2);84 wasSetThisLine = true;85 }86 var processed = parseItem2.process(parseIndex[0].processed, match);87 for (var j = 0; j < Object.keys(processed).length; j++) {88 parseIndex[0].processed[Object.keys(processed)[j]] = processed[Object.keys(processed)[j]];89 }90 parseItem2.raw.push(line);91 cb3();92 } else {93 cb3();94 }95 } else {96 cb3();97 }98 } else {99 cb3();100 }101 }, function (err) {102 cb1();103 });104 } else {105 cb1();106 }107 }108 /*109 , function (cb1) { //nested data 2 (multiple primary fields)110 if (parseIndex.length > 1 && !wasSetThisLine) {111 var match;112 async.eachSeries(parseIndex[1].model, function (parseItem2, cb3) {113 if (!match) {114 if (parseItem2.multiple || !parseItem2.found) {115 match = parseItem2.pattern.exec(line);116 if (match) {117 parseItem2.found = true;118 if (parseItem2.model.length > 0) {119 parseIndex.push(parseItem2);120 }121 var processed = parseItem2.process(parseIndex[1].processed, match);122 for (var i = 0; i < Object.keys(processed).length; i++) {123 parseIndex[1].processed[Object.keys(processed)[i]] = processed[Object.keys(processed)[i]];124 }125 parseItem2.raw.push(line);126 cb3();127 } else {128 cb3();129 }130 } else {131 cb3();132 }133 } else {134 cb3();135 }136 }, function (err) {137 cb1();138 });139 } else {140 cb1();141 }142 } */143 ], function (err) {144 //console.log(JSON.stringify(parseObject));145 cb();146 });147 }148 } else {149 cb();150 }151};152function convertPath(path) {153 return path.replace(/\.([0-9]{1,})/g, '[0]');154}155function checkPaths(paths, path) {156 if (paths.length === 0) {157 paths.push(path);158 console.log(path);159 return paths;160 } else {161 var pathCheck = false;162 for (var i = 0; i <= paths.length; i++) {163 if (i === paths.length) {164 if (!pathCheck) {165 paths.push(path);166 console.log(path);167 }168 return paths;169 } else {170 if (paths[i] === path) {171 pathCheck = true;172 }173 }174 }175 }176}177function outputObjectPaths(inputObj) {178 var paths = [];179 var keys1 = Object.keys(inputObj);180 for (var i = 0; i < keys1.length; i++) {181 if (inputObj[keys1[i]] instanceof Object) {182 var keys2 = Object.keys(inputObj[keys1[i]]);183 for (var j = 0; j < keys2.length; j++) {184 if (inputObj[keys1[i]][keys2[j]] instanceof Object) {185 var keys3 = Object.keys(inputObj[keys1[i]][keys2[j]]);186 for (var k = 0; k < keys3.length; k++) {187 if (inputObj[keys1[i]][keys2[j]][keys3[k]] instanceof Object) {188 var keys4 = Object.keys(inputObj[keys1[i]][keys2[j]][keys3[k]]);189 for (var m = 0; m < keys4.length; m++) {190 if (inputObj[keys1[i]][keys2[j]][keys3[k]][keys4[m]] instanceof Object) {191 var keys5 = Object.keys(inputObj[keys1[i]][keys2[j]][keys3[k]][keys4[m]]);192 for (var n = 0; n < keys5.length; n++) {193 paths = checkPaths(paths, convertPath(keys1[i] + '.' + keys2[j] + '.' + keys3[k] + '.' + keys4[m] + '.' + keys5[n]));194 }195 } else {196 paths = checkPaths(paths, convertPath(keys1[i] + '.' + keys2[j] + '.' + keys3[k] + '.' + keys4[m]));197 }198 }199 } else {200 paths = checkPaths(paths, convertPath(keys1[i] + '.' + keys2[j] + '.' + keys3[k]));201 }202 }203 } else {204 paths = checkPaths(paths, convertPath(keys1[i] + '.' + keys2[j]));205 }206 }207 } else {208 paths = checkPaths(paths, convertPath(keys1[i]));209 }210 }211}212/**213 * @Function _flush214 * Define standart Transform Stream's function _flush215 * Normally in should push parsed result (or error) to a pipe216 * @param cb - callback to notify that we are done217 */218VaParserStream.prototype._flush = function (cb) {219 if (this.error) {220 this.push(this.error);221 } else {222 //console.log("Done processing");223 var outputObj = _.reduce(parseObject.map(function (obj) {224 var result = {};225 result[obj.name] = obj.processed;226 return result;227 }), function (memo, current) {228 return _.extend(memo, current);229 }, {});230 /*231 var keys = Object.keys(outputObj);232 keys.forEach(function (key) {233 if (Object.keys(outputObj[key]).length > 0) {234 console.log(key + ': ' + JSON.stringify(Object.keys(outputObj[key])));235 }236 });237 */238 //outputObjectPaths(outputObj);239 this.push(outputObj);240 //console.log(JSON.stringify(outputObj));241 }242 cb(); // Notify done243};244//TODO : remove245function streamToIntObj(istream, done, error) {246 var ps = new VaParserStream();247 istream.pipe(ps).on('finish', function () {248 done(ps.rows);249 }).on('error', function (e) {250 if (error) {251 error(e);252 }253 });254}255module.exports.streamToIntObj = streamToIntObj;...

Full Screen

Full Screen

flv-metadata.ts

Source:flv-metadata.ts Github

copy

Full Screen

1/***2 * Copyright (C) 2018 Qli5. All Rights Reserved.3 *4 * @author qli5 <goodlq11[at](163|gmail).com>5 *6 * This Source Code Form is subject to the terms of the Mozilla Public7 * License, v. 2.0. If a copy of the MPL was not distributed with this8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.9 */10/* eslint-disable */11// @ts-nocheck12// import TwentyFourDataView from '../utils/twenty-four-dataview';13const dataTypeMap = {14 0: 'number', // size length 8 float15 1: 'boolean', // size length 116 2: 'string', // size length 217 3: 'object',18 8: 'array', // size length 419 10: 'strict_array', // size length 420};21class FLVMetaData {22 constructor(dataView) {23 this.parseIndex = 0;24 this.dataView = dataView;25 this.keyByteOffset = {};26 const first_amf = this.get_first_AMF_package(dataView);27 const second_amf = this.get_second_AMF_package(dataView);28 this.config = { first_amf, second_amf };29 this.parseIndex = 0;30 }31 get_first_AMF_package(dataView) {32 const type = dataTypeMap[dataView.getUint8(this.parseIndex)];33 this.parseIndex += 1;34 if (type === 'string') {35 const value = this.data_string(dataView);36 return value;37 } else {38 throw new Error('is not first package');39 }40 }41 get_second_AMF_package(dataView) {42 const result = {};43 var { type, arraymap_length } = this.get_data_info(dataView);44 if (type === 'array') {45 result.arraymap = this.deal_array(dataView);46 result.arraymap.length = arraymap_length;47 }48 return result;49 }50 data_string(dataView) {51 const data_length = dataView.getUint16(this.parseIndex);52 this.parseIndex += 2;53 let str = '';54 for (let i = 0; i < data_length; i++) {55 str += String.fromCharCode(dataView.getUint8(this.parseIndex));56 this.parseIndex += 1;57 }58 return str;59 }60 get_data_info(dataView, keyOffset) {61 const type = dataTypeMap[dataView.getUint8(this.parseIndex)];62 this.parseIndex += 1;63 if (keyOffset) {64 if (['filepositions', 'times'].includes(keyOffset)) {65 !this.keyByteOffset[keyOffset] && (this.keyByteOffset[keyOffset] = []);66 this.keyByteOffset[keyOffset].push(this.parseIndex);67 } else {68 this.keyByteOffset[keyOffset] = this.parseIndex;69 }70 }71 if (type === 'string') {72 const value = this.data_string(dataView);73 return { type, value };74 }75 if (type === 'number') {76 const value = dataView.getFloat64(this.parseIndex);77 this.parseIndex += 8;78 return { type, value };79 }80 if (type === 'boolean') {81 const value = dataView.getUint8(this.parseIndex) ? true : false;82 this.parseIndex += 1;83 return { type, value };84 }85 if (type === 'array') {86 const data_length = dataView.getUint32(this.parseIndex);87 this.parseIndex += 4;88 return { type, arraymap_length: data_length };89 }90 if (type === 'strict_array') {91 const data_length = dataView.getUint32(this.parseIndex);92 this.parseIndex += 4;93 return { type, strict_array_length: data_length };94 }95 if (type === 'object') {96 return { type };97 }98 }99 deal_array(dataView, obj = {}) {100 const itemKey = this.data_string(dataView);101 const { value: itemValue, type } = this.get_data_info(dataView, itemKey);102 if (type !== 'object') {103 obj[itemKey] = itemValue;104 return this.deal_array(dataView, obj);105 } else {106 obj[itemKey] = this.deal_object(dataView);107 // obj["end-mark"] = dataView.buffer.slice(this.parseIndex);108 return obj;109 }110 }111 // 处理 当type为object当情况112 deal_object(dataView, obj = {}) {113 if (dataView.byteLength - this.parseIndex < 8) {114 return obj;115 }116 const itemKey = this.data_string(dataView);117 var { type, strict_array_length } = this.get_data_info(dataView);118 obj[itemKey] = {119 length: strict_array_length,120 data: [],121 key: itemKey,122 };123 if (type === 'strict_array') {124 this.deal_object_data(dataView, obj[itemKey]);125 return this.deal_object(dataView, obj);126 }127 }128 // 处理 keyframes 的元信息129 deal_object_data(dataView, obj) {130 if (obj.data.length >= obj.length) {131 return obj;132 }133 var { type, value } = this.get_data_info(dataView, obj.key);134 if (type === 'number') {135 // 判断数据是不是到达指定的长度136 obj.data.push(value);137 return this.deal_object_data(dataView, obj);138 } else {139 return obj;140 }141 }142 get tagType() {143 return this.tagHeader.getUint8(0);144 }145 get dataSize() {146 return this.tagHeader.getUint24(1);147 }148 get timestamp() {149 return this.tagHeader.getUint24(4);150 }151 get timestampExtension() {152 return this.tagHeader.getUint8(7);153 }154 get streamID() {155 return this.tagHeader.getUint24(8);156 }157 // stripKeyframesScriptData() {158 // let hasKeyframes = 'hasKeyframes\x01';159 // let keyframes = '\x00\x09keyframs\x03';160 // if (this.tagType != 0x12) throw 'can not strip non-scriptdata\'s keyframes';161 // let index;162 // index = this.tagData.indexOf(hasKeyframes);163 // if (index != -1) {164 // //0x0101 => 0x0100165 // this.tagData.setUint8(index + hasKeyframes.length, 0x00);166 // }167 // // Well, I think it is unnecessary168 // /*index = this.tagData.indexOf(keyframes)169 // if (index != -1) {170 // this.dataSize = index;171 // this.tagHeader.setUint24(1, index);172 // this.tagData = new TwentyFourDataView(this.tagData.buffer, this.tagData.byteOffset, index);173 // }*/174 // }175 // getDuration() {176 // if (this.tagType != 0x12) throw 'can not find non-scriptdata\'s duration';177 // let duration = 'duration\x00';178 // let index = this.tagData.indexOf(duration);179 // if (index == -1) throw 'can not get flv meta duration';180 // index += 9;181 // return this.tagData.getFloat64(index);182 // }183 // getDurationAndView() {184 // if (this.tagType != 0x12) throw 'can not find non-scriptdata\'s duration';185 // let duration = 'duration\x00';186 // let index = this.tagData.indexOf(duration);187 // if (index == -1) throw 'can not get flv meta duration';188 // index += 9;189 // return {190 // duration: this.tagData.getFloat64(index),191 // durationDataView: new TwentyFourDataView(this.tagData.buffer, this.tagData.byteOffset + index, 8)192 // };193 // }194 // getCombinedTimestamp() {195 // return (this.timestampExtension << 24 | this.timestamp);196 // }197 // setCombinedTimestamp(timestamp) {198 // if (timestamp < 0) throw 'timestamp < 0';199 // this.tagHeader.setUint8(7, timestamp >> 24);200 // this.tagHeader.setUint24(4, timestamp & 0x00FFFFFF);201 // }202}...

Full Screen

Full Screen

jtkml.js

Source:jtkml.js Github

copy

Full Screen

1var fs = require('fs');2var util = require("util");3var JTKML = module.exports = function() {4 this.structure = [ 'JTKML', {}, [] ];5 this.parseIndex = 0;6 this.data = null;7};8JTKML.prototype.loadFile = function(filename, callback) {9 var self = this;10 fs.readFile(filename, function(err, data) {11 if (err)12 throw err;13 self.data = data.toString();14 var curPath = [ self.structure ];15 var curLevel = 0;16 var prevTag = null;17 while(self.parseIndex < self.data.length) {18 /* Skip */19 if (self.data.charAt(self.parseIndex) == '\n') {20 self.parseIndex++;21 continue;22 }23 /* Get level */24 var level = 0;25 for (; self.parseIndex < self.data.length; self.parseIndex++) {26 if (self.data.charAt(self.parseIndex) != '\t')27 break;28 level++;29 }30 /* Get tag object */31 var tag = self.parseLine();32 /* add to structure */33 if (level == curLevel) {34 curPath[curLevel][2].push(tag);35 } else if (level > curLevel) {36 curLevel++;37 curPath[curLevel] = prevTag;38 curPath[curLevel][2].push(tag);39 } else {40 curLevel = level;41 curPath[curLevel][2].push(tag);42 /* take off sub-node */43 curPath.length = curLevel + 1;44 }45 prevTag = tag;46 }47 /* Completed */48 if (callback) {49 process.nextTick(function() {50 callback(self.structure);51 });52 }53 });54};55JTKML.prototype.parseAttrs = function() {56 var start = this.parseIndex;57 var attrsString = '';58 var attrs = {};59 while(true) {60 var c = this.data.charAt(this.parseIndex);61 if (c == ')') {62 this.parseIndex++;63 break;64 }65 this.parseIndex++;66 }67 attrsString = this.data.substring(start + 1, this.parseIndex - 1);68 /* Get all attributes */69 var parts = attrsString.split(',');70 for (var index in parts) {71 var part = parts[index].split('=');72 var attrName = part[0].replace(/(^\s*)|(\s*$)/g, "");73 var attrValue = part[1].replace(/(^\s*)|(\s*$)/g, "");74 if (attrValue.charAt(0) == '\'' && attrValue.charAt(attrValue.length-1) == '\'') {75 attrValue = attrValue.slice(1, attrValue.length-1);76 } else if (attrValue.charAt(0) == '\"' && attrValue.charAt(attrValue.length-1) == '\"') {77 attrValue = attrValue.slice(1, attrValue.length-1);78 } else {79 throw Error('Syntax Error: Attribute value needs to be wraped in `\'` or `\"`');80 }81 attrs[attrName] = attrValue;82 }83 return attrs;84};85JTKML.prototype.parseLine = function() {86 var attrs = {};87 /* Get tag */88 var tag = [];89 var start = this.parseIndex;90 var end = -1;91 while(this.parseIndex < this.data.length) {92 var c = this.data.charAt(this.parseIndex);93 if (c == '(') {94 if (end == -1)95 throw Error('No tag name');96 attrs = this.parseAttrs();97 continue;98 } else if (c == '\n') {99 if (end == -1)100 throw Error('No tag name');101 tag[0] = this.data.substring(start, end);102 tag[1] = attrs;103 tag[2] = [];104 this.parseIndex++;105 break;106 }107 this.parseIndex++;108 end = this.parseIndex;109 }110 return tag;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var backstopjs = require('backstopjs');2backstopjs('reference').then(function (result) {3 console.log(result);4}).catch(function (error) {5 console.log(error);6});7### backstopjs(command, config, options)8The backstopjs configuration object. See [the backstopjs documentation](

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var config = JSON.parse(fs.readFileSync('./backstop.json'));3var path = require('path');4var dir = './backstop_data/html_report';5if (!fs.existsSync(dir)){6 fs.mkdirSync(dir);7}8var dir = './backstop_data/bitmaps_reference';9if (!fs.existsSync(dir)){10 fs.mkdirSync(dir);11}12var dir = './backstop_data/bitmaps_test';13if (!fs.existsSync(dir)){14 fs.mkdirSync(dir);15}16var dir = './backstop_data/bitmaps_test/20170426-162902';17if (!fs.existsSync(dir)){18 fs.mkdirSync(dir);19}20var dir = './backstop_data/bitmaps_test/20170426-162902/failed_diff';21if (!fs.existsSync(dir)){22 fs.mkdirSync(dir);23}24var dir = './backstop_data/bitmaps_test/20170426-162902/html_report';25if (!fs.existsSync(dir)){26 fs.mkdirSync(dir);27}28var dir = './backstop_data/bitmaps_test/20170426-162902/html_report/images';29if (!fs.existsSync(dir)){30 fs.mkdirSync(dir);31}32var dir = './backstop_data/bitmaps_test/20170426-162902/html_report/images/diff';33if (!fs.existsSync(dir)){34 fs.mkdirSync(dir);35}36var dir = './backstop_data/bitmaps_test/20170426-162902/html_report/images/fail';37if (!fs.existsSync(dir)){38 fs.mkdirSync(dir);39}40var dir = './backstop_data/bitmaps_test/20170426-162902/html_report/images/passed';41if (!fs.existsSync(dir)){42 fs.mkdirSync(dir);43}44var dir = './backstop_data/bitmaps_test/20170426-162902/html_report/images/reference';45if (!fs.existsSync(dir)){

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

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