-
-
Notifications
You must be signed in to change notification settings - Fork 27k
/
Copy pathget-source-map.js
67 lines (59 loc) · 1.78 KB
/
get-source-map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment jsdom
*/
import { getSourceMap } from '../utils/getSourceMap';
import fs from 'fs';
import { resolve } from 'path';
test('finds an external source map', async () => {
const file = fs
.readFileSync(resolve(__dirname, '../../fixtures/bundle.mjs'))
.toString('utf8');
fetch.mockResponseOnce(
fs
.readFileSync(resolve(__dirname, '../../fixtures/bundle.mjs.map'))
.toString('utf8')
);
const sm = await getSourceMap('/', file);
expect(sm.getOriginalPosition(26122, 21)).toEqual({
line: 7,
column: 0,
source: 'webpack:///packages/react-scripts/template/src/App.js',
});
});
test('find an inline source map', async () => {
const sourceName = 'test.js';
const file = fs
.readFileSync(resolve(__dirname, '../../fixtures/inline.mjs'))
.toString('utf8');
const fileO = fs
.readFileSync(resolve(__dirname, '../../fixtures/inline.es6.mjs'))
.toString('utf8');
const sm = await getSourceMap('/', file);
expect(sm.getSources()).toEqual([sourceName]);
expect(sm.getSource(sourceName)).toBe(fileO);
expect(sm.getGeneratedPosition(sourceName, 5, 10)).toEqual({
line: 10,
column: 8,
});
});
test('error on a source map with unsupported encoding', async () => {
expect.assertions(2);
const file = fs
.readFileSync(resolve(__dirname, '../../fixtures/junk-inline.mjs'))
.toString('utf8');
let error;
try {
await getSourceMap('/', file);
} catch (e) {
error = e;
}
expect(error instanceof Error).toBe(true);
expect(error.message).toBe(
'Sorry, non-base64 inline source-map encoding is not supported.'
);
});