SourceMetadataMapConsumer-test.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @emails oncall+js_symbolication
  8. * @format
  9. */
  10. 'use strict';
  11. const SourceMetadataMapConsumer = require('../SourceMetadataMapConsumer.js');
  12. describe('SourceMetadataMapConsumer', () => {
  13. it('ignores metadata beyond the range of the sources array', () => {
  14. const consumer = new SourceMetadataMapConsumer({
  15. version: 3,
  16. mappings: '',
  17. sources: ['foo'],
  18. names: [],
  19. x_facebook_sources: [
  20. null,
  21. [
  22. {
  23. mappings: '',
  24. names: [],
  25. },
  26. ],
  27. ],
  28. });
  29. expect(consumer.toArray(['foo'])).toEqual([null]);
  30. });
  31. it('ignores metadata for a null source', () => {
  32. const consumer = new SourceMetadataMapConsumer({
  33. version: 3,
  34. mappings: '',
  35. sources: ['foo', null],
  36. names: [],
  37. x_facebook_sources: [
  38. [
  39. {
  40. mappings: '',
  41. names: [],
  42. },
  43. ],
  44. ],
  45. });
  46. expect(consumer.toArray(['foo', null])).toEqual([
  47. [
  48. {
  49. mappings: '',
  50. names: [],
  51. },
  52. ],
  53. null,
  54. ]);
  55. });
  56. it('accepts metadata blob with null function map', () => {
  57. const consumer = new SourceMetadataMapConsumer({
  58. version: 3,
  59. mappings: 'AAAA',
  60. sources: ['foo'],
  61. names: [],
  62. x_facebook_sources: [[null]],
  63. });
  64. expect(consumer.functionNameFor({line: 1, column: 0, source: 'foo'})).toBe(
  65. null,
  66. );
  67. });
  68. it('accepts null metadata blob', () => {
  69. const consumer = new SourceMetadataMapConsumer({
  70. version: 3,
  71. mappings: 'AAAA',
  72. sources: ['foo'],
  73. names: [],
  74. x_facebook_sources: [null],
  75. });
  76. expect(consumer.functionNameFor({line: 1, column: 0, source: 'foo'})).toBe(
  77. null,
  78. );
  79. });
  80. });