This repository has been archived on 2022-03-12. You can view files and clone it, but cannot push or open issues or pull requests.

73 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-04-02 02:24:13 +03:00
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails oncall+js_symbolication
* @format
*/
'use strict';
const Symbolication = require('../Symbolication.js');
const fs = require('fs');
const path = require('path');
const {SourceMapConsumer} = require('source-map');
const resolve = fileName => path.resolve(__dirname, '__fixtures__', fileName);
const read = fileName => fs.readFileSync(resolve(fileName), 'utf8');
const TESTFILE_MAP = resolve('testfile.js.map');
const UNKNOWN_MODULE_IDS = {
segmentId: 0,
localId: undefined,
};
test('symbolicating with context created from source map object', async () => {
const map = JSON.parse(read(TESTFILE_MAP));
const context = Symbolication.createContext(SourceMapConsumer, map);
expect(
Symbolication.getOriginalPositionFor(1, 161, UNKNOWN_MODULE_IDS, context),
).toMatchInlineSnapshot(`
Object {
"column": 20,
"line": 18,
"name": null,
"source": "thrower.js",
}
`);
});
test('symbolicating with context created from source map string', async () => {
const map = read(TESTFILE_MAP);
const context = Symbolication.createContext(SourceMapConsumer, map);
expect(
Symbolication.getOriginalPositionFor(1, 161, UNKNOWN_MODULE_IDS, context),
).toMatchInlineSnapshot(`
Object {
"column": 20,
"line": 18,
"name": null,
"source": "thrower.js",
}
`);
});
test('symbolicating without specifying module IDs', async () => {
const map = read(TESTFILE_MAP);
const context = Symbolication.createContext(SourceMapConsumer, map);
expect(Symbolication.getOriginalPositionFor(1, 161, null, context))
.toMatchInlineSnapshot(`
Object {
"column": 20,
"line": 18,
"name": null,
"source": "thrower.js",
}
`);
});