2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2019-07-29 05:11:08 -04:00
|
|
|
import { test, assert } from "./test_util.ts";
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
const { setPrepareStackTrace } = Deno as any;
|
|
|
|
|
|
|
|
interface CallSite {
|
|
|
|
getThis(): unknown;
|
|
|
|
getTypeName(): string;
|
|
|
|
getFunction(): Function;
|
|
|
|
getFunctionName(): string;
|
|
|
|
getMethodName(): string;
|
|
|
|
getFileName(): string;
|
|
|
|
getLineNumber(): number | null;
|
|
|
|
getColumnNumber(): number | null;
|
|
|
|
getEvalOrigin(): string | null;
|
|
|
|
isToplevel(): boolean;
|
|
|
|
isEval(): boolean;
|
|
|
|
isNative(): boolean;
|
|
|
|
isConstructor(): boolean;
|
|
|
|
isAsync(): boolean;
|
|
|
|
isPromiseAll(): boolean;
|
|
|
|
getPromiseIndex(): number | null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getMockCallSite(
|
|
|
|
filename: string,
|
|
|
|
line: number | null,
|
|
|
|
column: number | null
|
|
|
|
): CallSite {
|
|
|
|
return {
|
|
|
|
getThis(): unknown {
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
getTypeName(): string {
|
|
|
|
return "";
|
|
|
|
},
|
|
|
|
getFunction(): Function {
|
|
|
|
return (): void => {};
|
|
|
|
},
|
|
|
|
getFunctionName(): string {
|
|
|
|
return "";
|
|
|
|
},
|
|
|
|
getMethodName(): string {
|
|
|
|
return "";
|
|
|
|
},
|
|
|
|
getFileName(): string {
|
|
|
|
return filename;
|
|
|
|
},
|
|
|
|
getLineNumber(): number | null {
|
|
|
|
return line;
|
|
|
|
},
|
|
|
|
getColumnNumber(): number | null {
|
|
|
|
return column;
|
|
|
|
},
|
|
|
|
getEvalOrigin(): null {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
isToplevel(): false {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isEval(): false {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isNative(): false {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isConstructor(): false {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isAsync(): false {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isPromiseAll(): false {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
getPromiseIndex(): null {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
test(function prepareStackTrace(): void {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
const MockError = {} as any;
|
|
|
|
setPrepareStackTrace(MockError);
|
|
|
|
assert(typeof MockError.prepareStackTrace === "function");
|
|
|
|
const prepareStackTrace: (
|
|
|
|
error: Error,
|
|
|
|
structuredStackTrace: CallSite[]
|
|
|
|
) => string = MockError.prepareStackTrace;
|
|
|
|
const result = prepareStackTrace(new Error("foo"), [
|
2019-09-02 17:07:11 -04:00
|
|
|
getMockCallSite("CLI_SNAPSHOT.js", 23, 0)
|
2019-07-29 05:11:08 -04:00
|
|
|
]);
|
|
|
|
assert(result.startsWith("Error: foo\n"));
|
2019-09-02 17:07:11 -04:00
|
|
|
assert(result.includes(".ts:"), "should remap to something in 'js/'");
|
2019-07-29 05:11:08 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test(function applySourceMap(): void {
|
|
|
|
const result = Deno.applySourceMap({
|
2019-09-02 17:07:11 -04:00
|
|
|
filename: "CLI_SNAPSHOT.js",
|
2019-07-29 05:11:08 -04:00
|
|
|
line: 23,
|
|
|
|
column: 0
|
|
|
|
});
|
2019-09-02 17:07:11 -04:00
|
|
|
assert(result.filename.endsWith(".ts"));
|
2019-07-29 05:11:08 -04:00
|
|
|
assert(result.line != null);
|
|
|
|
assert(result.column != null);
|
|
|
|
});
|