4

您好,我在设置 CircleCi 和 Cypress 时遇到问题。

我将 docker 映像包含了所有必要的依赖项,但它仍然无法正常工作。我尝试了大约 40 种不同的配置,但没有任何积极的结果。请检查下面屏幕截图中附加的我的配置和输出。

在此处输入图像描述

version: 2
jobs:
  build:
    docker:
      - image: circleci/node:9.2.0

      - image: circleci/mongo:3.4.4
      - image: cypress/base:8

working_directory: ~/repo

steps:
  - checkout

  - restore_cache:
      keys:
      - v1-dependencies-{{ checksum "package.json" }}
      - v1-dependencies-

  - run: yarn install

  - save_cache:
      paths:
        - node_modules
      key: v1-dependencies-{{ checksum "package.json" }}

  - run: yarn test   // THIS COMMAND RUNS UNIT TESTS - and it is working ok

  - run: yarn run dev & $(npm bin)/cypress run // THIS ONE IS FAILING

我还意识到,如果我删除 node/mongo 的图像并只运行 e2e 测试它正在工作。当我尝试使用三个 docker 映像同时运行单元测试和 e2e 测试时,就会出现问题。

4

2 回答 2

3

我尝试了 bkcura 的答案,但它没有用,并且仍然出现相同的错误。

所以我尝试使用新的圆形功能(球体)来混合两个球体:

它有效

这是我的config.yml

version: 2.1
orbs:
  cypress: cypress-io/cypress@1
  react: thefrontside/react@0.1.0
workflows:
  push:
    jobs:
      - react/install
      - react/test:
          requires:
            - react/install
  build:
    jobs:
      - cypress/run:
          yarn: true
          start: yarn start
          wait-on: 'http://localhost:3000'
          no-workspace: true

带有演示的回购:https ://github.com/jeanbauer/create-react-app-cypress-circle-ci

注意:可能这不是那么有效,所以如果您看到任何改进,请在此处向我发送问题

于 2019-09-02T18:41:42.660 回答
1

请参阅此处的文档:https ://docs.cypress.io/guides/guides/continuous-integration.html#Example-circle-yml-v2-config-file-with-yarn

您不需要缓存node_modules,而是缓存~/.cache

version: 2
jobs:
  build:
    docker:
      - image: cypress/base:8
        environment:
          ## this enables colors in the output
          TERM: xterm
    working_directory: ~/app
    steps:
      - checkout
      - restore_cache:
          keys:
            - v1-deps-{{ .Branch }}-{{ checksum "package.json" }}
            - v1-deps-{{ .Branch }}
            - v1-deps
      - run:
          name: Install Dependencies
          command: yarn install --frozen-lockfile
      - save_cache:
          key: v1-deps-{{ .Branch }}-{{ checksum "package.json" }}
          paths:
            - ~/.cache  ## cache both yarn and Cypress!
      - run: $(yarn bin)/cypress run --record --key <record_key>

为什么?

Cypress 在你的项目文件夹之外安装了一个预构建的平台特定二进制文件,~/.cache/Cypress这个东西是 ~200mb,下载需要一些时间,所以你应该缓存它。

而且它只安装在 上postInstall,如果你缓存就不会发生node_modules,因此错误消息 =)

于 2018-06-28T11:10:35.863 回答