Debugging Tests With Create React App using Typescript in VSCode or Chrome

只愿长相守 提交于 2020-01-01 19:16:14

问题


Created an app using (https://github.com/Microsoft/TypeScript-React-Starter)

npm install -g create-react-app

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

I've gone through a number of articles, seem to be going around in circles, but have not yet found how i can debug the default app.test.tsx

Node is on version 7.9.0 Everything else should be on the latest version.


回答1:


This has been fixed now. https://github.com/Microsoft/TypeScript-React-Starter/issues/46

  1. Install Node v8.5

  2. Update to the latest version of Create-React-App (or update the react-scripts-ts to 2.7)

  3. Configure vscode debugger with

    {
        "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. If you are on typescript 2.5, add this to your project https://github.com/nicolaserny/create-react-app-typescript/blob/master/packages/react-scripts/template/tsconfig.test.json


来源:https://stackoverflow.com/questions/45663364/debugging-tests-with-create-react-app-using-typescript-in-vscode-or-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!