stackTrace.spec.jsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import cloneDeep from 'lodash/cloneDeep';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import ExceptionStacktraceContent from 'sentry/components/events/interfaces/crashContent/exception/stackTrace';
  4. import {OrganizationContext} from 'sentry/views/organizationContext';
  5. import EmptyMessage from 'sentry/views/settings/components/emptyMessage';
  6. describe('ExceptionStacktraceContent', () => {
  7. const organization = TestStubs.Organization();
  8. const stacktrace = {
  9. frames: [
  10. {
  11. function: null,
  12. colNo: null,
  13. vars: {},
  14. symbol: null,
  15. module: '<unknown module>',
  16. lineNo: null,
  17. errors: null,
  18. package: null,
  19. absPath:
  20. 'https://sentry.io/hiventy/kraken-prod/issues/438681831/?referrer=slack#',
  21. inApp: false,
  22. instructionAddr: null,
  23. filename: '/hiventy/kraken-prod/issues/438681831/',
  24. platform: null,
  25. context: [],
  26. symbolAddr: null,
  27. },
  28. {
  29. absPath: 'foo/baz.c',
  30. colNo: null,
  31. context: [],
  32. errors: null,
  33. filename: 'foo/baz.c',
  34. function: null,
  35. inApp: false,
  36. instructionAddr: null,
  37. lineNo: 1,
  38. module: null,
  39. package: null,
  40. platform: null,
  41. rawFunction: null,
  42. symbol: null,
  43. symbolAddr: null,
  44. trust: null,
  45. vars: null,
  46. },
  47. ],
  48. };
  49. const props = {
  50. stackView: 'app',
  51. platform: 'node',
  52. expandFirstFrame: true,
  53. newestFirst: true,
  54. chainedException: false,
  55. event: {
  56. entries: [],
  57. crashFile: {
  58. sha1: 'sha1',
  59. name: 'name.dmp',
  60. dateCreated: '2019-05-21T18:01:48.762Z',
  61. headers: {'Content-Type': 'application/octet-stream'},
  62. id: '12345',
  63. size: 123456,
  64. type: 'event.minidump',
  65. },
  66. culprit: '',
  67. dateCreated: '2019-05-21T18:00:23Z',
  68. 'event.type': 'error',
  69. eventID: '123456',
  70. groupID: '1',
  71. id: '98654',
  72. location: 'main.js',
  73. message: 'TestException',
  74. platform: 'native',
  75. projectID: '123',
  76. tags: [{value: 'production', key: 'production'}],
  77. title: 'TestException',
  78. },
  79. data: stacktrace,
  80. stacktrace,
  81. framesOmitted: null,
  82. registers: null,
  83. hasSystemFrames: false,
  84. };
  85. it('default behaviour', () => {
  86. const wrapper = mountWithTheme(
  87. <OrganizationContext.Provider value={organization}>
  88. <ExceptionStacktraceContent {...props} />
  89. </OrganizationContext.Provider>
  90. );
  91. expect(wrapper).toSnapshot();
  92. });
  93. it('should return an emptyRender', () => {
  94. const wrapper = mountWithTheme(
  95. <OrganizationContext.Provider value={organization}>
  96. <ExceptionStacktraceContent {...props} stacktrace={undefined} />
  97. </OrganizationContext.Provider>
  98. );
  99. expect(wrapper.isEmptyRender()).toBe(true);
  100. });
  101. it('should return the EmptyMessage component', () => {
  102. const wrapper = mountWithTheme(
  103. <OrganizationContext.Provider value={organization}>
  104. <ExceptionStacktraceContent {...props} />
  105. </OrganizationContext.Provider>
  106. );
  107. const emptyMessageElement = wrapper.find(EmptyMessage).exists();
  108. expect(emptyMessageElement).toBe(true);
  109. });
  110. it('should not return the EmptyMessage component', () => {
  111. const modifiedProps = cloneDeep(props);
  112. modifiedProps.stacktrace.frames[0].inApp = true;
  113. const wrapper = mountWithTheme(
  114. <OrganizationContext.Provider value={organization}>
  115. <ExceptionStacktraceContent {...modifiedProps} />
  116. </OrganizationContext.Provider>
  117. );
  118. const emptyMessageElement = wrapper.find(EmptyMessage).exists();
  119. expect(emptyMessageElement).toBe(false);
  120. });
  121. it('should render system frames if "stackView: app" and there are no inApp frames and is a chained exceptions', () => {
  122. const wrapper = mountWithTheme(
  123. <OrganizationContext.Provider value={organization}>
  124. <ExceptionStacktraceContent {...props} chainedException />
  125. </OrganizationContext.Provider>
  126. );
  127. expect(wrapper.find('Line').length).toBe(2);
  128. });
  129. it('should not render system frames if "stackView: app" and there are inApp frames and is a chained exceptions', () => {
  130. const modifiedProps = cloneDeep(props);
  131. modifiedProps.stacktrace.frames[0].inApp = true;
  132. const wrapper = mountWithTheme(
  133. <OrganizationContext.Provider value={organization}>
  134. <ExceptionStacktraceContent {...modifiedProps} chainedException />
  135. </OrganizationContext.Provider>
  136. );
  137. // There must be two elements, one being the inApp frame and the other
  138. // the last frame which is non-app frame
  139. expect(wrapper.find('Line').length).toBe(2);
  140. // inApp === true
  141. expect(wrapper.find('.filename').at(1).text()).toBe(
  142. props.stacktrace.frames[0].filename
  143. );
  144. // inApp === false
  145. expect(wrapper.find('.filename').at(0).text()).toBe(
  146. props.stacktrace.frames[1].filename
  147. );
  148. });
  149. });