【问题标题】:Run Cypress dockerized passing parameters when using multiple commands使用多个命令时运行 Cypress dockerized 传递参数
【发布时间】:2021-12-25 02:11:25
【问题描述】:

我有一个关于在 docker 容器中运行 cypress 的快速问题(对 Docker 没有太多经验,如果这是一个愚蠢的问题,请见谅)

假设我的脚本部分是这样的:

"scripts": {
    "clean:reports": "rmdir /S /Q cypress\\reports && mkdir cypress\\reports && mkdir cypress\\reports\\mochareports",
    "pretest": "npm run clean:reports",
    "scripts": "cypress run",
    "combine-reports": "mochawesome-merge cypress/reports/mocha/*.json > cypress/reports/mochareports/report.json",
    "generate-report": "marge cypress/reports/mochareports/report.json -f report -o cypress/reports/mochareports",
    "posttest": "npm run combine-reports && npm run generate-report",
    "test" : "npm run scripts || npm run posttest"
  },

我的 dockerfile 入口点如下:

ENTRYPOINT ["npm","run"]

但是当我从“docker run”命令行运行 cypress 时,我需要传递一些参数...有没有办法传递参数(例如带有要执行的规范文件名的 --spec 参数)考虑“测试”脚本有两个命令?

我传递的参数是否仅适用于“npm run scripts”?还是两个命令都会收到?

谢谢

【问题讨论】:

    标签: docker automation parameters scripting cypress


    【解决方案1】:

    如果您使用entrypoint,您的默认命令 (cmd) 将连接到它。因此,入口点为 npm run 和默认命令(例如)test 的 Dockerfile 只会在容器中生成 npm run test

    如果你想覆盖默认命令或入口点,因为两者都是可能的,你必须使用docker run [OPTIONS] my-cypress-image npm run test --spec

    如果你想运行 cypress 命令,例如:docker run --entrypoint /bin/bash my-docker-image cypress run --spec

    这两个选项都将导致容器在测试完成前不久运行。您还可以选择通过docker run my-docker-image bash 保持容器运行,并通过docker exec npm run test 命令运行测试。

    【讨论】:

      猜你喜欢
      • 2013-03-20
      • 1970-01-01
      • 1970-01-01
      • 2015-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-25
      • 2020-08-06
      相关资源
      最近更新 更多