How to use TraceSelectors method in tracetest

Best JavaScript code snippet using tracetest

trace.test.js

Source:trace.test.js Github

copy

Full Screen

1// Copyright (c) 2017 Uber Technologies, Inc.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.14import _values from 'lodash/values';15import { followsFromRef } from './trace.fixture';16import {17 getSpanId,18 getSpanName,19 getSpanParentId,20 getSpanProcess,21 getSpanProcessId,22 getSpanServiceName,23 getSpanTimestamp,24} from './span';25import * as traceSelectors from './trace';26import traceGenerator from '../demo/trace-generators';27import { numberSortComparator } from '../utils/sort';28const generatedTrace = traceGenerator.trace({ numberOfSpans: 45 });29it('getTraceId() should return the traceID', () => {30 expect(traceSelectors.getTraceId(generatedTrace)).toBe(generatedTrace.traceID);31});32it('hydrateSpansWithProcesses() should return the trace with processes on each span', () => {33 const hydratedTrace = traceSelectors.hydrateSpansWithProcesses(generatedTrace);34 hydratedTrace.spans.forEach((span) =>35 expect(getSpanProcess(span)).toBe(generatedTrace.processes[getSpanProcessId(span)])36 );37});38it('getTraceSpansAsMap() should return a map of all of the spans', () => {39 const spanMap = traceSelectors.getTraceSpansAsMap(generatedTrace);40 [...spanMap.entries()].forEach((pair) => {41 expect(pair[1]).toEqual(generatedTrace.spans.find((span) => getSpanId(span) === pair[0]));42 });43});44describe('getTraceSpanIdsAsTree()', () => {45 it('builds the tree properly', () => {46 const tree = traceSelectors.getTraceSpanIdsAsTree(generatedTrace);47 const spanMap = traceSelectors.getTraceSpansAsMap(generatedTrace);48 tree.walk((value, node) => {49 const expectedParentValue = value === traceSelectors.TREE_ROOT_ID ? null : value;50 node.children.forEach((childNode) => {51 expect(getSpanParentId(spanMap.get(childNode.value))).toBe(expectedParentValue);52 });53 });54 });55 it('#115 - handles FOLLOW_FROM refs', () => {56 expect(() => traceSelectors.getTraceSpanIdsAsTree(followsFromRef)).not.toThrow();57 });58});59it('getParentSpan() should return the parent span of the tree', () => {60 expect(traceSelectors.getParentSpan(generatedTrace)).toBe(61 traceSelectors62 .getTraceSpansAsMap(generatedTrace)63 .get(traceSelectors.getTraceSpanIdsAsTree(generatedTrace).children[0].value)64 );65});66it('getParentSpan() should return the first span if there are multiple parents', () => {67 const initialTimestamp = new Date().getTime() * 1000;68 const firstSpan = {69 startTime: initialTimestamp,70 spanID: 'my-span-1',71 references: [],72 };73 const trace = {74 spans: [75 {76 startTime: initialTimestamp + 2000,77 spanID: 'my-span-3',78 references: [],79 },80 firstSpan,81 {82 startTime: initialTimestamp + 1000,83 spanID: 'my-span-2',84 references: [],85 },86 ],87 };88 expect(traceSelectors.getParentSpan(trace)).toBe(firstSpan);89});90it('getTraceName() should return a formatted name for the first span', () => {91 const hydratedTrace = traceSelectors.hydrateSpansWithProcesses(generatedTrace);92 const parentSpan = traceSelectors.getParentSpan(hydratedTrace);93 expect(traceSelectors.getTraceName(hydratedTrace)).toBe(94 `${getSpanServiceName(parentSpan)}: ${getSpanName(parentSpan)}`95 );96});97it('getTraceSpanCount() should return the length of the spans array', () => {98 expect(traceSelectors.getTraceSpanCount(generatedTrace)).toBe(generatedTrace.spans.length);99});100it('getTraceDuration() should return the duration for the span', () => {101 expect(traceSelectors.getTraceDuration(generatedTrace)).toBe(generatedTrace.spans[0].duration);102});103it('getTraceTimestamp() should return the first timestamp for the conventional trace', () => {104 expect(traceSelectors.getTraceTimestamp(generatedTrace)).toBe(generatedTrace.spans[0].startTime);105});106it('getTraceDepth() should determine the total depth of the trace tree', () => {107 expect(traceSelectors.getTraceDepth(generatedTrace)).toBe(108 traceSelectors.getTraceSpanIdsAsTree(generatedTrace).depth - 1109 );110});111it('getSpanDepthForTrace() should determine the depth of a given span in the parent', () => {112 function testDepthCalc(span) {113 let depth = 2;114 let currentId = getSpanParentId(span);115 const findCurrentSpanById = (item) => getSpanId(item) === currentId;116 while (currentId !== getSpanId(generatedTrace.spans[0])) {117 depth++;118 currentId = getSpanParentId(generatedTrace.spans.find(findCurrentSpanById));119 }120 // console.log('hypothetical depth', depth);121 expect(122 traceSelectors.getSpanDepthForTrace({123 trace: generatedTrace,124 span,125 })126 ).toBe(depth);127 }128 // test depth calculations for a few random spans129 testDepthCalc(generatedTrace.spans[1]);130 testDepthCalc(generatedTrace.spans[Math.floor(generatedTrace.spans.length / 2)]);131 testDepthCalc(generatedTrace.spans[Math.floor(generatedTrace.spans.length / 4)]);132 testDepthCalc(generatedTrace.spans[Math.floor(generatedTrace.spans.length * 0.75)]);133});134it('getTraceServices() should return an unique array of all services in the trace', () => {135 const svcs = [...traceSelectors.getTraceServices(generatedTrace)].sort();136 const set = new Set(_values(generatedTrace.processes).map((v) => v.serviceName));137 const setSvcs = [...set.values()].sort();138 expect(svcs).toEqual(setSvcs);139});140it('getTraceServiceCount() should return the length of the service list', () => {141 expect(traceSelectors.getTraceServiceCount(generatedTrace)).toBe(142 Object.values(generatedTrace.processes).reduce((results, process) => results.add(process.serviceName), new Set())143 .size144 );145});146it('formatDurationForUnit() should use the formatters to return the proper value', () => {147 expect(traceSelectors.formatDurationForUnit({ duration: 302000, unit: 'ms' })).toBe('302ms');148 expect(traceSelectors.formatDurationForUnit({ duration: 1302000, unit: 'ms' })).toBe('1302ms');149 expect(traceSelectors.formatDurationForUnit({ duration: 1302000, unit: 's' })).toBe('1.302s');150 expect(traceSelectors.formatDurationForUnit({ duration: 90000, unit: 's' })).toBe('0.09s');151});152it('formatDurationForTrace() should return a ms value for traces shorter than a second', () => {153 expect(154 traceSelectors.formatDurationForTrace({155 trace: {156 spans: [{ duration: 600000 }],157 },158 duration: 302000,159 })160 ).toBe('302ms');161});162it('formatDurationForTrace() should return a s value for traces longer than a second', () => {163 expect(164 traceSelectors.formatDurationForTrace({165 trace: {166 ...generatedTrace,167 spans: generatedTrace.spans.concat([168 {169 ...generatedTrace.spans[0],170 duration: 1000000,171 },172 ]),173 },174 duration: 302000,175 })176 ).toBe('0.302s');177 expect(178 traceSelectors.formatDurationForTrace({179 trace: {180 ...generatedTrace,181 spans: generatedTrace.spans.concat([182 {183 ...generatedTrace.spans[0],184 duration: 1200000,185 },186 ]),187 },188 duration: 302000,189 })190 ).toBe('0.302s');191});192it('getSortedSpans() should sort spans given a sort object', () => {193 expect(194 traceSelectors.getSortedSpans({195 trace: generatedTrace,196 spans: generatedTrace.spans,197 sort: {198 dir: 1,199 comparator: numberSortComparator,200 selector: getSpanTimestamp,201 },202 })203 ).toEqual([...generatedTrace.spans].sort((spanA, spanB) => spanA.startTime - spanB.startTime));204 expect(205 traceSelectors.getSortedSpans({206 trace: generatedTrace,207 spans: generatedTrace.spans,208 sort: {209 dir: -1,210 comparator: numberSortComparator,211 selector: getSpanTimestamp,212 },213 })214 ).toEqual([...generatedTrace.spans].sort((spanA, spanB) => spanB.startTime - spanA.startTime));215});216it('getTreeSizeForTraceSpan() should return the size for the parent span', () => {217 expect(218 traceSelectors.getTreeSizeForTraceSpan({219 trace: generatedTrace,220 span: generatedTrace.spans[0],221 })222 ).toBe(generatedTrace.spans.length - 1);223});224it('getTreeSizeForTraceSpan() should return the size for a child span', () => {225 expect(226 traceSelectors.getTreeSizeForTraceSpan({227 trace: generatedTrace,228 span: generatedTrace.spans[1],229 })230 ).toBe(traceSelectors.getTraceSpanIdsAsTree(generatedTrace).find(generatedTrace.spans[1].spanID).size - 1);231});232it('getTreeSizeForTraceSpan() should return -1 for an absent span', () => {233 expect(234 traceSelectors.getTreeSizeForTraceSpan({235 trace: generatedTrace,236 span: { spanID: 'whatever' },237 })238 ).toBe(-1);239});240it('getTraceName() should return the trace name based on the parentSpan', () => {241 const serviceName = generatedTrace.processes[generatedTrace.spans[0].processID].serviceName;242 const operationName = generatedTrace.spans[0].operationName;243 expect(traceSelectors.getTraceName(generatedTrace)).toBe(`${serviceName}: ${operationName}`);244});245it('omitCollapsedSpans() should filter out collapsed spans', () => {246 const span = generatedTrace.spans[1];247 const size = traceSelectors.getTraceSpanIdsAsTree(generatedTrace).find(span.spanID).size - 1;248 expect(249 traceSelectors.omitCollapsedSpans({250 trace: generatedTrace,251 spans: generatedTrace.spans,252 collapsed: [span.spanID],253 }).length254 ).toBe(generatedTrace.spans.length - size);255});256it('getTicksForTrace() should return a list of ticks given interval parameters', () => {257 const timestamp = new Date().getTime() * 1000;258 const trace = {259 spans: [260 {261 startTime: timestamp,262 duration: 3000000,263 },264 ],265 };266 expect(267 traceSelectors.getTicksForTrace({268 trace,269 interval: 3,270 width: 10,271 })272 ).toEqual([273 { timestamp, width: 10 },274 { timestamp: timestamp + 1000000, width: 10 },275 { timestamp: timestamp + 2000000, width: 10 },276 { timestamp: timestamp + 3000000, width: 10 },277 ]);278});279it('getTicksForTrace() should use defaults', () => {280 const timestamp = new Date().getTime() * 1000;281 const trace = {282 spans: [283 {284 startTime: timestamp,285 duration: 4000000,286 },287 ],288 };289 expect(traceSelectors.getTicksForTrace({ trace })).toEqual([290 { timestamp, width: traceSelectors.DEFAULT_TICK_WIDTH },291 {292 timestamp: timestamp + 1000000,293 width: traceSelectors.DEFAULT_TICK_WIDTH,294 },295 {296 timestamp: timestamp + 2000000,297 width: traceSelectors.DEFAULT_TICK_WIDTH,298 },299 {300 timestamp: timestamp + 3000000,301 width: traceSelectors.DEFAULT_TICK_WIDTH,302 },303 {304 timestamp: timestamp + 4000000,305 width: traceSelectors.DEFAULT_TICK_WIDTH,306 },307 ]);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var trace = require('tracetest.js');2var traceObj = new trace.TraceSelectors();3traceObj.TraceSelectors('test');4exports.TraceSelectors = function(){5 this.TraceSelectors = function(selector){6 console.log(selector);7 }8}9Your name to display (optional):10Your name to display (optional):11var trace = require('./tracetest.js');12Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2var traceSelectors = tracetest.TraceSelectors();3traceSelectors.push({4});5traceSelectors.push({6});7tracetest.TraceSelectors(traceSelectors);8tracetest.RunTest({9});10tracetest.RunTest({11});12tracetest.RunTest({13});14tracetest.RunTest({15});16tracetest.RunTest({17});18tracetest.RunTest({19});20tracetest.RunTest({21});22tracetest.RunTest({23});24tracetest.RunTest({25});26tracetest.RunTest({27});28tracetest.RunTest({29});30tracetest.RunTest({31});32tracetest.RunTest({

Full Screen

Using AI Code Generation

copy

Full Screen

1var trace = require('tracetest');2var traceSelectors = trace.TraceSelectors;3var trace = new traceSelectors();4trace.addSelector('selector1');5trace.addSelector('selector2');6trace.addSelector('selector3');7trace.addSelector('selector4');8trace.addSelector('selector5');9trace.addSelector('selector6');10trace.addSelector('selector7');11trace.addSelector('selector8');12trace.addSelector('selector9');13trace.addSelector('selector10');14trace.addSelector('selector11');15trace.addSelector('selector12');16trace.addSelector('selector13');17trace.addSelector('selector14');18trace.addSelector('selector15');19trace.addSelector('selector16');20trace.addSelector('selector17');21trace.addSelector('selector18');22trace.addSelector('selector19');23trace.addSelector('selector20');24trace.addSelector('selector21');25trace.addSelector('selector22');26trace.addSelector('selector23');27trace.addSelector('selector24');28trace.addSelector('selector25');29trace.addSelector('selector26');30trace.addSelector('selector27');31trace.addSelector('selector28');32trace.addSelector('selector29');33trace.addSelector('selector30');34trace.addSelector('selector31');35trace.addSelector('selector32');36trace.addSelector('selector33');37trace.addSelector('selector34');38trace.addSelector('selector35');39trace.addSelector('selector36');40trace.addSelector('selector37');41trace.addSelector('selector38');42trace.addSelector('selector39

Full Screen

Using AI Code Generation

copy

Full Screen

1var trace = tracetest.Tracer{}2trace.RegisterSpanServer(&spanServer)3trace.RegisterSpanServer(&spanServer2)4trace.RegisterSpanServer(&spanServer3)5trace.RegisterSpanServer(&spanServer4)6trace.RegisterSpanServer(&spanServer5)7trace.RegisterSpanServer(&spanServer6)8trace.RegisterSpanServer(&spanServer7)9trace.RegisterSpanServer(&spanServer8)10trace.RegisterSpanServer(&spanServer9)11trace.RegisterSpanServer(&spanServer10)12trace.RegisterSpanServer(&spanServer11)13trace.RegisterSpanServer(&spanServer12)14trace.RegisterSpanServer(&spanServer13)15trace.RegisterSpanServer(&spanServer14)16trace.RegisterSpanServer(&spanServer15)17trace.RegisterSpanServer(&spanServer16)18trace.RegisterSpanServer(&spanServer17)19trace.RegisterSpanServer(&spanServer18)20trace.RegisterSpanServer(&spanServer19)21trace.RegisterSpanServer(&spanServer20)22trace.RegisterSpanServer(&spanServer21)23trace.RegisterSpanServer(&spanServer22)24trace.RegisterSpanServer(&spanServer23)25trace.RegisterSpanServer(&spanServer24)26trace.RegisterSpanServer(&spanServer25)27trace.RegisterSpanServer(&spanServer26)28trace.RegisterSpanServer(&spanServer27)29trace.RegisterSpanServer(&spanServer28)30trace.RegisterSpanServer(&spanServer29)31trace.RegisterSpanServer(&spanServer30)32trace.RegisterSpanServer(&spanServer31)33trace.RegisterSpanServer(&spanServer32)34trace.RegisterSpanServer(&spanServer33)35trace.RegisterSpanServer(&spanServer34)36trace.RegisterSpanServer(&spanServer35)37trace.RegisterSpanServer(&spanServer36)38trace.RegisterSpanServer(&spanServer37)39trace.RegisterSpanServer(&spanServer38)40trace.RegisterSpanServer(&spanServer39)41trace.RegisterSpanServer(&spanServer40)42trace.RegisterSpanServer(&spanServer41)43trace.RegisterSpanServer(&spanServer42)44trace.RegisterSpanServer(&spanServer43)45trace.RegisterSpanServer(&spanServer44)46trace.RegisterSpanServer(&spanServer45)47trace.RegisterSpanServer(&spanServer46)48trace.RegisterSpanServer(&spanServer47)49trace.RegisterSpanServer(&spanServer48)50trace.RegisterSpanServer(&spanServer49)51trace.RegisterSpanServer(&spanServer50)52trace.RegisterSpanServer(&spanServer51)53trace.RegisterSpanServer(&spanServer52)54trace.RegisterSpanServer(&spanServer53)

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 tracetest 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