forked from babel/babel
/
index.js
51 lines (49 loc) 路 1.16 KB
/
index.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
import { runCodeInTestContext } from "..";
describe("helper-transform-fixture-test-runner", function() {
it("should not execute code in Node's global context", function() {
try {
global.foo = "outer";
runCodeInTestContext(
`
expect(global.foo).toBeUndefined();
global.foo = "inner";
`,
{
filename: `${__filename}.fake1`,
},
);
expect(global.foo).toBe("outer");
runCodeInTestContext(
`
expect(global.foo).toBe("inner");
`,
{
filename: `${__filename}.fake2`,
},
);
} finally {
delete global.foo;
runCodeInTestContext(
`
delete global.foo;
`,
{
filename: `${__filename}.fake3`,
},
);
}
});
it("should print correct trace position when error is thrown in the first line", () => {
const opts = {
filename: `${__filename}.fake4`,
};
runCodeInTestContext(
`try { throw new Error() } catch (e) {
opts.stack = e.stack
}
`,
opts,
);
expect(opts.stack).toContain(opts.filename + ":1:13");
});
});