forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathastBreakpointLocation.spec.js
More file actions
64 lines (59 loc) · 1.78 KB
/
Copy pathastBreakpointLocation.spec.js
File metadata and controls
64 lines (59 loc) · 1.78 KB
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
import { getASTLocation } from "../astBreakpointLocation.js";
import {
getSource,
getOriginalSource
} from "../../../workers/parser/tests/helpers";
import { setSource } from "../../../workers/parser/sources";
import { getSymbols } from "../../../workers/parser/getSymbols";
import cases from "jest-in-case";
async function setup({ file, location, functionName, original }) {
const source = original ? getOriginalSource(file) : getSource(file);
setSource(source);
const symbols = getSymbols(source.id);
const astLocation = getASTLocation(source, symbols, location);
expect(astLocation.name).toBe(functionName);
expect(astLocation).toMatchSnapshot();
}
describe("ast", () => {
cases("valid location", setup, [
{
name: "returns the scope and offset",
file: "math",
location: { line: 6, column: 0 },
functionName: "math"
},
{
name: "returns name for a nested anon fn as the parent func",
file: "outOfScope",
location: { line: 25, column: 0 },
functionName: "outer"
},
{
name: "returns name for a nested named fn",
file: "outOfScope",
location: { line: 5, column: 0 },
functionName: "inner"
},
{
name: "returns name for an anon fn with a named variable",
file: "outOfScope",
location: { line: 40, column: 0 },
functionName: "globalDeclaration"
}
]);
cases("invalid location", setup, [
{
name: "returns the scope name for global scope as undefined",
file: "class",
original: true,
location: { line: 10, column: 0 },
functionName: undefined
},
{
name: "returns name for an anon fn in global scope as undefined",
file: "outOfScope",
location: { line: 44, column: 0 },
functionName: undefined
}
]);
});