mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
53 lines
949 B
TypeScript
53 lines
949 B
TypeScript
import { expect, test } from "bun:test";
|
|
import { runInNewContext } from "node:vm";
|
|
|
|
test("can get sourceURL from eval inside node:vm", () => {
|
|
try {
|
|
runInNewContext(
|
|
`
|
|
throw new Error("hello");
|
|
//# sourceURL=hellohello.js
|
|
`,
|
|
{},
|
|
);
|
|
} catch (e: any) {
|
|
var err: Error = e;
|
|
}
|
|
|
|
expect(err!.stack!.replaceAll(import.meta.path, "<this-url>")).toMatchSnapshot();
|
|
});
|
|
|
|
test("can get sourceURL inside node:vm", () => {
|
|
const err = runInNewContext(
|
|
`
|
|
|
|
function hello() {
|
|
return Bun.inspect(new Error("hello"));
|
|
}
|
|
|
|
hello();
|
|
|
|
//# sourceURL=hellohello.js
|
|
`,
|
|
{ Bun },
|
|
);
|
|
|
|
expect(err.replaceAll(import.meta.path, "<this-url>")).toMatchSnapshot();
|
|
});
|
|
|
|
test("eval sourceURL is correct", () => {
|
|
const err = eval(
|
|
`
|
|
|
|
function hello() {
|
|
return Bun.inspect(new Error("hello"));
|
|
}
|
|
|
|
hello();
|
|
|
|
//# sourceURL=hellohello.js
|
|
`,
|
|
);
|
|
expect(err.replaceAll(import.meta.path, "<this-url>")).toMatchSnapshot();
|
|
});
|