|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | + |
| 7 | +import React from 'react'; |
| 8 | +import { Stackframe } from '../../../../typings/es_schemas/raw/fields/stackframe'; |
| 9 | +import { renderWithTheme } from '../../../utils/testHelpers'; |
| 10 | +import { FrameHeading } from './FrameHeading'; |
| 11 | + |
| 12 | +function getRenderedStackframeText( |
| 13 | + stackframe: Stackframe, |
| 14 | + codeLanguage: string |
| 15 | +) { |
| 16 | + const result = renderWithTheme( |
| 17 | + <FrameHeading |
| 18 | + codeLanguage={codeLanguage} |
| 19 | + isLibraryFrame={false} |
| 20 | + stackframe={stackframe} |
| 21 | + /> |
| 22 | + ); |
| 23 | + |
| 24 | + return result.getByTestId('FrameHeading').textContent; |
| 25 | +} |
| 26 | + |
| 27 | +describe('FrameHeading', () => { |
| 28 | + describe('with a Go stackframe', () => { |
| 29 | + it('renders', () => { |
| 30 | + expect( |
| 31 | + getRenderedStackframeText( |
| 32 | + { |
| 33 | + exclude_from_grouping: false, |
| 34 | + filename: 'main.go', |
| 35 | + abs_path: '/src/opbeans-go/main.go', |
| 36 | + line: { number: 196 }, |
| 37 | + function: 'Main.func2', |
| 38 | + module: 'main', |
| 39 | + }, |
| 40 | + 'go' |
| 41 | + ) |
| 42 | + ).toEqual('main.go in Main.func2 at line 196'); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + describe('with a Java stackframe', () => { |
| 47 | + it('renders', () => { |
| 48 | + expect( |
| 49 | + getRenderedStackframeText( |
| 50 | + { |
| 51 | + library_frame: true, |
| 52 | + exclude_from_grouping: false, |
| 53 | + filename: 'OutputBuffer.java', |
| 54 | + classname: 'org.apache.catalina.connector.OutputBuffer', |
| 55 | + line: { number: 825 }, |
| 56 | + module: 'org.apache.catalina.connector', |
| 57 | + function: 'flushByteBuffer', |
| 58 | + }, |
| 59 | + 'Java' |
| 60 | + ) |
| 61 | + ).toEqual( |
| 62 | + 'at org.apache.catalina.connector.OutputBuffer.flushByteBuffer(OutputBuffer.java:825)' |
| 63 | + ); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + describe('with a .NET stackframe', () => { |
| 68 | + describe('with a classname', () => { |
| 69 | + it('renders', () => { |
| 70 | + expect( |
| 71 | + getRenderedStackframeText( |
| 72 | + { |
| 73 | + classname: 'OpbeansDotnet.Controllers.CustomersController', |
| 74 | + exclude_from_grouping: false, |
| 75 | + filename: |
| 76 | + '/src/opbeans-dotnet/Controllers/CustomersController.cs', |
| 77 | + abs_path: |
| 78 | + '/src/opbeans-dotnet/Controllers/CustomersController.cs', |
| 79 | + line: { number: 23 }, |
| 80 | + module: |
| 81 | + 'opbeans-dotnet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null', |
| 82 | + function: 'Get', |
| 83 | + }, |
| 84 | + 'C#' |
| 85 | + ) |
| 86 | + ).toEqual( |
| 87 | + 'OpbeansDotnet.Controllers.CustomersController in Get in /src/opbeans-dotnet/Controllers/CustomersController.cs at line 23' |
| 88 | + ); |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + describe('with no classname', () => { |
| 93 | + it('renders', () => { |
| 94 | + expect( |
| 95 | + getRenderedStackframeText( |
| 96 | + { |
| 97 | + exclude_from_grouping: false, |
| 98 | + filename: |
| 99 | + 'Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider+ResultEnumerable`1', |
| 100 | + line: { number: 0 }, |
| 101 | + function: 'GetEnumerator', |
| 102 | + module: |
| 103 | + 'Microsoft.EntityFrameworkCore, Version=2.2.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60', |
| 104 | + }, |
| 105 | + 'C#' |
| 106 | + ) |
| 107 | + ).toEqual( |
| 108 | + 'Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider+ResultEnumerable`1 in GetEnumerator' |
| 109 | + ); |
| 110 | + }); |
| 111 | + }); |
| 112 | + }); |
| 113 | + |
| 114 | + describe('with a Node stackframe', () => { |
| 115 | + it('renders', () => { |
| 116 | + expect( |
| 117 | + getRenderedStackframeText( |
| 118 | + { |
| 119 | + library_frame: true, |
| 120 | + exclude_from_grouping: false, |
| 121 | + filename: 'internal/async_hooks.js', |
| 122 | + abs_path: 'internal/async_hooks.js', |
| 123 | + line: { number: 120 }, |
| 124 | + function: 'callbackTrampoline', |
| 125 | + }, |
| 126 | + 'javascript' |
| 127 | + ) |
| 128 | + ).toEqual('at callbackTrampoline (internal/async_hooks.js:120)'); |
| 129 | + }); |
| 130 | + |
| 131 | + describe('with a classname', () => { |
| 132 | + it('renders', () => { |
| 133 | + expect( |
| 134 | + getRenderedStackframeText( |
| 135 | + { |
| 136 | + classname: 'TCPConnectWrap', |
| 137 | + exclude_from_grouping: false, |
| 138 | + library_frame: true, |
| 139 | + filename: 'internal/stream_base_commons.js', |
| 140 | + abs_path: 'internal/stream_base_commons.js', |
| 141 | + line: { number: 205 }, |
| 142 | + function: 'onStreamRead', |
| 143 | + }, |
| 144 | + 'javascript' |
| 145 | + ) |
| 146 | + ).toEqual( |
| 147 | + 'at TCPConnectWrap.onStreamRead (internal/stream_base_commons.js:205)' |
| 148 | + ); |
| 149 | + }); |
| 150 | + }); |
| 151 | + |
| 152 | + describe('with no classname and no function', () => { |
| 153 | + it('renders', () => { |
| 154 | + expect( |
| 155 | + getRenderedStackframeText( |
| 156 | + { |
| 157 | + exclude_from_grouping: false, |
| 158 | + library_frame: true, |
| 159 | + filename: 'internal/stream_base_commons.js', |
| 160 | + abs_path: 'internal/stream_base_commons.js', |
| 161 | + line: { number: 205 }, |
| 162 | + }, |
| 163 | + 'javascript' |
| 164 | + ) |
| 165 | + ).toEqual('at (internal/stream_base_commons.js:205)'); |
| 166 | + }); |
| 167 | + }); |
| 168 | + }); |
| 169 | + |
| 170 | + describe('with a Python stackframe', () => { |
| 171 | + it('renders', () => { |
| 172 | + expect( |
| 173 | + getRenderedStackframeText( |
| 174 | + { |
| 175 | + exclude_from_grouping: false, |
| 176 | + library_frame: false, |
| 177 | + filename: 'opbeans/views.py', |
| 178 | + abs_path: '/app/opbeans/views.py', |
| 179 | + line: { |
| 180 | + number: 190, |
| 181 | + context: ' return post_order(request)', |
| 182 | + }, |
| 183 | + module: 'opbeans.views', |
| 184 | + function: 'orders', |
| 185 | + context: { |
| 186 | + pre: [ |
| 187 | + ' # set transaction name to post_order', |
| 188 | + " elasticapm.set_transaction_name('POST opbeans.views.post_order')", |
| 189 | + ], |
| 190 | + post: [ |
| 191 | + ' order_list = list(m.Order.objects.values(', |
| 192 | + " 'id', 'customer_id', 'customer__full_name', 'created_at'", |
| 193 | + ], |
| 194 | + }, |
| 195 | + vars: { request: "<WSGIRequest: POST '/api/orders'>" }, |
| 196 | + }, |
| 197 | + 'python' |
| 198 | + ) |
| 199 | + ).toEqual('opbeans/views.py in orders at line 190'); |
| 200 | + }); |
| 201 | + }); |
| 202 | + |
| 203 | + describe('with a Ruby stackframe', () => { |
| 204 | + it('renders', () => { |
| 205 | + expect( |
| 206 | + getRenderedStackframeText( |
| 207 | + { |
| 208 | + library_frame: false, |
| 209 | + exclude_from_grouping: false, |
| 210 | + abs_path: '/app/app/controllers/api/customers_controller.rb', |
| 211 | + filename: 'api/customers_controller.rb', |
| 212 | + line: { |
| 213 | + number: 15, |
| 214 | + context: ' render json: Customer.find(params[:id])\n', |
| 215 | + }, |
| 216 | + function: 'show', |
| 217 | + context: { |
| 218 | + pre: ['\n', ' def show\n'], |
| 219 | + post: [' end\n', ' end\n'], |
| 220 | + }, |
| 221 | + }, |
| 222 | + 'ruby' |
| 223 | + ) |
| 224 | + ).toEqual("api/customers_controller.rb:15 in `show'"); |
| 225 | + }); |
| 226 | + }); |
| 227 | + |
| 228 | + describe('with a RUM stackframe', () => { |
| 229 | + it('renders', () => { |
| 230 | + expect( |
| 231 | + getRenderedStackframeText( |
| 232 | + { |
| 233 | + library_frame: false, |
| 234 | + exclude_from_grouping: false, |
| 235 | + filename: 'static/js/main.616809fb.js', |
| 236 | + abs_path: 'http://opbeans-frontend:3000/static/js/main.616809fb.js', |
| 237 | + sourcemap: { |
| 238 | + error: |
| 239 | + 'No Sourcemap available for ServiceName opbeans-rum, ServiceVersion 2020-08-25 02:09:37, Path http://opbeans-frontend:3000/static/js/main.616809fb.js.', |
| 240 | + updated: false, |
| 241 | + }, |
| 242 | + line: { number: 319, column: 3842 }, |
| 243 | + function: 'unstable_runWithPriority', |
| 244 | + }, |
| 245 | + 'javascript' |
| 246 | + ) |
| 247 | + ).toEqual( |
| 248 | + 'at unstable_runWithPriority (static/js/main.616809fb.js:319:3842)' |
| 249 | + ); |
| 250 | + }); |
| 251 | + }); |
| 252 | +}); |
0 commit comments