Debugging Tests With Create React App using Typesc

2020-07-27 05:10发布

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条回答
叼着烟拽天下
2楼-- · 2020-07-27 05:38

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
查看更多
登录 后发表回答