Skip to content

Commit b4d4e85

Browse files
motiz88facebook-github-bot
authored andcommitted
Refactor types + tests of parseHermesStack
Summary: Changelog: [Internal] * Migrate `parseHermesStack.js` to modern Flow syntax * Use inline snapshots in `parseHermesStack-test.js` Reviewed By: jacdebug Differential Revision: D42367093 fbshipit-source-id: 854b11283729ce9f3c2ea6e3b0c46c7f7a767a56
1 parent cb9eaa6 commit b4d4e85

3 files changed

Lines changed: 159 additions & 170 deletions

File tree

Libraries/Core/Devtools/__tests__/__snapshots__/parseHermesStack-test.js.snap

Lines changed: 0 additions & 137 deletions
This file was deleted.

Libraries/Core/Devtools/__tests__/parseHermesStack-test.js

Lines changed: 131 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,33 @@ describe('parseHermesStack', () => {
2323
' at foo$bar (address at /js/foo.hbc:10:1234)',
2424
].join('\n'),
2525
),
26-
).toMatchSnapshot();
26+
).toMatchInlineSnapshot(`
27+
Object {
28+
"entries": Array [
29+
Object {
30+
"functionName": "global",
31+
"location": Object {
32+
"line1Based": 1,
33+
"sourceUrl": "unknown",
34+
"type": "BYTECODE",
35+
"virtualOffset0Based": 9,
36+
},
37+
"type": "FRAME",
38+
},
39+
Object {
40+
"functionName": "foo$bar",
41+
"location": Object {
42+
"line1Based": 10,
43+
"sourceUrl": "/js/foo.hbc",
44+
"type": "BYTECODE",
45+
"virtualOffset0Based": 1234,
46+
},
47+
"type": "FRAME",
48+
},
49+
],
50+
"message": "TypeError: undefined is not a function",
51+
}
52+
`);
2753
});
2854

2955
test('source location', () => {
@@ -35,7 +61,33 @@ describe('parseHermesStack', () => {
3561
' at foo$bar (/js/foo.js:10:1234)',
3662
].join('\n'),
3763
),
38-
).toMatchSnapshot();
64+
).toMatchInlineSnapshot(`
65+
Object {
66+
"entries": Array [
67+
Object {
68+
"functionName": "global",
69+
"location": Object {
70+
"column1Based": 9,
71+
"line1Based": 1,
72+
"sourceUrl": "unknown",
73+
"type": "SOURCE",
74+
},
75+
"type": "FRAME",
76+
},
77+
Object {
78+
"functionName": "foo$bar",
79+
"location": Object {
80+
"column1Based": 1234,
81+
"line1Based": 10,
82+
"sourceUrl": "/js/foo.js",
83+
"type": "SOURCE",
84+
},
85+
"type": "FRAME",
86+
},
87+
],
88+
"message": "TypeError: undefined is not a function",
89+
}
90+
`);
3991
});
4092

4193
test('tolerate empty filename', () => {
@@ -47,7 +99,33 @@ describe('parseHermesStack', () => {
4799
' at foo$bar (:10:1234)',
48100
].join('\n'),
49101
),
50-
).toMatchSnapshot();
102+
).toMatchInlineSnapshot(`
103+
Object {
104+
"entries": Array [
105+
Object {
106+
"functionName": "global",
107+
"location": Object {
108+
"column1Based": 9,
109+
"line1Based": 1,
110+
"sourceUrl": "unknown",
111+
"type": "SOURCE",
112+
},
113+
"type": "FRAME",
114+
},
115+
Object {
116+
"functionName": "foo$bar",
117+
"location": Object {
118+
"column1Based": 1234,
119+
"line1Based": 10,
120+
"sourceUrl": "",
121+
"type": "SOURCE",
122+
},
123+
"type": "FRAME",
124+
},
125+
],
126+
"message": "TypeError: undefined is not a function",
127+
}
128+
`);
51129
});
52130

53131
test('skipped frames', () => {
@@ -60,7 +138,37 @@ describe('parseHermesStack', () => {
60138
' at foo$bar (/js/foo.js:10:1234)',
61139
].join('\n'),
62140
),
63-
).toMatchSnapshot();
141+
).toMatchInlineSnapshot(`
142+
Object {
143+
"entries": Array [
144+
Object {
145+
"functionName": "global",
146+
"location": Object {
147+
"column1Based": 9,
148+
"line1Based": 1,
149+
"sourceUrl": "unknown",
150+
"type": "SOURCE",
151+
},
152+
"type": "FRAME",
153+
},
154+
Object {
155+
"count": 50,
156+
"type": "SKIPPED",
157+
},
158+
Object {
159+
"functionName": "foo$bar",
160+
"location": Object {
161+
"column1Based": 1234,
162+
"line1Based": 10,
163+
"sourceUrl": "/js/foo.js",
164+
"type": "SOURCE",
165+
},
166+
"type": "FRAME",
167+
},
168+
],
169+
"message": "TypeError: undefined is not a function",
170+
}
171+
`);
64172
});
65173

66174
test('ignore frames that are part of message', () => {
@@ -73,6 +181,24 @@ describe('parseHermesStack', () => {
73181
' at foo$bar (/js/foo.js:10:1234)',
74182
].join('\n'),
75183
),
76-
).toMatchSnapshot();
184+
).toMatchInlineSnapshot(`
185+
Object {
186+
"entries": Array [
187+
Object {
188+
"functionName": "foo$bar",
189+
"location": Object {
190+
"column1Based": 1234,
191+
"line1Based": 10,
192+
"sourceUrl": "/js/foo.js",
193+
"type": "SOURCE",
194+
},
195+
"type": "FRAME",
196+
},
197+
],
198+
"message": "The next line is not a stack frame
199+
at bogus (filename:1:2)
200+
but the real stack trace follows below.",
201+
}
202+
`);
77203
});
78204
});

Libraries/Core/Devtools/parseHermesStack.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,46 @@
1010

1111
'use strict';
1212

13-
type HermesStackLocationNative = {|
14-
+type: 'NATIVE',
15-
|};
13+
type HermesStackLocationNative = $ReadOnly<{
14+
type: 'NATIVE',
15+
}>;
1616

17-
type HermesStackLocationSource = {|
18-
+type: 'SOURCE',
19-
+sourceUrl: string,
20-
+line1Based: number,
21-
+column1Based: number,
22-
|};
17+
type HermesStackLocationSource = $ReadOnly<{
18+
type: 'SOURCE',
19+
sourceUrl: string,
20+
line1Based: number,
21+
column1Based: number,
22+
}>;
2323

24-
type HermesStackLocationBytecode = {|
25-
+type: 'BYTECODE',
26-
+sourceUrl: string,
27-
+line1Based: number,
28-
+virtualOffset0Based: number,
29-
|};
24+
type HermesStackLocationBytecode = $ReadOnly<{
25+
type: 'BYTECODE',
26+
sourceUrl: string,
27+
line1Based: number,
28+
virtualOffset0Based: number,
29+
}>;
3030

3131
type HermesStackLocation =
3232
| HermesStackLocationNative
3333
| HermesStackLocationSource
3434
| HermesStackLocationBytecode;
3535

36-
type HermesStackEntryFrame = {|
37-
+type: 'FRAME',
38-
+location: HermesStackLocation,
39-
+functionName: string,
40-
|};
36+
type HermesStackEntryFrame = $ReadOnly<{
37+
type: 'FRAME',
38+
location: HermesStackLocation,
39+
functionName: string,
40+
}>;
4141

42-
type HermesStackEntrySkipped = {|
43-
+type: 'SKIPPED',
44-
+count: number,
45-
|};
42+
type HermesStackEntrySkipped = $ReadOnly<{
43+
type: 'SKIPPED',
44+
count: number,
45+
}>;
4646

4747
type HermesStackEntry = HermesStackEntryFrame | HermesStackEntrySkipped;
4848

49-
export type HermesParsedStack = {|
50-
+message: string,
51-
+entries: $ReadOnlyArray<HermesStackEntry>,
52-
|};
49+
export type HermesParsedStack = $ReadOnly<{
50+
message: string,
51+
entries: $ReadOnlyArray<HermesStackEntry>,
52+
}>;
5353

5454
// Capturing groups:
5555
// 1. function name

0 commit comments

Comments
 (0)