【问题标题】:Debugging Tests With Create React App using Typescript in VSCode or Chrome在 VSCode 或 Chrome 中使用 Typescript 创建 React App 来调试测试
【发布时间】:2018-01-21 15:12:44
【问题描述】:

使用创建的应用程序 (https://github.com/Microsoft/TypeScript-React-Starter)

npm install -g create-react-app

create-react-app my-app --scripts-version=react-scripts-ts

我浏览了很多文章,似乎在兜圈子,但还没有找到如何调试默认的 app.test.tsx

Node 版本为 7.9.0 其他一切都应该是最新版本。

【问题讨论】:

    标签: reactjs typescript2.0 jestjs create-react-app


    【解决方案1】:

    此问题现已修复。 https://github.com/Microsoft/TypeScript-React-Starter/issues/46

    1. 安装节点 v8.5

    2. 更新到最新版本的 Create-React-App (或将 react-scripts-ts 更新到 2.7)

    3. 使用

    4. 配置 vscode 调试器

        {
            "version": "0.2.0",
            "configurations": [
              {
                "name": "Debug CRA Tests",
                "type": "node",
                "request": "launch",
                "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts-ts",
                "runtimeArgs": [
                  "--inspect-brk",
                  "test"
                ],
                "args": [
                  "--runInBand",
                  "--no-cache",
                  "--env=jsdom"
                ],
                "cwd": "${workspaceRoot}",
                "protocol": "inspector",
                "console": "integratedTerminal",
                "internalConsoleOptions": "neverOpen"
              }
            ]
          }
    <!-- begin snippet: js hide: false console: true babel: false -->
    1. 如果您使用的是 typescript 2.5,请将其添加到您的项目中 https://github.com/nicolaserny/create-react-app-typescript/blob/master/packages/react-scripts/template/tsconfig.test.json

    【讨论】:

    • 我到处都在寻找这个。我还查看了 react 文档,但没有成功。非常感谢!
    猜你喜欢
    • 2017-04-28
    • 2021-04-09
    • 2017-07-31
    • 2019-04-29
    • 2022-07-05
    • 2017-09-23
    • 1970-01-01
    • 2017-09-23
    • 2016-02-05
    相关资源
    最近更新 更多