test_example.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import os
  2. import responses
  3. from sentry.testutils import RelayStoreHelper, TransactionTestCase
  4. from sentry.testutils.helpers.datetime import before_now, iso_format
  5. from sentry.utils import json
  6. def get_fixture_path(name):
  7. return os.path.join(os.path.dirname(__file__), "example-project", name)
  8. def load_fixture(name):
  9. with open(get_fixture_path(name)) as f:
  10. return f.read()
  11. class ExampleTestCase(RelayStoreHelper, TransactionTestCase):
  12. @responses.activate
  13. def test_sourcemap_expansion(self):
  14. responses.add(
  15. responses.GET,
  16. "http://example.com/test.js",
  17. body=load_fixture("test.js"),
  18. content_type="application/javascript",
  19. )
  20. responses.add(
  21. responses.GET,
  22. "http://example.com/test.min.js",
  23. body=load_fixture("test.min.js"),
  24. content_type="application/javascript",
  25. )
  26. responses.add(
  27. responses.GET,
  28. "http://example.com/test.map",
  29. body=load_fixture("test.map"),
  30. content_type="application/json",
  31. )
  32. responses.add(responses.GET, "http://example.com/index.html", body="Not Found", status=404)
  33. min_ago = iso_format(before_now(minutes=1))
  34. data = {
  35. "timestamp": min_ago,
  36. "message": "hello",
  37. "platform": "javascript",
  38. "exception": {
  39. "values": [
  40. {
  41. "type": "Error",
  42. "stacktrace": {
  43. "frames": json.loads(load_fixture("minifiedError.json"))[::-1]
  44. },
  45. }
  46. ]
  47. },
  48. }
  49. event = self.post_and_retrieve_event(data)
  50. exception = event.interfaces["exception"]
  51. frame_list = exception.values[0].stacktrace.frames
  52. assert len(frame_list) == 4
  53. assert frame_list[0].function == "produceStack"
  54. assert frame_list[0].lineno == 6
  55. assert frame_list[0].filename == "index.html"
  56. assert frame_list[1].function == "test"
  57. assert frame_list[1].lineno == 20
  58. assert frame_list[1].filename == "test.js"
  59. assert frame_list[2].function == "invoke"
  60. assert frame_list[2].lineno == 15
  61. assert frame_list[2].filename == "test.js"
  62. assert frame_list[3].function == "onFailure"
  63. assert frame_list[3].lineno == 5
  64. assert frame_list[3].filename == "test.js"