首页 > 解决方案 > 试图在 ReactBoilerplate repo 中进行 cypress react 单元测试

问题描述

所以在过去的 5 个小时左右,我一直把头撞在墙上,试图弄清楚如何让这一切正常工作。

然后,我复制了一个内部项目的结构和部门,并将其制成公共回购,以尝试获得一些帮助。我知道这将是某种糟糕的配置问题,但我就是不知道在哪里。

有人可以帮我理解我需要做什么才能在 webpack typescript react 项目中进行 cypress react 单元测试吗?

https://github.com/glomotion/test-cypress-typescript-react

尝试运行时

yarn run cypress open

然后运行从 UI 显示的单个测试...

我似乎总是从 cypress 得到某种与 webpack/typescript 相关的构建错误:在此处输入图像描述

incasse 它有帮助...这里有一些来自控制台的额外调试信息,同时尝试使用额外的 webpack 调试信息运行:

cypress:webpack stats had error(s) +8s
  cypress:webpack errored bundling /Users/timpaul/Library/Application Support/Cypress/cy/production/projects/test-cypress-typescript-react-ffdf18db96b66e8934f9c769081501f9/bundles/src/components/vertical-space/vertical-space.cypress.test.tsx.js Webpack Compilation Error
./src/components/vertical-space/vertical-space.cypress.test.tsx
Module build failed (from ./node_modules/ts-loader/index.js):
Error: TypeScript emitted no output for /Users/timpaul/Desktop/GIT-Repos/test-cypress-typescript-react/src/components/vertical-space/vertical-space.cypress.test.tsx. +8ms
  cypress:webpack - compile finished for /Users/timpaul/Desktop/GIT-Repos/test-cypress-typescript-react/src/components/vertical-space/vertical-space.cypress.test.tsx, initial? true +93ms
Webpack Compilation Error
./src/components/vertical-space/vertical-space.cypress.test.tsx
Module build failed (from ./node_modules/ts-loader/index.js):
Error: TypeScript emitted no output for /Users/timpaul/Desktop/GIT-Repos/test-cypress-typescript-react/src/components/vertical-space/vertical-space.cypress.test.tsx.
GET /__cypress/tests?p=src/components/vertical-space/vertical-space.cypress.test.tsx 200 8680.292 ms - 431
  cypress:webpack finished bundling /Users/timpaul/Library/Application Support/Cypress/cy/production/projects/test-cypress-typescript-react-ffdf18db96b66e8934f9c769081501f9/bundles/cypress/support/index.js +432ms
  cypress:webpack - compile finished for /Users/timpaul/Desktop/GIT-Repos/test-cypress-typescript-react/cypress/support/index.js, initial? true +7ms

包依赖版本:

// package.json:
...
 "engines": {
   "npm": ">=6.14.8",
   "node": ">=12.18.4"
 },
...
"cypress-react-unit-test": "^4.16.0",
"@cypress/webpack-preprocessor": "^5.4.7",
"cypress": "^5.3.0",
"typescript": "^4.0.3",
"webpack": "^4.44.2",
...

标签: reactjstypescriptunit-testingcypress

解决方案


原来这只是删除 webpack mini css 加载器的问题。


推荐阅读