tapjs/tsimp

Source map paths are wrong

andrew0 opened this issue · 3 comments

I tried using this library but ran into some issues because the stack traces seem to be wrong. I put up a small repro here but it's really basic, just runs a script that prints a stack trace:

console.error(new Error('kaboom').stack);

When I run this with node --import=tsimp/import src/main.ts, I get this:

Error: kaboom
    at <anonymous> (/private/tmp/src/main.ts:1:15)
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
    at async loadESM (node:internal/process/esm_loader:42:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

When I build the TypeScript code with tsc and run it with node --enable-source-maps dist/main.js, I get this:

Error: kaboom
    at <anonymous> (/private/tmp/tsimp-repro/src/main.ts:1:15)
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
    at async loadESM (node:internal/process/esm_loader:42:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

With tsimp, the current directory seems to be removed from the file where the error is thrown (/private/tmp/src/main.ts when it should be /private/tmp/tsimp-repro/src/main.ts).

This commit fixes the problem for me: andrew0@9164973. I would submit a PR but I'm not sure what to do with the snapshot tests, since it makes it so the source maps have an absolute path for the sourceRoot.

Good find. I can fix up the snapshots easily enough to keep absolute paths out. (Tap will automatically prevent cwd in snapshots by default, but other paths can be a problem.)

Found this issue looking for at source map support for Node.js Test Runner.

Warning: Could not report code coverage. TypeError: Cannot read properties of undefined

This is a known limitation of the Node.js test runner. It causes the code coverage reporting to break.