1
0
Fork 0
forked from svrjs/svrjs
This repository has been archived on 2024-11-10. You can view files and clone it, but cannot push or open issues or pull requests.
svrjs/tests/utils/generateErrorStack.test.js

45 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2024-09-14 16:23:49 +02:00
const generateErrorStack = require("../../src/utils/generateErrorStack.js");
describe("Error stack generation function", () => {
test("should return the original stack if it is V8-style", () => {
const error = new Error("Test error");
error.stack = `Error: Test error
at Object.<anonymous> (/path/to/file.js:10:15)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)`;
const result = generateErrorStack(error);
expect(result).toBe(error.stack);
});
test("should generate a new stack if the original stack is SpiderMonkey-style", () => {
const error = new Error("Test error");
error.stack = `baz@filename.js:10:15
bar@filename.js:6:3
foo@filename.js:2:3
@filename.js:13:1`;
const result = generateErrorStack(error);
expect(result).toContain("Error: Test error");
expect(result).toContain(" at baz (filename.js:10:15)");
expect(result).toContain(" at bar (filename.js:6:3)");
expect(result).toContain(" at foo (filename.js:2:3)");
expect(result).toContain(" at filename.js:13:1");
});
test("should generate a new stack if the original stack is JavaScriptCore-style", () => {
const error = new Error("Test error");
error.stack = `baz@filename.js:10:15
bar@filename.js:6:3
foo@filename.js:2:3
global code@filename.js:13:1`;
const result = generateErrorStack(error);
expect(result).toContain("Error: Test error");
expect(result).toContain(" at baz (filename.js:10:15)");
expect(result).toContain(" at bar (filename.js:6:3)");
expect(result).toContain(" at foo (filename.js:2:3)");
expect(result).toContain(" at filename.js:13:1");
});
});