How to use stackTrace method in Cypress

Best JavaScript code snippet using cypress

stacktrace_test.js

Source:stacktrace_test.js Github

copy

Full Screen

1// Copyright 2009 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14goog.provide('goog.testing.stacktraceTest');15goog.setTestOnly('goog.testing.stacktraceTest');16goog.require('goog.functions');17goog.require('goog.string');18goog.require('goog.testing.ExpectedFailures');19goog.require('goog.testing.PropertyReplacer');20goog.require('goog.testing.StrictMock');21goog.require('goog.testing.asserts');22goog.require('goog.testing.jsunit');23goog.require('goog.testing.stacktrace');24goog.require('goog.testing.stacktrace.Frame');25goog.require('goog.userAgent');26var stubs = new goog.testing.PropertyReplacer();27var expectedFailures;28function setUpPage() {29 expectedFailures = new goog.testing.ExpectedFailures();30}31function setUp() {32 stubs.set(goog.testing.stacktrace, 'isClosureInspectorActive_', function() {33 return false;34 });35}36function tearDown() {37 stubs.reset();38 expectedFailures.handleTearDown();39}40function testParseStackFrameInV8() {41 var frameString = ' at Error (unknown source)';42 var frame = goog.testing.stacktrace.parseStackFrame_(frameString);43 var expected = new goog.testing.stacktrace.Frame('', 'Error', '', '');44 assertObjectEquals('exception name only', expected, frame);45 frameString = ' at Object.assert (file:///.../asserts.js:29:10)';46 frame = goog.testing.stacktrace.parseStackFrame_(frameString);47 expected = new goog.testing.stacktrace.Frame(48 'Object', 'assert', '', 'file:///.../asserts.js:29:10');49 assertObjectEquals('context object + function name + url', expected, frame);50 frameString = ' at Object.x.y.z (/Users/bob/file.js:564:9)';51 frame = goog.testing.stacktrace.parseStackFrame_(frameString);52 expected = new goog.testing.stacktrace.Frame(53 'Object.x.y', 'z', '', '/Users/bob/file.js:564:9');54 assertObjectEquals(55 'nested context object + function name + url', expected, frame);56 frameString = ' at http://www.example.com/jsunit.js:117:13';57 frame = goog.testing.stacktrace.parseStackFrame_(frameString);58 expected = new goog.testing.stacktrace.Frame(59 '', '', '', 'http://www.example.com/jsunit.js:117:13');60 assertObjectEquals('url only', expected, frame);61 frameString = ' at [object Object].exec [as execute] (file:///foo)';62 frame = goog.testing.stacktrace.parseStackFrame_(frameString);63 expected = new goog.testing.stacktrace.Frame(64 '[object Object]', 'exec', 'execute', 'file:///foo');65 assertObjectEquals('function alias', expected, frame);66 frameString = ' at new Class (file:///foo)';67 frame = goog.testing.stacktrace.parseStackFrame_(frameString);68 expected =69 new goog.testing.stacktrace.Frame('', 'new Class', '', 'file:///foo');70 assertObjectEquals('constructor call', expected, frame);71 frameString = ' at new <anonymous> (file:///foo)';72 frame = goog.testing.stacktrace.parseStackFrame_(frameString);73 expected = new goog.testing.stacktrace.Frame(74 '', 'new <anonymous>', '', 'file:///foo');75 assertObjectEquals('anonymous constructor call', expected, frame);76 frameString = ' at Array.forEach (native)';77 frame = goog.testing.stacktrace.parseStackFrame_(frameString);78 expected = new goog.testing.stacktrace.Frame('Array', 'forEach', '', '');79 assertObjectEquals('native function call', expected, frame);80 frameString = ' at foo (eval at file://bar)';81 frame = goog.testing.stacktrace.parseStackFrame_(frameString);82 expected =83 new goog.testing.stacktrace.Frame('', 'foo', '', 'eval at file://bar');84 assertObjectEquals('eval', expected, frame);85 frameString = ' at foo.bar (closure/goog/foo.js:11:99)';86 frame = goog.testing.stacktrace.parseStackFrame_(frameString);87 expected = new goog.testing.stacktrace.Frame(88 'foo', 'bar', '', 'closure/goog/foo.js:11:99');89 assertObjectEquals('Path without schema', expected, frame);90 // In the Chrome console, execute: console.log(eval('Error().stack')).91 frameString =92 ' at eval (eval at <anonymous> (unknown source), <anonymous>:1:1)';93 frame = goog.testing.stacktrace.parseStackFrame_(frameString);94 expected = new goog.testing.stacktrace.Frame(95 '', 'eval', '', 'eval at <anonymous> (unknown source), <anonymous>:1:1');96 assertObjectEquals('nested eval', expected, frame);97}98function testParseStackFrameInOpera() {99 var frameString = '@';100 var frame = goog.testing.stacktrace.parseStackFrame_(frameString);101 var expected = new goog.testing.stacktrace.Frame('', '', '', '');102 assertObjectEquals('empty frame', expected, frame);103 frameString = '@javascript:console.log(Error().stack):1';104 frame = goog.testing.stacktrace.parseStackFrame_(frameString);105 expected = new goog.testing.stacktrace.Frame(106 '', '', '', 'javascript:console.log(Error().stack):1');107 assertObjectEquals('javascript path only', expected, frame);108 frameString = '@file:///foo:42';109 frame = goog.testing.stacktrace.parseStackFrame_(frameString);110 expected = new goog.testing.stacktrace.Frame('', '', '', 'file:///foo:42');111 assertObjectEquals('path only', expected, frame);112 // (function go() { throw Error() })()113 // var c = go; c()114 frameString = 'go([arguments not available])@';115 frame = goog.testing.stacktrace.parseStackFrame_(frameString);116 expected = new goog.testing.stacktrace.Frame('', 'go', '', '');117 assertObjectEquals('name and empty path', expected, frame);118 frameString = 'go([arguments not available])@file:///foo:42';119 frame = goog.testing.stacktrace.parseStackFrame_(frameString);120 expected = new goog.testing.stacktrace.Frame('', 'go', '', 'file:///foo:42');121 assertObjectEquals('name and path', expected, frame);122 // (function() { throw Error() })()123 frameString =124 '<anonymous function>([arguments not available])@file:///foo:42';125 frame = goog.testing.stacktrace.parseStackFrame_(frameString);126 expected = new goog.testing.stacktrace.Frame('', '', '', 'file:///foo:42');127 assertObjectEquals('anonymous function', expected, frame);128 // var b = {foo: function() { throw Error() }}129 frameString = '<anonymous function: foo>()@file:///foo:42';130 frame = goog.testing.stacktrace.parseStackFrame_(frameString);131 expected = new goog.testing.stacktrace.Frame('', 'foo', '', 'file:///foo:42');132 assertObjectEquals('object literal function', expected, frame);133 // var c = {}; c.foo = function() { throw Error() }134 frameString = '<anonymous function: c.foo>()@file:///foo:42';135 frame = goog.testing.stacktrace.parseStackFrame_(frameString);136 expected =137 new goog.testing.stacktrace.Frame('c', 'foo', '', 'file:///foo:42');138 assertObjectEquals('named object literal function', expected, frame);139 frameString = '<anonymous function: Foo.prototype.bar>()@';140 frame = goog.testing.stacktrace.parseStackFrame_(frameString);141 expected = new goog.testing.stacktrace.Frame('Foo.prototype', 'bar', '', '');142 assertObjectEquals('prototype function', expected, frame);143 frameString = '<anonymous function: goog.Foo.prototype.bar>()@';144 frame = goog.testing.stacktrace.parseStackFrame_(frameString);145 expected =146 new goog.testing.stacktrace.Frame('goog.Foo.prototype', 'bar', '', '');147 assertObjectEquals('namespaced prototype function', expected, frame);148}149// All test strings are parsed with the conventional and long150// frame algorithms.151function testParseStackFrameInFirefox() {152 var frameString = 'Error("Assertion failed")@:0';153 var frame = goog.testing.stacktrace.parseStackFrame_(frameString);154 var expected = new goog.testing.stacktrace.Frame('', 'Error', '', '');155 assertObjectEquals('function name + arguments', expected, frame);156 frameString = '()@file:///foo:42';157 frame = goog.testing.stacktrace.parseStackFrame_(frameString);158 expected = new goog.testing.stacktrace.Frame('', '', '', 'file:///foo:42');159 assertObjectEquals('anonymous function', expected, frame);160 frameString = '@javascript:alert(0)';161 frame = goog.testing.stacktrace.parseStackFrame_(frameString);162 expected =163 new goog.testing.stacktrace.Frame('', '', '', 'javascript:alert(0)');164 assertObjectEquals('anonymous function', expected, frame);165}166// All test strings are parsed with the conventional and long167// frame algorithms.168function testParseStackFrameInFirefoxWithQualifiedName() {169 var frameString = 'ns.method@http://some.thing/a.js:1:2';170 var frame = goog.testing.stacktrace.parseStackFrame_(frameString);171 var expected = new goog.testing.stacktrace.Frame(172 '', 'ns.method', '', 'http://some.thing/a.js:1:2');173 assertObjectEquals('anonymous function', expected, frame);174}175function testCanonicalizeFrame() {176 var frame = new goog.testing.stacktrace.Frame(177 '<window>', 'foo', 'bar', 'http://x?a=1&b=2:1');178 assertEquals(179 'canonical stack frame, everything is escaped', '&lt;window&gt;.foo ' +180 '[as bar] at http://x?a=1&amp;b=2:1',181 frame.toCanonicalString());182}183function testDeobfuscateFunctionName() {184 goog.testing.stacktrace.setDeobfuscateFunctionName(function(name) {185 return name.replace(/\$/g, '.');186 });187 var frame = new goog.testing.stacktrace.Frame('', 'a$b$c', 'd$e', '');188 assertEquals(189 'deobfuscated function name', 'a.b.c [as d.e]',190 frame.toCanonicalString());191}192function testFramesToString() {193 var normalFrame = new goog.testing.stacktrace.Frame('', 'foo', '', '');194 var anonFrame = new goog.testing.stacktrace.Frame('', '', '', '');195 var frames = [normalFrame, anonFrame, null, anonFrame];196 var stack = goog.testing.stacktrace.framesToString_(frames);197 assertEquals('framesToString', '> foo\n> anonymous\n> (unknown)\n', stack);198}199function testFollowCallChain() {200 var func = function(var_args) {201 return goog.testing.stacktrace.followCallChain_();202 };203 // Created a fake type with a toString method.204 function LocalType(){};205 LocalType.prototype.toString = function() { return 'sg'; };206 // Create a mock with no expectations.207 var mock = new goog.testing.StrictMock(LocalType);208 mock.$replay();209 var frames = func(210 undefined, null, false, 0, '', {}, goog.nullFunction, mock,211 new LocalType);212 // Opera before version 10 doesn't support the caller attribute. In that213 // browser followCallChain_() returns empty stack trace.214 expectedFailures.expectFailureFor(215 goog.userAgent.OPERA && !goog.userAgent.isVersionOrHigher('10'));216 try {217 assertTrue('The stack trace consists of >=2 frames', frames.length >= 2);218 } catch (e) {219 expectedFailures.handleException(e);220 }221 if (frames.length >= 2) {222 assertEquals('innermost function is anonymous', '', frames[0].getName());223 // There are white space differences how browsers convert functions to224 // strings.225 assertEquals(226 'test function name', 'testFollowCallChain', frames[1].getName());227 }228 mock.$verify();229}230// Create a stack trace string with one modest record and one long record,231// Verify that all frames are parsed. The length of the long arg is set232// to blow Firefox 3x's stack if put through a RegExp.233function testParsingLongStackTrace() {234 var longArg =235 goog.string.buildString('(', goog.string.repeat('x', 1000000), ')');236 var stackTrace = goog.string.buildString(237 'shortFrame()@:0\n', 'longFrame', longArg,238 '@http://google.com/somescript:0\n');239 var frames = goog.testing.stacktrace.parse_(stackTrace);240 assertEquals('number of returned frames', 2, frames.length);241 var expected = new goog.testing.stacktrace.Frame('', 'shortFrame', '', '');242 assertObjectEquals('short frame', expected, frames[0]);243 assertNull('exception no frame', frames[1]);244}245function testParseStackFrameInIE10() {246 var frameString = ' at foo (http://bar:4000/bar.js:150:3)';247 var frame = goog.testing.stacktrace.parseStackFrame_(frameString);248 var expected = new goog.testing.stacktrace.Frame(249 '', 'foo', '', 'http://bar:4000/bar.js:150:3');250 assertObjectEquals('name and path', expected, frame);251 frameString = ' at Anonymous function (http://bar:4000/bar.js:150:3)';252 frame = goog.testing.stacktrace.parseStackFrame_(frameString);253 expected = new goog.testing.stacktrace.Frame(254 '', 'Anonymous function', '', 'http://bar:4000/bar.js:150:3');255 assertObjectEquals('Anonymous function', expected, frame);256 frameString = ' at Global code (http://bar:4000/bar.js:150:3)';257 frame = goog.testing.stacktrace.parseStackFrame_(frameString);258 expected = new goog.testing.stacktrace.Frame(259 '', 'Global code', '', 'http://bar:4000/bar.js:150:3');260 assertObjectEquals('Global code', expected, frame);261 frameString = ' at foo (eval code:150:3)';262 frame = goog.testing.stacktrace.parseStackFrame_(frameString);263 expected =264 new goog.testing.stacktrace.Frame('', 'foo', '', 'eval code:150:3');265 assertObjectEquals('eval code', expected, frame);266 frameString = ' at eval code (eval code:150:3)';267 frame = goog.testing.stacktrace.parseStackFrame_(frameString);268 expected =269 new goog.testing.stacktrace.Frame('', 'eval code', '', 'eval code:150:3');270 assertObjectEquals('nested eval', expected, frame);271}272function testParseStackFrameInIE11() {273 var frameString = ' at a.b.c (Unknown script code:150:3)';274 var frame = goog.testing.stacktrace.parseStackFrame_(frameString);275 var expected = new goog.testing.stacktrace.Frame(276 '', 'a.b.c', '', 'Unknown script code:150:3');277 assertObjectEquals('name and path', expected, frame);278}279function testParseStackFrameInEdge() {280 frameString = ' at a.b.c (http://host.com:80/some/file.js:101:2)';281 frame = goog.testing.stacktrace.parseStackFrame_(frameString);282 expected = new goog.testing.stacktrace.Frame(283 '', 'a.b.c', '', 'http://host.com:80/some/file.js:101:2');284 assertObjectEquals(expected, frame);285}286// Verifies that retrieving the stack trace works when the 'stack' field of an287// exception contains an array of CallSites instead of a string. This is the288// case when running in a lightweight V8 runtime (for instance, in gjstests),289// as opposed to a browser environment.290function testGetStackFrameWithV8CallSites() {291 // A function to create V8 CallSites. Note that CallSite is an extern and thus292 // cannot be mocked with closure mocks.293 function createCallSite(functionName, fileName, lineNumber, colNumber) {294 return {295 getFunctionName: goog.functions.constant(functionName),296 getFileName: goog.functions.constant(fileName),297 getLineNumber: goog.functions.constant(lineNumber),298 getColumnNumber: goog.functions.constant(colNumber)299 };300 }301 // Mock the goog.testing.stacktrace.getStack_ function, which normally302 // triggers an exception for the purpose of reading and returning its stack303 // trace. Here, pretend that V8 provided an array of CallSites instead of the304 // string that browsers provide.305 stubs.set(goog.testing.stacktrace, 'getNativeStack_', function() {306 return [307 createCallSite('fn1', 'file1', 1, 2),308 createCallSite('fn2', 'file2', 3, 4), createCallSite('fn3', 'file3', 5, 6)309 ];310 });311 // Retrieve the stacktrace. This should translate the array of CallSites into312 // a single multi-line string.313 var stackTrace = goog.testing.stacktrace.get();314 // Make sure the stack trace was translated correctly.315 var frames = stackTrace.split('\n');316 assertEquals(frames[0], '> fn1 at file1:1:2');317 assertEquals(frames[1], '> fn2 at file2:3:4');318 assertEquals(frames[2], '> fn3 at file3:5:6');...

Full Screen

Full Screen

stacktrace.js

Source:stacktrace.js Github

copy

Full Screen

1goog.provide('goog.testing.stacktrace'); 2goog.provide('goog.testing.stacktrace.Frame'); 3goog.testing.stacktrace.Frame = function(context, name, alias, args, path) { 4 this.context_ = context; 5 this.name_ = name; 6 this.alias_ = alias; 7 this.args_ = args; 8 this.path_ = path; 9}; 10goog.testing.stacktrace.Frame.prototype.getName = function() { 11 return this.name_; 12}; 13goog.testing.stacktrace.Frame.prototype.isAnonymous = function() { 14 return ! this.name_ || this.context_ == '[object Object]'; 15}; 16goog.testing.stacktrace.Frame.prototype.toCanonicalString = function() { 17 var htmlEscape = goog.testing.stacktrace.htmlEscape_; 18 var deobfuscate = goog.testing.stacktrace.maybeDeobfuscateFunctionName_; 19 var canonical =[this.context_ ? htmlEscape(this.context_) + '.': '', this.name_ ? htmlEscape(deobfuscate(this.name_)): 'anonymous', htmlEscape(this.args_), this.alias_ ? ' [as ' + htmlEscape(deobfuscate(this.alias_)) + ']': '']; 20 if(this.path_) { 21 canonical.push(' at '); 22 if(goog.testing.stacktrace.isClosureInspectorActive_()) { 23 var lineNumber = this.path_.match(/\d+$/)[0]; 24 canonical.push('<a href="" onclick="CLOSURE_INSPECTOR___.showLine(\'', htmlEscape(this.path_), '\', \'', lineNumber, '\'); return false">', htmlEscape(this.path_), '</a>'); 25 } else { 26 canonical.push(htmlEscape(this.path_)); 27 } 28 } 29 return canonical.join(''); 30}; 31goog.testing.stacktrace.MAX_DEPTH_ = 20; 32goog.testing.stacktrace.MAX_FIREFOX_FRAMESTRING_LENGTH_ = 500000; 33goog.testing.stacktrace.IDENTIFIER_PATTERN_ = '[a-zA-Z_$][\\w$]*'; 34goog.testing.stacktrace.CHROME_ALIAS_PATTERN_ = '(?: \\[as (' + goog.testing.stacktrace.IDENTIFIER_PATTERN_ + ')\\])?'; 35goog.testing.stacktrace.CHROME_FUNCTION_NAME_PATTERN_ = '(?:new )?(?:' + goog.testing.stacktrace.IDENTIFIER_PATTERN_ + '|<anonymous>)'; 36goog.testing.stacktrace.CHROME_FUNCTION_CALL_PATTERN_ = ' (?:(.*?)\\.)?(' + goog.testing.stacktrace.CHROME_FUNCTION_NAME_PATTERN_ + ')' + goog.testing.stacktrace.CHROME_ALIAS_PATTERN_; 37goog.testing.stacktrace.URL_PATTERN_ = '((?:http|https|file)://[^\\s)]+|javascript:.*)'; 38goog.testing.stacktrace.CHROME_URL_PATTERN_ = ' (?:' + '\\(unknown source\\)' + '|' + '\\(native\\)' + '|' + '\\((?:eval at )?' + goog.testing.stacktrace.URL_PATTERN_ + '\\)' + '|' + goog.testing.stacktrace.URL_PATTERN_ + ')'; 39goog.testing.stacktrace.CHROME_STACK_FRAME_REGEXP_ = new RegExp('^ at' + '(?:' + goog.testing.stacktrace.CHROME_FUNCTION_CALL_PATTERN_ + ')?' + goog.testing.stacktrace.CHROME_URL_PATTERN_ + '$'); 40goog.testing.stacktrace.FIREFOX_FUNCTION_CALL_PATTERN_ = '(' + goog.testing.stacktrace.IDENTIFIER_PATTERN_ + ')?' + '(\\(.*\\))?@'; 41goog.testing.stacktrace.FIREFOX_STACK_FRAME_REGEXP_ = new RegExp('^' + goog.testing.stacktrace.FIREFOX_FUNCTION_CALL_PATTERN_ + '(?::0|' + goog.testing.stacktrace.URL_PATTERN_ + ')$'); 42goog.testing.stacktrace.FUNCTION_SOURCE_REGEXP_ = new RegExp('^function (' + goog.testing.stacktrace.IDENTIFIER_PATTERN_ + ')'); 43goog.testing.stacktrace.followCallChain_ = function() { 44 var frames =[]; 45 var fn = arguments.callee.caller; 46 var depth = 0; 47 while(fn && depth < goog.testing.stacktrace.MAX_DEPTH_) { 48 var fnString = Function.prototype.toString.call(fn); 49 var match = fnString.match(goog.testing.stacktrace.FUNCTION_SOURCE_REGEXP_); 50 var functionName = match ? match[1]: ''; 51 var argsBuilder =['(']; 52 if(fn.arguments) { 53 for(var i = 0; i < fn.arguments.length; i ++) { 54 var arg = fn.arguments[i]; 55 if(i > 0) { 56 argsBuilder.push(', '); 57 } 58 if(goog.isString(arg)) { 59 argsBuilder.push('"', arg, '"'); 60 } else { 61 if(arg && arg['$replay']) { 62 argsBuilder.push('goog.testing.Mock'); 63 } else { 64 argsBuilder.push(String(arg)); 65 } 66 } 67 } 68 } else { 69 argsBuilder.push('unknown'); 70 } 71 argsBuilder.push(')'); 72 var args = argsBuilder.join(''); 73 frames.push(new goog.testing.stacktrace.Frame('', functionName, '', args, '')); 74 try { 75 fn = fn.caller; 76 } catch(e) { 77 break; 78 } 79 depth ++; 80 } 81 return frames; 82}; 83goog.testing.stacktrace.parseStackFrame_ = function(frameStr) { 84 var m = frameStr.match(goog.testing.stacktrace.CHROME_STACK_FRAME_REGEXP_); 85 if(m) { 86 return new goog.testing.stacktrace.Frame(m[1]|| '', m[2]|| '', m[3]|| '', '', m[4]|| m[5]|| ''); 87 } 88 if(frameStr.length > goog.testing.stacktrace.MAX_FIREFOX_FRAMESTRING_LENGTH_) { 89 return goog.testing.stacktrace.parseLongFirefoxFrame_(frameStr); 90 } 91 m = frameStr.match(goog.testing.stacktrace.FIREFOX_STACK_FRAME_REGEXP_); 92 if(m) { 93 return new goog.testing.stacktrace.Frame('', m[1]|| '', '', m[2]|| '', m[3]|| ''); 94 } 95 return null; 96}; 97goog.testing.stacktrace.parseLongFirefoxFrame_ = function(frameStr) { 98 var firstParen = frameStr.indexOf('('); 99 var lastAmpersand = frameStr.lastIndexOf('@'); 100 var lastColon = frameStr.lastIndexOf(':'); 101 var functionName = ''; 102 if((firstParen >= 0) &&(firstParen < lastAmpersand)) { 103 functionName = frameStr.substring(0, firstParen); 104 } 105 var loc = ''; 106 if((lastAmpersand >= 0) &&(lastAmpersand + 1 < lastColon)) { 107 loc = frameStr.substring(lastAmpersand + 1); 108 } 109 var args = ''; 110 if((firstParen >= 0 && lastAmpersand > 0) &&(firstParen < lastAmpersand)) { 111 args = frameStr.substring(firstParen, lastAmpersand); 112 } 113 return new goog.testing.stacktrace.Frame('', functionName, '', args, loc); 114}; 115goog.testing.stacktrace.deobfuscateFunctionName_; 116goog.testing.stacktrace.setDeobfuscateFunctionName = function(fn) { 117 goog.testing.stacktrace.deobfuscateFunctionName_ = fn; 118}; 119goog.testing.stacktrace.maybeDeobfuscateFunctionName_ = function(name) { 120 return goog.testing.stacktrace.deobfuscateFunctionName_ ? goog.testing.stacktrace.deobfuscateFunctionName_(name): name; 121}; 122goog.testing.stacktrace.isClosureInspectorActive_ = function() { 123 return Boolean(goog.global['CLOSURE_INSPECTOR___']&& goog.global['CLOSURE_INSPECTOR___']['supportsJSUnit']); 124}; 125goog.testing.stacktrace.htmlEscape_ = function(text) { 126 return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'); 127}; 128goog.testing.stacktrace.framesToString_ = function(frames) { 129 var lastIndex = frames.length - 1; 130 while(frames[lastIndex]&& frames[lastIndex].isAnonymous()) { 131 lastIndex --; 132 } 133 var privateAssertIndex = - 1; 134 for(var i = 0; i < frames.length; i ++) { 135 if(frames[i]&& frames[i].getName() == '_assert') { 136 privateAssertIndex = i; 137 break; 138 } 139 } 140 var canonical =[]; 141 for(var i = privateAssertIndex + 1; i <= lastIndex; i ++) { 142 canonical.push('> '); 143 if(frames[i]) { 144 canonical.push(frames[i].toCanonicalString()); 145 } else { 146 canonical.push('(unknown)'); 147 } 148 canonical.push('\n'); 149 } 150 return canonical.join(''); 151}; 152goog.testing.stacktrace.parse_ = function(stack) { 153 var lines = stack.replace(/\s*$/, '').split('\n'); 154 var frames =[]; 155 for(var i = 0; i < lines.length; i ++) { 156 frames.push(goog.testing.stacktrace.parseStackFrame_(lines[i])); 157 } 158 return frames; 159}; 160goog.testing.stacktrace.canonicalize = function(stack) { 161 var frames = goog.testing.stacktrace.parse_(stack); 162 return goog.testing.stacktrace.framesToString_(frames); 163}; 164goog.testing.stacktrace.get = function() { 165 var stack = new Error().stack; 166 var frames = stack ? goog.testing.stacktrace.parse_(stack): goog.testing.stacktrace.followCallChain_(); 167 return goog.testing.stacktrace.framesToString_(frames); 168}; ...

Full Screen

Full Screen

DebuggerPresentationUtils.js

Source:DebuggerPresentationUtils.js Github

copy

Full Screen

1// Copyright 2015 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4WebInspector.DebuggerPresentationUtils = {}5/**6 * @param {?WebInspector.DebuggerModel} debuggerModel7 * @param {!Array.<!ConsoleAgent.CallFrame>=} stackTrace8 * @param {!ConsoleAgent.AsyncStackTrace=} asyncStackTrace9 * @param {boolean=} showBlackboxed10 * @return {?ConsoleAgent.CallFrame}11 */12WebInspector.DebuggerPresentationUtils.callFrameAnchorFromStackTrace = function(debuggerModel, stackTrace, asyncStackTrace, showBlackboxed)13{14 /**15 * @param {?Array.<!ConsoleAgent.CallFrame>=} stackTrace16 * @return {?ConsoleAgent.CallFrame}17 */18 function innerCallFrameAnchorFromStackTrace(stackTrace)19 {20 if (!stackTrace || !stackTrace.length)21 return null;22 if (showBlackboxed)23 return stackTrace[0];24 for (var i = 0; i < stackTrace.length; ++i) {25 var script = debuggerModel && debuggerModel.scriptForId(stackTrace[i].scriptId);26 var blackboxed = script ?27 WebInspector.BlackboxSupport.isBlackboxed(script.sourceURL, script.isContentScript()) :28 WebInspector.BlackboxSupport.isBlackboxedURL(stackTrace[i].url);29 if (!blackboxed)30 return stackTrace[i];31 }32 return null;33 }34 var callFrame = innerCallFrameAnchorFromStackTrace(stackTrace);35 if (callFrame)36 return callFrame;37 while (asyncStackTrace) {38 callFrame = innerCallFrameAnchorFromStackTrace(asyncStackTrace.callFrames);39 if (callFrame)40 return callFrame;41 asyncStackTrace = asyncStackTrace.asyncStackTrace;42 }43 return stackTrace ? stackTrace[0] : null;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.on('uncaught:exception', (err, runnable) => {2 })3 describe('My First Test', () => {4 it('Does not do much!', () => {5 expect(true).to.equal(true)6 })7 })8 Cypress.on('uncaught:exception', (err, runnable) => {9 })10 Cypress.on('uncaught:exception', (err, runnable) => {11 })12 Cypress.on('uncaught:exception', (err, runnable) => {13 })14 Cypress.on('uncaught:exception', (err, runnable) => {15 })16 Cypress.on('uncaught:exception', (err, runnable) => {17 })18 Cypress.on('uncaught:exception', (err, runnable) => {19 })20 Cypress.on('uncaught:exception', (err, runnable) => {21 })22 Cypress.on('uncaught:exception', (err, runnable) => {23 })24 Cypress.on('uncaught:exception', (err, runnable) => {25 })26 Cypress.on('uncaught:exception', (err, runnable) => {

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.window().then((win) => {2 const stack = win.stackTrace();3 console.log(stack);4});5Cypress.Commands.add('stackTrace', () => {6 return Cypress._.map(Cypress.runner.stack, (frame) => {7 return {8 };9 });10});11Cypress.on('window:before:load', (win) => {12 win.stackTrace = () => {13 return Cypress._.map(Cypress.runner.stack, (frame) => {14 return {15 };16 });17 };18});19Cypress.Commands.add('stackTrace', () => {20 return Cypress._.map(Cypress.runner.stack, (frame) => {21 return {22 };23 });24});25Cypress.on('window:before:load', (win) => {26 win.stackTrace = () => {27 return Cypress._.map(Cypress.runner.stack, (frame) => {28 return {29 };30 });31 };32});33Cypress.Commands.add('stackTrace', () => {34 return Cypress._.map(Cypress.runner.stack, (frame) => {35 return {36 };37 });38});39Cypress.on('window:before:

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.on('uncaught:exception', (err, runnable) => {2 console.log(err.stack)3})4Cypress.on('uncaught:exception', (err, runnable) => {5 console.log(err.stack)6})7Cypress.on('uncaught:exception', (err, runnable) => {8 console.log(err.stack)9})10Cypress.on('uncaught:exception', (err, runnable) => {11 console.log(err.stack)12})13Cypress.on('uncaught:exception', (err, runnable) => {14 console.log(err.stack)15})16Cypress.on('uncaught:exception', (err, runnable) => {17 console.log(err.stack)18})19Cypress.on('uncaught:exception', (err, runnable) => {20 console.log(err.stack)21})22Cypress.on('uncaught:exception', (err, runnable) => {23 console.log(err.stack)24})25Cypress.on('uncaught:exception', (err, runnable) => {26 console.log(err.stack)

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