简体   繁体   English

在 VSCode 或 Chrome 中使用 Typescript 使用 Create React App 调试测试

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

Created an app using ( https://github.com/Microsoft/TypeScript-React-Starter )使用( https://github.com/Microsoft/TypeScript-React-Starter )创建了一个应用程序

npm install -g create-react-app npm install -g create-react-app

create-react-app my-app --scripts-version=react-scripts-ts 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我已经阅读了许多文章,似乎在兜圈子,但还没有找到如何调试默认的 app.test.tsx

Node is on version 7.9.0 Everything else should be on the latest version. Node 的版本是 7.9.0 其他所有东西都应该是最新版本。

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

  1. Install Node v8.5安装节点 v8.5

  2. Update to the latest version of Create-React-App (or update the react-scripts-ts to 2.7)更新到最新版本的 Create-React-App(或更新 react-scripts-ts 到 2.7)

  3. Configure vscode debugger with配置 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. 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如果您使用的是 typescript 2.5,请将其添加到您的项目https://github.com/nicolaserny/create-react-app-typescript/blob/master/packages/react-scripts/template/tsconfig.test.json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM