rawContent.spec.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import render, {
  2. getJavaFrame,
  3. getJavaPreamble,
  4. } from 'sentry/components/events/interfaces/crashContent/stackTrace/rawContent';
  5. describe('RawStacktraceContent', function () {
  6. describe('getJavaFrame()', function () {
  7. it('should render java frames', function () {
  8. expect(
  9. getJavaFrame({
  10. module: 'org.mortbay.thread.QueuedThreadPool$PoolThread',
  11. function: 'run',
  12. filename: 'QueuedThreadPool.java',
  13. lineNo: 582,
  14. })
  15. ).toEqual(
  16. ' at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)'
  17. );
  18. // without line number
  19. expect(
  20. getJavaFrame({
  21. module: 'org.mortbay.thread.QueuedThreadPool$PoolThread',
  22. function: 'run',
  23. filename: 'QueuedThreadPool.java',
  24. })
  25. ).toEqual(
  26. ' at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java)'
  27. );
  28. // without line number and filename
  29. expect(
  30. getJavaFrame({
  31. module: 'org.mortbay.thread.QueuedThreadPool$PoolThread',
  32. function: 'run',
  33. })
  34. ).toEqual(' at org.mortbay.thread.QueuedThreadPool$PoolThread.run');
  35. });
  36. });
  37. describe('getJavaPreamble()', function () {
  38. it('takes a type and value', () => {
  39. expect(
  40. getJavaPreamble({
  41. type: 'Baz',
  42. value: 'message',
  43. })
  44. ).toEqual('Baz: message');
  45. });
  46. it('takes a module name', () => {
  47. expect(
  48. getJavaPreamble({
  49. module: 'foo.bar',
  50. type: 'Baz',
  51. value: 'message',
  52. })
  53. ).toEqual('foo.bar.Baz: message');
  54. });
  55. });
  56. describe('render()', function () {
  57. const exception = {
  58. module: 'example.application',
  59. type: 'Error',
  60. value: 'an error occurred',
  61. },
  62. data = {
  63. frames: [
  64. {
  65. function: 'main',
  66. module: 'example.application',
  67. lineNo: 1,
  68. filename: 'application',
  69. },
  70. {
  71. function: 'doThing',
  72. module: 'example.application',
  73. lineNo: 2,
  74. filename: 'application',
  75. },
  76. ],
  77. };
  78. it('renders java example', () => {
  79. expect(render(data, 'java', exception)).toEqual(
  80. `example.application.Error: an error occurred
  81. at example.application.doThing(application:2)
  82. at example.application.main(application:1)`
  83. );
  84. });
  85. it('renders python example', () => {
  86. expect(render(data, 'python', exception)).toEqual(
  87. `Error: an error occurred
  88. File "application", line 1, in main
  89. File "application", line 2, in doThing`
  90. );
  91. });
  92. });
  93. });