forked from facebook/create-react-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unmapper.js
72 lines (65 loc) · 2.21 KB
/
unmapper.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
68
69
70
71
72
/**
* 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.
*/
import { unmap } from '../utils/unmapper';
import { parse } from '../utils/parser';
import fs from 'fs';
import { resolve } from 'path';
test('basic warning', async () => {
expect.assertions(2);
const error = `Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of \`B\`. See https://fb.me/react-warning-keys for more information.
in div (at B.js:8)
in B (at A.js:6)
in A (at App.js:8)
in div (at App.js:10)
in App (at index.js:6)`;
fetch.mockResponseOnce(
fs
.readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs'))
.toString('utf8')
);
fetch.mockResponseOnce(
fs
.readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs.map'))
.toString('utf8')
);
const frames = await unmap('/static/js/bundle.js', parse(error), 0);
const expected = JSON.parse(
fs
.readFileSync(resolve(__dirname, '../../fixtures/bundle2.json'))
.toString('utf8')
);
expect(frames).toEqual(expected);
fetch.mockResponseOnce(
fs
.readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs'))
.toString('utf8')
);
fetch.mockResponseOnce(
fs
.readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs.map'))
.toString('utf8')
);
expect(await unmap('/static/js/bundle.js', expected)).toEqual(expected);
});
test('default context & unfound source', async () => {
expect.assertions(1);
const error = `Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of \`B\`. See https://fb.me/react-warning-keys for more information.
in div (at B.js:8)
in unknown (at blabla.js:10)`;
fetch.mockResponseOnce(
fs
.readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs'))
.toString('utf8')
);
fetch.mockResponseOnce(
fs
.readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs.map'))
.toString('utf8')
);
const frames = await unmap('/static/js/bundle.js', parse(error));
expect(frames).toMatchSnapshot();
});