How to use contextLines method in backstopjs

Best JavaScript code snippet using backstopjs

md.js

Source:md.js Github

copy

Full Screen

1import fs from "fs";2/* This snippit is usefule for building out the table of contents3var doc = document.getElementById('main')4var toc = [];5for(var i=0; i<doc.children.length; i++)6{7 let child = doc.children[i];8 console.log(child)9 if(child.tagName == "H1")10 {11 let entry = `<div class='level1'><a href="#${child.id || child.getAttribute('idf')}">${child.innerHTML}</a></div>`;12 toc.push(entry)13 }14 if(child.tagName == "H2")15 {16 let entry = `<div class='level2'><a href="#${child.id || child.getAttribute('idf')}">${child.innerHTML}</a></div>`;17 toc.push(entry)18 }19 if(child.tagName == "H3")20 {21 let entry = `<div class='level3'><a href="#${child.id || child.getAttribute('idf')}">${child.innerHTML}</a></div>`;22 toc.push(entry)23 }24}25console.log(toc.join("\n"))26*/27export function buildTemplateHTML(rawTxt, navTemplate)28{29 var html = toHTML(rawTxt);30 var bonusStyle = `31 <style>32 body33 {34 background-image: url(/img/tileBackground2.jpg);35 background-size: 40%;36 }37 .main38 {39 border: solid 2px black;40 background-color: white;41 margin-top: 40px;42 }43 nav {display: block}44 </style>45 `46 var fullPage = `47 <!DOCTYPE html>48 <html>49 <head>50 <meta encoding='utf-8' />51 <title>Twilight Sparkle's Secret Shipfic Folder Online</title>52 <meta name="viewport" content="width=device-width, initial-scale=1.0">53 <meta name="twitter:card" content="summary" />54 <meta property="og:title" content="Twilight Sparkle's Secret Shipfic Folder Online">55 <meta property="og:description" content="Play and host TSSSF games through the magic of the internet">56 <meta property="og:image" content="http://tsssf.net/img/tsssf-box.png">57 <meta property="og:url" content="http://www.tsssf.net">58 <meta property="og:type" content="website">59 <link href="/info/style.css" type="text/css" rel="stylesheet"/>60 <link href="/info/highlight.min.css" type="text/css" rel="stylesheet" />61 <script src="/sectionLinks.js"></script>62 <script src="/info/highlight.min.js"></script>63 <script>64 function inIframe () {65 try {66 return window.self !== window.top;67 } catch (e) {68 return true;69 }70 }71 if(!inIframe())72 {73 document.head.innerHTML += \`${bonusStyle}\`74 }75 function toggleOpen(element)76 { 77 if(element.classList.contains('open'))78 element.classList.remove('open');79 else80 element.classList.add('open');81 }82 </script>83 </head>84 <body>85 <nav>86 ${navTemplate}87 </nav>88 <div id='main' class='main'>89 ${html}90 </div>91 <script>92 if(inIframe())93 {94 let thispage = window.location + "".split("#")[0];95 let links = document.getElementsByTagName('a');96 for(let i=0; i < links.length; i++)97 {98 if(!links[i].href.startsWith(thispage))99 {100 links[i].setAttribute("target", "_blank");101 }102 }103 }104 </script>105 </body>106 </html>`;107 return fullPage;108}109export function buildTemplate(filename, navTemplate, outFileName)110{111 var rawTxt = fs.readFileSync(filename, {encoding: "utf8"});112 113 var fullPage = buildTemplateHTML(rawTxt, navTemplate)114 var outFileName = (outFileName || filename).replace(".md", ".html");115 forceFoldersToExist(outFileName);116 fs.writeFileSync(outFileName, fullPage);117}118export function forceFoldersToExist(file)119{120 let pieces = file.split("/");121 pieces.pop();122 let folder = pieces.shift();123 while(pieces.length >= 0)124 {125 if(!fs.existsSync(folder))126 {127 fs.mkdirSync(folder);128 }129 if(pieces.length)130 folder = folder + "/" + pieces.shift();131 else132 break133 }134}135/*136 * Element has three attributes137 * type:138 * lines:139 * id: 140 */141/**142 * Block elements to worry about143 * headers144 * Lists -lazy145 * blockquotes -lazy146 * code blocks147 * horizontal rules148 */149export function toHTML(markdown)150{151 var hyperlinks = {};152 var urlDefPattern = /\[([A-Za-z0-9_.,;: ]+)\]: ?(.+?)(\r\n|\n|\r|$)/;153 var link1 = urlDefPattern.exec(markdown);154 while(link1)155 {156 hyperlinks[link1[1]] = link1[2].trim();157 markdown = markdown.replace(link1[0], "")158 link1 = urlDefPattern.exec(markdown);159 }160 var Fmt = {};161 Fmt.Blockquote = /^> ?/;162 Fmt.HashHeading = /^#{1,6} /;163 Fmt.Bullets = /^ ? ? ?[*+-] /;164 Fmt.Ordered = /^ *\d+\. +/;165 Fmt.Code = /^ /;166 Fmt.Hr = /^\s*\*\s*\*(\s*\*)+|^\s*-\s*-(\s*-)+/;167 Fmt.UnderlineHeading = /^---+|^===+/;168 Fmt.HTML = /^<([a-zA-Z0-9]+)(\s*\w+\s*=\s*('([^'\\]|\\.)*'|"([^"\\]|\\.)*"))*\s*\/?>/169 // margin170 // identifier171 // par172 // break173 // blockquote174 // bullet175 // number176 //steps177 // parse link definitions178 // parse block elements179 // parse inline elements180 var lines = markdown.replace(/\t/g," ").split(/\r\n|\n|\r/);181 return processBlocks({type:"", lines: lines});182 function textToId(text)183 { 184 return (185 text.toLowerCase()186 .replace(/[^a-z0-9- ]/g,"")187 .replace(/-/g, " ")188 .replace(/ +/g," ")189 .trim()190 .replace(/ /g, "-")191 )192 }193 function processBlocks(element)194 {195 var margin = 0;196 var lines = element.lines;197 var contextLines = [];198 var blocks = [];199 //these are used if element is a list to determine if it should wrap items in <p> tags200 var isSingleParagraph = true;201 var inParagraph = false;202 var pCount = 0;203 while(lines.length)204 {205 var contextLine = {line: lines.shift(), indent: 0};206 var HTMLmatch = Fmt.HTML.exec(contextLine.line);207 if(HTMLmatch)208 {209 var inlineTags = ["b", "big", "i", "small", "tt", "abbr", "acronym", "cite",210 "code", "dfn", "em", "kbd", "strong", "samp", "var", "a", "bdo", "br", "img",211 "map", "object", "q", "span", "sub", "sup", "button", "input", "label",212 "select", "textarea"];213 if(inlineTags.indexOf(HTMLmatch[1]) == -1)214 {215 if(HTMLmatch[0][HTMLmatch[0].length-2] == "/" || contextLine.line.indexOf("</"+HTMLmatch[1]+">") != -1)216 {217 contextLine.type = "HTML";218 inParagraph = false;219 contextLines.push(contextLine);220 continue;221 }222 else223 {224 var count = -1;225 var nestedLevel = 0;226 for(var i=0; i<lines.length; i++)227 {228 if(lines[i].startsWith("</"+HTMLmatch[1]+">"))229 {230 count = i;231 break;232 }233 }234 if(count != -1)235 {236 inParagraph = false;237 contextLine.type = "HTML";238 contextLines.push(contextLine);239 for(var i=0; i<=count; i++)240 {241 var contextLine = {line: lines.shift(), indent: 0};242 contextLine.type = "HTML";243 contextLines.push(contextLine);244 }245 continue;246 }247 }248 }249 }250 if(contextLine.line.trim() == "")251 {252 contextLine.type = "Break";253 inParagraph = false;254 }255 else if(Fmt.HashHeading.exec(contextLine.line))256 {257 contextLine.type = "Hash";258 //isSingleParagraph = false;259 }260 else if(Fmt.Hr.exec(contextLine.line))261 {262 contextLine.type = "Hr"263 while(contextLine.line[contextLine.indent] == " ")264 contextLine.indent++;265 //isSingleParagraph = false;266 }267 else if(Fmt.Blockquote.exec(contextLine.line))268 {269 contextLine.type = "Quote";270 //isSingleParagraph = false;271 }272 else if(Fmt.Bullets.exec(contextLine.line))273 {274 contextLine.type = "Bullet";275 contextLine.line = contextLine.line.replace(/\+|-/, "*");276 contextLine.inner = contextLine.line.indexOf("*") + 1;277 while(contextLine.line[contextLine.inner] == " ")278 contextLine.inner++;279 //isSingleParagraph = false;280 }281 else if(Fmt.Ordered.exec(contextLine.line))282 {283 contextLine.type = "Number";284 contextLine.inner = contextLine.line.indexOf('.') + 2;285 //isSingleParagraph = false;286 }287 else if(lines.length && Fmt.UnderlineHeading.exec(lines[0]))288 {289 contextLine.type = "Heading";290 contextLines.push(contextLine);291 contextLine = {type:"Heading", line: lines.shift(), indent:0};292 //isSingleParagraph = false;293 }294 else295 {296 if(!inParagraph)297 pCount++;298 inParagraph = true;299 contextLine.type = "Par";300 }301 while(contextLine.line[contextLine.indent] == " " || contextLine.line[contextLine.indent] == "\t")302 {303 if(contextLine.line[contextLine.indent] == "\t")304 contextLine.indent += 4;305 else306 contextLine.indent++;307 }308 contextLines.push(contextLine);309 }310 //group lines into appropriate HTML elements + process each element311 while(contextLines.length)312 {313 if(contextLines[0].type == "Break")314 {315 contextLines.shift();316 }317 else if(contextLines[0].type == "HTML")318 {319 var code = "";320 while(contextLines.length && contextLines[0].type == "HTML")321 {322 code += contextLines.shift().line + "\r\n";323 }324 blocks.push(code);325 }326 else if(contextLines[0].indent >= 4)327 {328 var preCode = "<pre><code>";329 preCode += removeTab(contextLines.shift().line)330 while(contextLines.length && (contextLines[0].type == "Break" || contextLines[0].indent >= 4))331 {332 preCode += "\r\n" + removeTab(contextLines.shift().line)333 }334 preCode += "</code></pre>";335 blocks.push(preCode);336 }337 else if(contextLines[0].type == "Par")338 {339 var paragraph = {type:"p", lines: []};340 if(element.type=="li" && pCount == 1 && isSingleParagraph)341 paragraph.type = "";342 while(contextLines.length && contextLines[0].type == "Par" && contextLines[0].indent < 4)343 {344 var line = contextLines.shift().line;345 line = line.replace(/ $/, "<br>");346 paragraph.lines.push(line);347 }348 blocks.push(processInline(paragraph));349 }350 else if(contextLines[0].type == "Heading")351 {352 var line1 = contextLines.shift().line;353 var line2 = contextLines.shift().line;354 var heading = {lines:[line1]};355 if(line2[0] == "=")356 heading.type = "h1";357 else358 heading.type = "h2";359 heading.id = textToId(line1);360 blocks.push(processInline(heading));361 }362 else if(contextLines[0].type == "Hash")363 {364 var line = contextLines.shift().line;365 var pattern = /^#{1,6} (.*?)#* *$/.exec(line)[1];366 var heading = {lines: [/^#{1,6} (.*?)#* *$/.exec(line)[1]]}367 var count = 0;368 while(line[count] == "#")369 count++;370 heading.type = "h"+count;371 heading.id = textToId(heading.lines[0]);;372 blocks.push(processInline(heading));373 }374 else if(contextLines[0].type == "Hr")375 {376 blocks.push("<hr>");377 contextLines.shift();378 }379 else if(contextLines[0].type == "Quote")380 {381 var blockquote = {type: "blockquote", lines:[]};382 var lastTokenBreak = false;383 while(contextLines.length &&384 (contextLines[0].type == "Quote" || contextLines[0].type == "Break" || (!lastTokenBreak && contextLines[0].type == "Par")))385 {386 if(contextLines[0].type == "Quote")387 {388 blockquote.lines.push(contextLines[0].line.substring(2));389 lastTokenBreak = false;390 }391 else if(contextLines[0].type == "Break")392 {393 lastTokenBreak = true;394 blockquote.lines.push(contextLines[0].line);395 }396 else397 {398 blockquote.lines.push(contextLines[0].line);399 }400 contextLines.shift();401 }402 blocks.push(processBlocks(blockquote));403 }404 else if(contextLines[0].type == "Bullet" || contextLines[0].type == "Number")405 {406 var listType = contextLines[0].type407 var ul = (listType == "Bullet" ? "<ul>" : "<ol>");408 var lastTokenBreak = false;409 while(contextLines.length && contextLines[0].type == listType)410 {411 var li = {type: "li", lines:[]};412 var line = contextLines.shift();413 var inner = line.inner;414 li.lines.push(line.line.substring(inner));415 while(contextLines.length && (contextLines[0].type == "Break"416 || (!lastTokenBreak && contextLines[0].type == "Par")417 || contextLines[0].indent >= inner418 ))419 {420 if(contextLines[0].type == "Break")421 {422 lastTokenBreak = true;423 }424 if(contextLines[0].type == "Par" && contextLines[0].indent < inner)425 li.lines.push(contextLines[0].line.substring(contextLines[0].indent));426 else427 li.lines.push(contextLines[0].line.substring(inner));428 contextLines.shift();429 }430 ul += processBlocks(li);431 }432 ul += (listType == "Bullet" ? "</ul>" : "</ol>");433 blocks.push(ul);434 }435 else436 {437 contextLines.shift();438 }439 }440 if(element.type == "")441 return blocks.join("");442 var id = (element.id ? ` id="${element.id}"` : "")443 return `<${element.type}${id}>${blocks.join("")}</${element.type}>`;444 }445 function removeTab(line)446 {447 if(!line) return line;448 if(line.startsWith("\t")) return line.substring(1);449 return line.substring(4);450 }451 // takes the lines of the element, processes them, wraps them up in the HTML tag,452 // and returns the complete HTML for the element453 function processInline(element)454 {455 var text = element.lines.join("\r\n");456 var escapes = {};457 escapes["\\\\"] = "\uE000\uE014\uE402";458 escapes["\\`"] = "\uE001\uE014\uE402";459 escapes["\\*"] = "\uE002\uE014\uE402";460 escapes["\\_"] = "\uE003\uE014\uE402";461 escapes["\\{"] = "\uE004\uE014\uE402";462 escapes["\\}"] = "\uE005\uE014\uE402";463 escapes["\\("] = "\uE006\uE014\uE402";464 escapes["\\)"] = "\uE007\uE014\uE402";465 escapes["\\["] = "\uE008\uE014\uE402";466 escapes["\\]"] = "\uE009\uE014\uE402";467 escapes["\\#"] = "\uE00A\uE014\uE402";468 escapes["\\+"] = "\uE00B\uE014\uE402";469 escapes["\\-"] = "\uE00C\uE014\uE402";470 escapes["\\."] = "\uE00D\uE014\uE402";471 escapes["\\!"] = "\uE010\uE014\uE402";472 for(var key in escapes)473 {474 var r = new RegExp(key.replace(/([\\\[\]\(\)\{\}\*\+])/g,"\\$1"), "g");475 text = text.replace(r, escapes[key]);476 }477 //url replacements478 479 // [text](htt) style links480 text = text.replace(/\[([^\[\]]*)\] ?\(([^()}]*)\)/g, "<a href='$2'>$1</a>")481 // <https://...> style links482 var RefLinkPat = /<(\w+:\/\/[^>]*)>/;483 var match = RefLinkPat.exec(text);484 while(match)485 {486 var url = match[1];487 488 var linkText = url;489 linkText = url.length > 50 ? url.substring(0,47) + "..." : url; 490 text = text.replace(match[0], "<a href='" + url + "'>" + linkText + "</a>");491 match = RefLinkPat.exec(text);492 }493 494 //strong rule **495 text = text.replace(/ \*\*([^\s]|[^\s][\s\S]*?[^\s])\*\* /g," <strong>$1</strong> ");496 text = text.replace(/ __([^\s]|[^\s][\s\S]*?[^\s])__ /g," <strong>$1</strong> ");497 //emphasis rule *498 text = text.replace(/ \*([^\s]|[^\s][\s\S]*?[^\s])\* /g," <em>$1</em> ");499 text = text.replace(/ _([^\s]|[^\s][\s\S]*?[^\s])_ /g," <em>$1</em> ");500 text = text.replace(/§(\w+)/g, "<a onclick='linkHandler(\"$1\"); return false;' href='?$1'>$1</a>");501 var code = /<script>([\s\S]*)<\/script>/.exec(text);502 for(key in escapes)503 {504 var r = new RegExp(escapes[key], "g");505 text = text.replace(r, key.substring(1));506 }507 if(element.type == "")508 return text;509 var anchor = (element.id ? `<span id="${element.id}" style="position: relative; top: -20px"></span>` : "")510 var idfAttr = element.id || "";511 return `${anchor}<${element.type} idf="${idfAttr}">${text}</${element.type}>`;512 }...

Full Screen

Full Screen

normalizeDiffOptions.js

Source:normalizeDiffOptions.js Github

copy

Full Screen

1'use strict';2Object.defineProperty(exports, '__esModule', {3 value: true4});5exports.normalizeDiffOptions = exports.noColor = void 0;6var _chalk = _interopRequireDefault(require('chalk'));7function _interopRequireDefault(obj) {8 return obj && obj.__esModule ? obj : {default: obj};9}10/**11 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.12 *13 * This source code is licensed under the MIT license found in the14 * LICENSE file in the root directory of this source tree.15 */16const noColor = string => string;17exports.noColor = noColor;18const DIFF_CONTEXT_DEFAULT = 5;19const OPTIONS_DEFAULT = {20 aAnnotation: 'Expected',21 aColor: _chalk.default.green,22 aIndicator: '-',23 bAnnotation: 'Received',24 bColor: _chalk.default.red,25 bIndicator: '+',26 changeColor: _chalk.default.inverse,27 changeLineTrailingSpaceColor: noColor,28 commonColor: _chalk.default.dim,29 commonIndicator: ' ',30 commonLineTrailingSpaceColor: noColor,31 contextLines: DIFF_CONTEXT_DEFAULT,32 emptyFirstOrLastLinePlaceholder: '',33 expand: true,34 includeChangeCounts: false,35 omitAnnotationLines: false,36 patchColor: _chalk.default.yellow37};38const getContextLines = contextLines =>39 typeof contextLines === 'number' &&40 Number.isSafeInteger(contextLines) &&41 contextLines >= 042 ? contextLines43 : DIFF_CONTEXT_DEFAULT; // Pure function returns options with all properties.44const normalizeDiffOptions = (options = {}) => ({45 ...OPTIONS_DEFAULT,46 ...options,47 contextLines: getContextLines(options.contextLines)48});...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var backstop = require('backstopjs');2backstop('test', {3 dockerCommandTemplate: 'docker run --rm -it --mount type=bind,source="{cwd}",target=/src backstopjs/backstopjs:{version} {backstopCommand} {args}'4}).then(function (result) {5 console.log(result);6}).catch(function (error) {7 console.log(error);8});9{10 {11 },12 {13 }14 {15 }16 "paths": {17 },18 "engineOptions": {19 },20}

Full Screen

Using AI Code Generation

copy

Full Screen

1var backstopjs = require('backstopjs');2var backstop = backstopjs();3var backstopConfig = require('./backstop.json');4backstop('reference', {config: backstopConfig}).then(function(){5 backstop('test', {config: backstopConfig}).then(function(){6 console.log('done');7 });8});9{10 {11 },12 {13 },14 {15 }16 {17 }18 "paths": {19 },20 "engineOptions": {21 },22}

Full Screen

Using AI Code Generation

copy

Full Screen

1var backstopjs = require('backstopjs');2var config = require('./backstop.json');3var contextLines = backstopjs.contextLines;4contextLines(config)5.then(function () {6 console.log('done');7})8.catch(function (error) {9 console.log(error);10});11{12 {13 },14 {15 },16 {17 },18 {19 }20 {21 }22 "paths": {23 },24 "engineOptions": {25 },26}

Full Screen

Using AI Code Generation

copy

Full Screen

1var backstopjs = require('backstopjs');2var config = require('./backstop.json');3var options = {4};5backstopjs('test', options).then(function (result) {6 console.log(result);7}).catch(function (err) {8 console.log(err);9});10{11 {12 },13 {14 }15 {16 }17 "paths": {18 },19 "engineOptions": {20 },21}22{23 {

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var path = require('path');3var util = require('util');4var exec = require('child_process').exec;5var child;6var backstop = require('backstopjs');7var test = require('backstopjs/core/command/test');8var reference = require('backstopjs/core/command/reference');9var approve = require('backstopjs/core/command/approve');10var openReport = require('backstopjs/core/command/openReport');11var initConfig = require('backstopjs/core/command/initConfig');12var initTest = require('backstopjs/core/command/initTest');13var initReference = require('backstopjs/core/command/initReference');14var initApprove = require('backstopjs/core/command/initApprove');15var initOpenReport = require('backstopjs/core/command/initOpenReport');16var init = require('backstopjs/core/command/init');17var help = require('backstopjs/core/command/help');18var capture = require('backstopjs/core/command/capture');19var approve = require('backstopjs/core/command/approve');20var openReport = require('backstopjs/core/command/openReport');21var util = require('backstopjs/core/util');22var backstop = require('backstopjs');23var fs = require('fs');24var path = require('path');25var util = require('util');26var exec = require('child_process').exec;27var child;28var backstop = require('backstopjs');29var test = require('backstopjs/core/command/test');30var reference = require('backstopjs/core/command/reference');31var approve = require('backstopjs/core/command/approve');32var openReport = require('backstopjs/core/command/openReport');33var initConfig = require('backstopjs/core/command/initConfig');34var initTest = require('backstopjs/core/command/initTest');35var initReference = require('backstopjs/core/command/initReference');36var initApprove = require('backstopjs/core/command/initApprove');37var initOpenReport = require('backstopjs/core/command/initOpenReport');38var init = require('backstopjs/core/command/init');39var help = require('backstopjs/core/command/help');40var capture = require('backstopjs/core/command/capture');41var approve = require('backstopjs/core/command/approve');42var openReport = require('backstopjs/core/command/openReport');43var util = require('backstopjs/core/util');

Full Screen

Using AI Code Generation

copy

Full Screen

1var backstopjs = require('backstopjs');2var config = require('./backstop.json');3config.scenarios[0].selectors = ['.test'];4backstopjs('test', {config: config});5{6 {7 },8 {9 },10 {11 }12 {13 }14 "paths": {15 },16 "engineOptions": {17 },18}

Full Screen

Using AI Code Generation

copy

Full Screen

1const backstopjs = require('./backstopjs');2const resemblejs = require('./resemblejs');3const compare = require('./compare');4backstopjs.run().then(() => {5 return resemblejs.run();6}).then(() => {7 return compare.run();8});9const backstopjs = require('backstopjs');10const backstopjsConfig = require('./backstopjs.json');11const run = () => {12 return backstopjs('test', { config: backstopjsConfig });13};14module.exports = {15};16const backstopjs = require('./backstopjs');17describe('backstopjs', () => {18 it('should run', () => {19 return backstopjs.run();20 });21});22const resemblejs = require('resemblejs');23const resemblejsConfig = require('./resemblejs.json');24const run = () => {25 return resemblejs.run(resemblejsConfig);26};27module.exports = {28};29const resemblejs = require('./resemblejs');30describe('resemblejs', () => {31 it('should run', () => {32 return resemblejs.run();33 });34});35const compare = require('compare');

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