@zendesk/retrace
Version:
define and capture Product Operation Traces along with computed metrics with an optional friendly React beacon API
81 lines • 5.19 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const trace_flon2op03qt_ticket_activated_json_1 = __importDefault(require("./__fixtures__/trace-flon2op03qt-ticket.activated.json"));
const mapOperationForVisualization_1 = require("./mapOperationForVisualization");
(0, vitest_1.describe)('mapOperationForVisualizationHierarchical', () => {
(0, vitest_1.it)('should process the fixture trace data', () => {
const result = (0, mapOperationForVisualization_1.mapOperationForVisualizationHierarchical)(trace_flon2op03qt_ticket_activated_json_1.default);
(0, vitest_1.expect)(result).not.toBeNull();
(0, vitest_1.expect)(result?.name).toBeDefined();
(0, vitest_1.expect)(result?.spans).toBeInstanceOf(Array);
(0, vitest_1.expect)(result?.expandedSpanIds).toBeInstanceOf(Set);
});
(0, vitest_1.it)('should create hierarchical spans with proper structure', () => {
const result = (0, mapOperationForVisualization_1.mapOperationForVisualizationHierarchical)(trace_flon2op03qt_ticket_activated_json_1.default);
(0, vitest_1.expect)(result).not.toBeNull();
// Check that spans have hierarchical properties
if (result && result.spans.length > 0) {
const firstSpan = result.spans[0];
(0, vitest_1.expect)(firstSpan).toBeDefined();
if (firstSpan) {
(0, vitest_1.expect)(firstSpan).toHaveProperty('children');
(0, vitest_1.expect)(firstSpan).toHaveProperty('isExpanded');
(0, vitest_1.expect)(firstSpan).toHaveProperty('depth');
(0, vitest_1.expect)(firstSpan).toHaveProperty('parentId');
(0, vitest_1.expect)(Array.isArray(firstSpan.children)).toBe(true);
(0, vitest_1.expect)(typeof firstSpan.isExpanded).toBe('boolean');
(0, vitest_1.expect)(typeof firstSpan.depth).toBe('number');
}
}
});
(0, vitest_1.it)('should handle spans with parent-child relationships', () => {
const result = (0, mapOperationForVisualization_1.mapOperationForVisualizationHierarchical)(trace_flon2op03qt_ticket_activated_json_1.default);
(0, vitest_1.expect)(result).not.toBeNull();
if (result) {
// Find spans that have children
const spansWithChildren = result.spans.filter((span) => span.children.length > 0);
if (spansWithChildren.length > 0) {
const parentSpan = spansWithChildren[0];
(0, vitest_1.expect)(parentSpan.children.length).toBeGreaterThan(0);
// Check that children have correct parent references
for (const child of parentSpan.children) {
(0, vitest_1.expect)(child.parentId).toBe(parentSpan.span.id);
(0, vitest_1.expect)(child.depth).toBe(parentSpan.depth + 1);
}
}
}
});
(0, vitest_1.it)('should maintain the same data as the flat version', () => {
const result = (0, mapOperationForVisualization_1.mapOperationForVisualizationHierarchical)(trace_flon2op03qt_ticket_activated_json_1.default);
(0, vitest_1.expect)(result).not.toBeNull();
if (result) {
// Should have the same basic structure
(0, vitest_1.expect)(result.name).toBeDefined();
(0, vitest_1.expect)(result.duration).toBeGreaterThan(0);
(0, vitest_1.expect)(result.spanTypes).toBeInstanceOf(Set);
(0, vitest_1.expect)(result.uniqueGroups).toBeInstanceOf(Array);
// Should have an expansion state
(0, vitest_1.expect)(result.expandedSpanIds).toBeInstanceOf(Set);
(0, vitest_1.expect)(result.expandedSpanIds.size).toBe(0); // Default to no expansions
}
});
(0, vitest_1.it)('should handle filtering options', () => {
const resultWithResources = (0, mapOperationForVisualization_1.mapOperationForVisualizationHierarchical)(trace_flon2op03qt_ticket_activated_json_1.default, { displayResources: true });
const resultWithoutResources = (0, mapOperationForVisualization_1.mapOperationForVisualizationHierarchical)(trace_flon2op03qt_ticket_activated_json_1.default, { displayResources: false });
(0, vitest_1.expect)(resultWithResources).not.toBeNull();
(0, vitest_1.expect)(resultWithoutResources).not.toBeNull();
if (resultWithResources && resultWithoutResources) {
// Should have different numbers of spans based on filtering
const resourceSpansWithFilter = resultWithResources.spans.filter((span) => span.type === 'resource');
const resourceSpansWithoutFilter = resultWithoutResources.spans.filter((span) => span.type === 'resource');
if (resourceSpansWithFilter.length > 0) {
(0, vitest_1.expect)(resourceSpansWithoutFilter.length).toBe(0);
}
}
});
});
//# sourceMappingURL=mapOperationForVisualization.test.js.map