使用VSCode或Chrome中的Typescript创建React App进行调试测试

时间:2017-08-13 18:05:38

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

使用创建应用 (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

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

1 个答案:

答案 0 :(得分:0)

现在已经修复了。 https://github.com/Microsoft/TypeScript-React-Starter/issues/46

  1. 安装Node 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