Symbolication-test.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 Symbolication = require('../Symbolication.js');
  12. const fs = require('fs');
  13. const path = require('path');
  14. const {SourceMapConsumer} = require('source-map');
  15. const resolve = fileName => path.resolve(__dirname, '__fixtures__', fileName);
  16. const read = fileName => fs.readFileSync(resolve(fileName), 'utf8');
  17. const TESTFILE_MAP = resolve('testfile.js.map');
  18. const UNKNOWN_MODULE_IDS = {
  19. segmentId: 0,
  20. localId: undefined,
  21. };
  22. test('symbolicating with context created from source map object', async () => {
  23. const map = JSON.parse(read(TESTFILE_MAP));
  24. const context = Symbolication.createContext(SourceMapConsumer, map);
  25. expect(
  26. Symbolication.getOriginalPositionFor(1, 161, UNKNOWN_MODULE_IDS, context),
  27. ).toMatchInlineSnapshot(`
  28. Object {
  29. "column": 20,
  30. "line": 18,
  31. "name": null,
  32. "source": "thrower.js",
  33. }
  34. `);
  35. });
  36. test('symbolicating with context created from source map string', async () => {
  37. const map = read(TESTFILE_MAP);
  38. const context = Symbolication.createContext(SourceMapConsumer, map);
  39. expect(
  40. Symbolication.getOriginalPositionFor(1, 161, UNKNOWN_MODULE_IDS, context),
  41. ).toMatchInlineSnapshot(`
  42. Object {
  43. "column": 20,
  44. "line": 18,
  45. "name": null,
  46. "source": "thrower.js",
  47. }
  48. `);
  49. });
  50. test('symbolicating without specifying module IDs', async () => {
  51. const map = read(TESTFILE_MAP);
  52. const context = Symbolication.createContext(SourceMapConsumer, map);
  53. expect(Symbolication.getOriginalPositionFor(1, 161, null, context))
  54. .toMatchInlineSnapshot(`
  55. Object {
  56. "column": 20,
  57. "line": 18,
  58. "name": null,
  59. "source": "thrower.js",
  60. }
  61. `);
  62. });