CircleCI 设置与 Cypress 和 React-testing-library



我想使用 CircleCi 来运行我的 Cypress 和 react-testing-library 测试,因为我想测试我的 react 应用程序。 在本地 env 上我会运行(工作正常):

  • yarn run test执行我的反应测试库测试
  • yarn cypress run执行柏树测试

现在,我找到了有关如何制作 circleci 的资源config.yaml但没有任何效果。参考链接 1、链接 2、链接 3、链接 4、链接 5

一些测试失败是由于:error cypress@7.1.0: The engine "node" is incompatible with this module. Expected version ">=12.0.0". Got "10.24.1"或错误的兑现或其他原因。跑了20次后我一无所知,有人可以帮我吗?

当我浏览资源时,我认为这应该适用于赛普拉斯测试,但事实并非如此。

version: 2.1
orbs:
cypress: cypress-io/cypress@1
workflows:
build: 
jobs:
- cypress/install:
build: yarn run build # run a custom app build step
yarn: true
- cypress/run:
requires:
- cypress/install
parallel: true # split all specs across machines
parallelism: 4 # use 4 CircleCI machines to finish quickly
yarn: true
group: 'all tests' # name this group "all tests" on the dashboard
start: yarn start # start server before running tests

对于那些稍后将搜索此问题的人。我克服了错误:

  • error cypress@7.1.0: The engine "node" is incompatible with this module. Expected version ">=12.0.0". Got "10.24.1"不使用 orb,而是使用workflow->jobs->steps
  • 通过使用yarn而不是npmfsevents not accessible from jest-haste-map
  • 最后,您的一些错误可能来自您的应用程序(至少在我的情况下是 react 应用程序)从未上传到 github 的文件.env获取配置,因此没有签出到 CircleCI docker,因此在测试期间应用程序将不起作用。

我正在使用的工作解决方案是:

version: 2.1
jobs:
run_tests:
docker:
- image: cypress/base:12
environment:
# this enables colors in the output
TERM: xterm
working_directory: ~/portalo
steps:
- checkout
- run:
name: Install project dependencies
command: yarn install --frozen-lockfile
- run: 
name: Compile and start development server on port 3000
command: yarn startOnPort3000Linux
background: true
- run: 
name: Wait for development server to start
command: 'yarn wait-on http://localhost:3000'
- run: 
name: Run routing tests with react-testing-library via yarn test
command: 'yarn test ~/portalo/src/tests/react-testing-library/routing.test.tsx'
- run: 
name: Run e2e tests with Cypruss via cypress run
command: $(yarn bin)/cypress run
workflows:
version: 2.1
build_and_test:
jobs:
- run_tests

注意:必须添加wait-on。就我而言,yarn add wait-on

注意2:所有步骤必须在一个步骤中才能显示所有已安装的软件包。它可以是使用保存/还原缓存的推文。

最新更新