line.spec.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, within} from 'sentry-test/reactTestingLibrary';
  3. import Line from 'sentry/components/events/interfaces/frame/line';
  4. import {Frame} from 'sentry/types';
  5. import {OrganizationContext} from 'sentry/views/organizationContext';
  6. import {RouteContext} from 'sentry/views/routeContext';
  7. function TestComponent({children}: {children: React.ReactNode}) {
  8. const {organization, router} = initializeOrg();
  9. return (
  10. <OrganizationContext.Provider value={organization}>
  11. <RouteContext.Provider
  12. value={{
  13. router,
  14. location: router.location,
  15. params: {},
  16. routes: [],
  17. }}
  18. >
  19. {children}
  20. </RouteContext.Provider>
  21. </OrganizationContext.Provider>
  22. );
  23. }
  24. describe('Frame - Line', function () {
  25. const event = TestStubs.Event();
  26. const data: Frame = {
  27. absPath: null,
  28. colNo: null,
  29. context: [],
  30. errors: null,
  31. filename: null,
  32. function: null,
  33. inApp: false,
  34. instructionAddr: null,
  35. lineNo: null,
  36. module: null,
  37. package: null,
  38. platform: null,
  39. rawFunction: null,
  40. symbol: null,
  41. symbolAddr: null,
  42. trust: null,
  43. vars: null,
  44. };
  45. describe('renderOriginalSourceInfo()', function () {
  46. it('should render the source map information as a HTML string', function () {
  47. const {container} = render(
  48. <TestComponent>
  49. <Line
  50. data={{
  51. origAbsPath: 'https://beta.getsentry.com/_static/sentry/dist/vendor.js',
  52. mapUrl: 'https://beta.getsentry.com/_static/sentry/dist/vendor.js.map',
  53. map: 'vendor.js.map',
  54. ...data,
  55. }}
  56. registers={{}}
  57. components={[]}
  58. event={event}
  59. />
  60. </TestComponent>
  61. );
  62. expect(container).toSnapshot();
  63. });
  64. });
  65. describe('renderContext()', () => {
  66. it('should render context lines', () => {
  67. render(
  68. <TestComponent>
  69. <Line
  70. data={{
  71. ...data,
  72. context: [
  73. [
  74. 211,
  75. ' # Mark the crashed thread and add its stacktrace to the exception',
  76. ],
  77. [212, " crashed_thread = data['threads'][state.requesting_thread]"],
  78. [213, " crashed_thread['crashed'] = True"],
  79. ],
  80. }}
  81. registers={{}}
  82. components={[]}
  83. event={event}
  84. isExpanded
  85. />
  86. </TestComponent>
  87. );
  88. expect(screen.getByRole('list')).toSnapshot();
  89. });
  90. it('should render register values', () => {
  91. render(
  92. <TestComponent>
  93. <Line
  94. data={data}
  95. registers={{
  96. r10: '0x00007fff9300bf70',
  97. r11: '0xffffffffffffffff',
  98. r12: '0x0000000000000000',
  99. r13: '0x0000000000000000',
  100. r14: '0x000000000000000a',
  101. r15: '0x0000000000000000',
  102. r8: '0x00007fff9300bf78',
  103. r9: '0x0000000000000040',
  104. rax: '0x00007fff9291e660',
  105. rbp: '0x00007ffedfdff7e0',
  106. rbx: '0x00007fff9291e660',
  107. rcx: '0x0000000000000008',
  108. rdi: '0x00007ffedfdff790',
  109. rdx: '0x0000020000000303',
  110. rip: '0x000000010fe00a59',
  111. rsi: '0x0000000000000300',
  112. rsp: '0x00007ffedfdff7c0',
  113. }}
  114. components={[]}
  115. event={event}
  116. isExpanded
  117. />
  118. </TestComponent>
  119. );
  120. expect(screen.getByText('Registers')).toBeInTheDocument();
  121. });
  122. it('should not render empty registers', () => {
  123. render(
  124. <TestComponent>
  125. <Line data={data} registers={{}} components={[]} event={event} isExpanded />
  126. </TestComponent>
  127. );
  128. expect(screen.queryByText('Registers')).not.toBeInTheDocument();
  129. });
  130. it('should render context vars', () => {
  131. const vars = {
  132. origin: null,
  133. helper: '<sentry.coreapi.MinidumpApiHelper object at 0x10e157ed0>',
  134. self: '<sentry.web.api.MinidumpView object at 0x10e157250>',
  135. args: [],
  136. request: '<WSGIRequest at 0x4531253712>',
  137. content: '[Filtered]',
  138. kwargs: {},
  139. project_id: "u'3'",
  140. };
  141. render(
  142. <TestComponent>
  143. <Line
  144. data={{...data, vars}}
  145. registers={{}}
  146. components={[]}
  147. event={event}
  148. isExpanded
  149. />
  150. </TestComponent>
  151. );
  152. for (const [key, value] of Object.entries(vars)) {
  153. const row = screen.getByText(key).closest('tr');
  154. expect(row).toBeTruthy();
  155. if (!row) {
  156. return;
  157. }
  158. const utils = within(row);
  159. expect(utils.getByText(key)).toBeInTheDocument();
  160. if (typeof value !== 'string') {
  161. return;
  162. }
  163. expect(utils.getByText(value)).toBeInTheDocument();
  164. }
  165. });
  166. });
  167. });