frame.spec.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {Frame} from 'sentry/utils/profiling/frame';
  2. describe('Frame', () => {
  3. describe.each([['javascript'], ['node']])(
  4. 'renames unknown frame to <anonymous> for platform %s',
  5. platform => {
  6. it('sets anonymouse name if frame has no name', () => {
  7. expect(new Frame({key: 0, name: '', line: 0, column: 0}, platform).name).toBe(
  8. '<anonymous>'
  9. );
  10. });
  11. it('appends [native code] to name if frame belongs to native code', () => {
  12. expect(
  13. new Frame(
  14. {key: 0, name: 'foo', line: undefined, column: undefined},
  15. platform
  16. ).name.endsWith('[native code]')
  17. ).toBe(true);
  18. });
  19. }
  20. );
  21. it('marks frame as extension', () => {
  22. for (const prefix of ['@moz-extension://', 'chrome-extension://']) {
  23. expect(
  24. new Frame(
  25. {
  26. key: 0,
  27. name: 'foo',
  28. line: undefined,
  29. column: undefined,
  30. file: `${prefix}foo/bar.js`,
  31. },
  32. 'javascript'
  33. ).is_browser_extension
  34. ).toBe(true);
  35. }
  36. expect(
  37. new Frame(
  38. {
  39. key: 0,
  40. name: 'foo',
  41. line: undefined,
  42. column: undefined,
  43. file: `bar.js`,
  44. },
  45. 'javascript'
  46. ).is_browser_extension
  47. ).toBe(false);
  48. });
  49. describe('pulls package from path for web|node platforms', () => {
  50. it('file in node modules', () => {
  51. expect(
  52. new Frame(
  53. {
  54. key: 0,
  55. name: 'Foo',
  56. path: '/usr/code/node_modules/file.js',
  57. line: undefined,
  58. column: undefined,
  59. },
  60. 'node'
  61. ).module
  62. ).toBe(undefined);
  63. });
  64. it.each([
  65. ['node:internal/crypto/hash', 'node:internal/crypto'],
  66. ['node:vm', 'node:vm'],
  67. ['/usr/code/node_modules/@sentry/profiling-node/file.js', '@sentry/profiling-node'],
  68. ['/usr/code/node_modules/sentry/profiling-node/file.js', 'sentry'],
  69. ['/usr/code/node_modules/sentry/file.js', 'sentry'],
  70. [
  71. 'C:\\Program Files (x86)\\node_modules\\@sentry\\profiling-node\\file.js',
  72. '@sentry/profiling-node',
  73. ],
  74. [
  75. 'C:\\Program Files (x86)\\node_modules\\sentry\\profiling-node\\file.js',
  76. 'sentry',
  77. ],
  78. ['C:\\Program Files (x86)\\node_modules\\sentry\\file.js', 'sentry'],
  79. ])('%s -> %s', (path, expected) => {
  80. expect(
  81. new Frame(
  82. {
  83. key: 0,
  84. name: 'Foo',
  85. path,
  86. line: undefined,
  87. column: undefined,
  88. },
  89. 'node'
  90. ).module
  91. ).toBe(expected);
  92. });
  93. });
  94. });