Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/danielroe/errx. Zero dependency library to capture and parse stack traces in Node, Bun, Deno and mo
error stack-trace
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127import { fileURLToPath } from 'node:url'import { describe, expect, it } from 'vitest'import { captureStackTrace, parseRawStackTrace } from '../src'
describe('errx', () => { it('works', () => { const trace = captureStackTrace().map(t => ({ ...t, column: typeof t.column === 'number' ? '<number>' : undefined, line: typeof t.line === 'number' ? '<number>' : undefined, source: t.source.replace(/^(.*node_modules\/)+/, ''), })) expect(trace).toMatchInlineSnapshot(` [ { "column": "<number>", "function": undefined, "line": "<number>", "source": "${import.meta.url}", }, { "column": "<number>", "function": undefined, "line": "<number>", "source": "@vitest/runner/dist/chunk-artifact.js", }, { "column": "<number>", "function": undefined, "line": "<number>", "source": "@vitest/runner/dist/chunk-artifact.js", }, { "column": "<number>", "function": undefined, "line": "<number>", "source": "@vitest/runner/dist/chunk-artifact.js", }, { "column": undefined, "function": "new Promise", "line": undefined, "source": "<anonymous>", }, { "column": "<number>", "function": "runWithCancel", "line": "<number>", "source": "@vitest/runner/dist/chunk-artifact.js", }, { "column": "<number>", "function": undefined, "line": "<number>", "source": "@vitest/runner/dist/chunk-artifact.js", }, { "column": undefined, "function": "new Promise", "line": undefined, "source": "<anonymous>", }, ] `) })})
const sourcePath = fileURLToPath(new URL('../src/index.ts', import.meta.url))
const vitestTrace = `Error: at Module.getTrace (${sourcePath}:10:9) at /Users/daniel/code/danielroe/errx/test/index.test.ts:6:12 at file:///Users/daniel/code/danielroe/errx/node_modules/.pnpm/@vitest+runner@1.6.0/node_modules/@vitest/runner/dist/index.js:135:14 at file:///Users/daniel/code/danielroe/errx/node_modules/.pnpm/@vitest+runner@1.6.0/node_modules/@vitest/runner/dist/index.js:60:26 at runTest (file:///Users/daniel/code/danielroe/errx/node_modules/.pnpm/@vitest+runner@1.6.0/node_modules/@vitest/runner/dist/index.js:781:17) at runSuite (file:///Users/daniel/code/danielroe/errx/node_modules/.pnpm/@vitest+runner@1.6.0/node_modules/@vitest/runner/dist/index.js:909:15) at runSuite (file:///Users/daniel/code/danielroe/errx/node_modules/.pnpm/@vitest+runner@1.6.0/node_modules/@vitest/runner/dist/index.js:909:15) at runFiles (file:///Users/daniel/code/danielroe/errx/node_modules/.pnpm/@vitest+runner@1.6.0/node_modules/@vitest/runner/dist/index.js:958:5) at startTests (file:///Users/daniel/code/danielroe/errx/node_modules/.pnpm/@vitest+runner@1.6.0/node_modules/@vitest/runner/dist/index.js:967:3) at file:///Users/daniel/code/danielroe/errx/node_modules/.pnpm/vitest@1.6.0_@types+node@20.14.9/node_modules/vitest/dist/chunks/runtime-runBaseTests.oAvMKtQC.js:116:7`
const jitiTrace = `Error at getTrace (${sourcePath}:20:9) at ${sourcePath}:39:13 at evalModule (/Users/daniel/.npm/_npx/d5f9a72d28c5edfe/node_modules/jiti/dist/jiti.js:1:247313) at jiti (/Users/daniel/.npm/_npx/d5f9a72d28c5edfe/node_modules/jiti/dist/jiti.js:1:245241) at Object.<anonymous> (/Users/daniel/.npm/_npx/d5f9a72d28c5edfe/node_modules/jiti/bin/jiti.js:16:1) at Module._compile (node:internal/modules/cjs/loader:1376:14) at Module._extensions..js (node:internal/modules/cjs/loader:1435:10) at Module.load (node:internal/modules/cjs/loader:1207:32) at Module._load (node:internal/modules/cjs/loader:1023:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) at node:internal/main/run_main_module:28:49`
const bunTrace = `Error: at getTrace (${sourcePath}:38:8) at module code (${sourcePath}:19:14) at moduleEvaluation (native) at moduleEvaluation (native) at <anonymous> (native) at asyncFunctionResume (native) at promiseReactionJobWithoutPromiseUnwrapAsyncContext (native) at promiseReactionJob (native)`
const denoTrace = `Error at captureStackTrace (file:///some/path:19:9) at file://${sourcePath}:59:13`
describe('parseStackTrace', () => { it('parses vitest', () => { expect(parseRawStackTrace(vitestTrace)).toMatchFileSnapshot('__snapshots__/vitest.json5') }) it('parses jiti', () => { expect(parseRawStackTrace(jitiTrace)).toMatchFileSnapshot('__snapshots__/jiti.json5') }) it('parses bun', () => { expect(parseRawStackTrace(bunTrace)).toMatchFileSnapshot('__snapshots__/bun.json5') }) it('parses deno', () => { expect(parseRawStackTrace(denoTrace)).toMatchFileSnapshot('__snapshots__/deno.json5') })})