Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When running jest test, breakpoint set on ts file doesn't get hit, #1125

Closed
heejaechang opened this issue Oct 15, 2021 · 1 comment
Closed
Assignees
Labels
*as-designed Described behavior is as designed

Comments

@heejaechang
Copy link

heejaechang commented Oct 15, 2021

Describe the bug
When running jest test, breakpoint set on ts file doesn't get hit,

what I observe is debugger sometimes bring up another ts file (which looks like a generated file with the same file name) which seems to be a javascript file. since it is different file with the same name, line and columns are out of sync so, breakpoint either not work or broke into wrong place. it feels like some issue with sourcemap.

another weird thing to mention is vscode shows 2 editors with the same name as shown below. and debugger show one as short name and the other in full name. and one of them looks like javascript file (readonly) and the other original ts file. yet has same "ts" name.

image

image

To Reproduce
Steps to reproduce the behavior:

  1. clone https://github.com/microsoft/pyrx.git (it is private repo, ping me for access)
  2. open testState.ts file
  3. set breakpoint on verifyWorkspaceEdit method on testState class
  4. open renameFile.stubFile.fourslash.ts file
  5. open "run and debug" tab
  6. select "pylance fourslash current file"
  7. run

expected behavior:
breakpoint hit

actual behavior:
no breakpoint gets hit.

Log File

vscode-debugadapter-64bf200a.json.gz

VS Code Version: v1.61.0
** JavaScript debugger (nightly) ** v2021.10.1317

Additional context
it repro with built-in version as well.

@heejaechang heejaechang added the bug Issue identified by VS Code Team member as probable bug label Oct 15, 2021
@connor4312
Copy link
Member

connor4312 commented Oct 15, 2021

This is because by default we'll only resolve sourcemaps for programs in the same package as the target file. This was added intentionally to avoid very long boot times in monorepos that might have lots of irrelevant packages.

To fix this, you can add "resolveSourceMapLocations": null (or use its default that globs the workspace folder) to have the debugger resolve sourcemaps everywhere.


Also, you can set breakpoints in the test files themselves with some quick changes to runner.ts:

diff --git a/packages/pyright/packages/pyright-internal/src/tests/harness/fourslash/runner.ts b/packages/pyright/packages/pyright-internal/src/tests/harness/fourslash/runner.ts
index a99b81e4..bb55b3fc 100644
--- a/packages/pyright/packages/pyright-internal/src/tests/harness/fourslash/runner.ts
+++ b/packages/pyright/packages/pyright-internal/src/tests/harness/fourslash/runner.ts
@@ -6,6 +6,7 @@
  * Provide APIs to run fourslash tests from provided fourslash markup contents
  */
 
+import { dirname } from 'path';
 import * as ts from 'typescript';
 
 import { combinePaths } from '../../../common/pathUtils';
@@ -69,7 +70,8 @@ export function runFourSlashTestContent(
             : new TestState(absoluteBasePath, testData, mountPaths, hostSpecificFeatures);
     const output = ts.transpileModule(content, {
         reportDiagnostics: true,
-        compilerOptions: { target: ts.ScriptTarget.ES2015 },
+        fileName,
+        compilerOptions: { target: ts.ScriptTarget.ES2015, inlineSourceMap: true, sourceRoot: 'file:///' + dirname(fileName) },
     });
     if (output.diagnostics!.length > 0) {
         throw new Error(`Syntax error in ${absoluteBasePath}: ${output.diagnostics![0].messageText}`);

note that because the script is eval'd, breakpoints will be off by a line (the debugger doesn't really know ahead of time whether the source map accounts for this, jest's do but tsc's don't), but it's a little better experience, perhaps. Also you may want to add windows handling to form the sourceRoot uri, that is just a quick hack to demo 😉

@connor4312 connor4312 added *as-designed Described behavior is as designed and removed bug Issue identified by VS Code Team member as probable bug labels Oct 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
*as-designed Described behavior is as designed
Projects
None yet
Development

No branches or pull requests

2 participants