Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

vscode breakpoints not being hit in TS mocha tests

未关闭
#280 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
docker-compose, node.js, typescript, vscode

调研方向

从 docker-compose 定义、VS Code 启动配置以及 package.json 中的 test-brk 命令开始。比较在主机和容器中的测试运行情况,包括生成的源代码和 source maps 所使用的路径;当通过 docker-compose exec 运行测试时 Mocha 断点能够解析,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Hi

I have a boilerplate express project in TS.
My setup is that I run the project and the build tool chain inside a docker container; the goal being simple replication of dev environments across multiple machines.

The container is managed by the following compose definition:

  services:
    node:
      image: node:12.18.1
      hostname: app-node-dev
      command: npm run dev
      environment:
        - HOME=/home/me/workspace/service-kit/sk-base-nodejs
        - NODE_ENV=development
      ports:
        - 8080:8080
        - 18080:18080
        - 9222:9222
        - 9321:9321
      volumes:
        - ../..:/home/me/workspace/service-kit/sk-base-nodejs:rw
        - /etc/group:/etc/group:ro
        - /etc/passwd:/etc/passwd:ro
        - /etc/shadow:/etc/shadow:ro
        - /tmp:/tmp:rw
      user: ${_UID}:${_GID}
      working_dir: /home/me/workspace/service-kit/sk-base-nodejs
      stdin_open: true
      tty: true
      restart: unless-stopped

Note that I am using the working dir as an exact copy of the absolute path on my host machine.
Previously I was mounting to /workspace but I thought that the unmatching paths may be causing the problem; apparently not.

I mount the passwd/shadow so that I can maintain the file ownership.

I have the following vscode launch configuration to attach to the running app instance:

    {
        "type": "node",
        "request": "attach",
        "name": "SK - Attach to Node",
        "protocol": "inspector",
        "port": 9222,
        "restart": true,
        "localRoot": "${workspaceFolder}/dist",
        "remoteRoot": "/workspace/dist",
        "outFiles": [
          "${workspaceFolder}/dist/**/*.js"
        ],
        "skipFiles": [
          "<node_internals>/**/*.js",
        ]
      },

This works great. I can attach and hit breakpoints as expected.

However the problem is when I execute mocha tests via the following launch configuration:

      {
          "type": "node",
          "request": "launch",
          "name": "SK - Mocha Tests Bak",
          "cwd": "${workspaceRoot}",
          "runtimeExecutable": "make",
          "runtimeArgs": [
              "npm",
              "run",
              "test-brk"
          ],
          "env": {
            "NODE_ENV": "test-external",
          },
          "port": 9321,
          "console": "integratedTerminal",
          "internalConsoleOptions": "neverOpen",
          "protocol": "inspector",
          "sourceMaps": true,
      },

One key unusual thing here is that I am executing make npm run test-brk. This make command translates to a docker-compose exec that runs npm run test-brk within the running container.

The test-brk command in the package.json is defined as:

"test-brk": "mocha --require node_modules/ts-node/register --inspect-brk=0.0.0.0:9321 --debug-brk --exit test/**/*.spec.ts",

When I launch the debug config in vscode the tests launch and execute and pass; but the breakpoints are not hit.

`Breakpoint ignored because generated source not found (source map problem?)`

Here is where things get interesting. The above execution runs the npm run test-brk within the container. If I install node on my dev machine and execute npm run test-brk from my host then everything works as expected - the tests run and the breakpoints are hit.

In short - it appears that vscode cannot find the source maps if I run mocha from within the container. But the source maps are found if I run mocha from on the host.

Is there something that I am missing that gets generated within the container that vscode cannot access? even though the workspace folder is mounted?

I would really appreciate any input on this.

Node is version 12.18.1
Source map support 0.5.19

主要语言
JavaScript
星标
2.2k
派生
221
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

evanw/node-source-map-support 的其他 Issue

查看 evanw/node-source-map-support 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。