简体   繁体   English

如何使用Node(express.js)后端和create-react-app作为前端运行Jest测试

[英]How to run Jest tests with Node (express.js) backend and create-react-app as frontend

I have the following folder structure: 我具有以下文件夹结构:

在此处输入图片说明

Clearly React is using Jest in "Client" node_modules. 显然,React在“客户端” node_modules中使用Jest。 If i try to install Jest for server node_modules (one lvl up), i will get error from React, saying i have duplicate packages up in the tree. 如果我尝试为服务器的nod​​e_modules安装Jest(最多升级一个),我将从React收到错误消息,说我在树中有重复的软件包。 How should i run tests for server with Jest? 我应该如何使用Jest对服务器进行测试? How should i install Jest for server? 我应该如何为服务器安装Jest? Or should i? 还是我应该? Or i can use the same Jest react uses in "Client" folder? 或者我可以在“客户端”文件夹中使用相同的Jest react使用? If so, how? 如果是这样,怎么办? What is the command? 命令是什么? Really appreciate your help. 非常感谢您的帮助。

通过使用npm link client/node_modules/jest来自项目root的npm link client/node_modules/jest解决。

2 separate dependency trees, avoiding duplicate packages up in the tree would look like following: 2个独立的依赖关系树,避免树中出现duplicate packages up in the tree如下所示:

server
  ├──> node_modules
  ├──> index.js
  └──> package.json
client
  ├──> node_modules
  ├──> index.js
  └──> package.json
.gitignore
README.md

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

相关问题 用于后端的节点JS Express和用于前端的React JS - Node JS Express for backend and React JS for frontend 如何通过 Vercel 部署 Node.js 和 Express.js 后端以供 Next.js 前端使用? - How to deploy Node.js & Express.js Backend to be used by Next.js Frontend via Vercel? 如何在快速后端server.js文件中设置一些值并在create-react-app代码中使用它? - How to set some value in express backend server.js file and use it in create-react-app code? Node + create-react-app + Express - 如何将函数导入 Express - Node + create-react-app + Express - how to import function into Express 部署React-(Create-React-App),Express.js和MySQL - Deploy React-(Create-React-App),Express.js and MySQL 如何在 React.js 前端和 Express.js 后端之间发送值 - How to send value between React.js Frontend and Express.js Backend 使用 create-react-app 和 express.js 制作多页应用 - Make a multi-page app with create-react-app and express.js 如何将变量从 Express.js 后端发送到 React.js 前端? - How do I send a variable from Express.js backend to React.js frontend? 如何使用heroku在node.js后端实现create-react-app? - How to implement create-react-app with node.js backend with heroku? React.js:如何将搜索查询从 react.js 前端发送到 express.js 后端? - React.js: How do I send search query from react.js frontend to express.js backend?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM