尝试在ReactBoilerplate存储库中进行柏树反应单元测试

时间:2020-10-14 10:54:48

标签: reactjs typescript unit-testing cypress

因此,在过去的5个小时左右,我一直在用力撞墙,试图找出如何使其全部正常工作。

然后,我复制了内部项目的结构和部门,并将其放入公共仓库,以尝试获得帮助。我知道这将是某种不良的配置问题,但我只是不知道在哪里。

有人可以帮助我了解如何在webpack打字稿react项目中进行cypress react单元测试吗?

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

尝试运行时

yarn run cypress open

然后运行从UI出现的单个测试...

我似乎总是从cypress那里得到一些与webpack / typescript相关的构建错误:enter image description here

认为这有帮助...这是尝试从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",
...

1 个答案:

答案 0 :(得分:0)

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