stack-trace
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Stack-Trace is a powerful npm package that allows you to access V8 stack traces as an array of CallSite objects. This feature gives developers insights into the function calls that have been made within the V8 JavaScript engine at the time the stack was created, making it an invaluable tool for debugging and understanding your code's behavior.
The usage of Stack-Trace is straightforward and intuitive. First, you'd want to install it using npm by running npm install stack-trace
in your terminal.
Below is an example of how to capture the current stack:
import { get } from 'stack-trace';
const trace = get();
expect(trace[0].getFileName()).toBe(__filename);
Stack-Trace is also equipped to parse an Error object in instances where the stack you're interested in has already been popped. A simple representation is as follows:
import { parse } from 'stack-trace';
const err = new Error('something went wrong');
const trace = parse(err);
expect(trace[0].getFileName()).toBe(__filename);
Remember, parsing the Error#stack
property may not retrieve all properties. For more details on returned properties, you'd want to refer to the API docs.
For comprehensive information on Stack-Trace and its API, including stackTrace.get([belowFn])
, stackTrace.parse(err)
, and details about the CallSite object, refer to the official V8 CallSite object API documentation here. Knowing how to configure and use Stack-Trace will aid greatly in your JavaScript debugging and development process.