function resolveStack
resolveStack(
stack: string,
projectRoot: string
): { resolvedStack: string; firstUserFrame: string | null; firstUserSourceText: string | null; }

Resolves every frame in stack that references a test bundle to its original source.

  • resolvedStack: the same stack with bundle frames rewritten to original paths.
  • firstUserFrame: the first frame that resolves outside node_modules/ (the actual assertion call-site), as "path:line:col" suitable for the TAP at: field.
  • firstUserSourceText: the trimmed source line at the first user frame (from sourcesContent), or null when the map has no embedded source text.

Frames from native code, external scripts, or unknown formats are left unchanged.

import * as SourceMap from './source-map.ts';

const decoder = SourceMap.parse('{"sources":["../test/login-test.ts"],"mappings":"AAAA"}', '/proj/tmp');

SourceMap.resolveStack('Error: rejected\n    at http://localhost:7357/tests.js:1:1', decoder, '/proj');
// { resolvedStack: 'Error: rejected\n    at test/login-test.ts:1:1',
//   firstUserFrame: 'test/login-test.ts:1:1', firstUserSourceText: null }

Parameters

stack: string
projectRoot: string

Return Type

{ resolvedStack: string; firstUserFrame: string | null; firstUserSourceText: string | null; }

Usage

import { resolveStack } from "lib/utils/source-map.ts";