【问题标题】:Cypress build error in Azure pipeline: Cannot find module '@cypress/code-coverage/task'Azure 管道中的赛普拉斯构建错误:找不到模块“@cypress/code-coverage/task”
【发布时间】:2021-12-23 01:27:09
【问题描述】:

这是我的配置:

// cypress/plugins/index.js
module.exports = (on, config) => {
  require('@cypress/code-coverage/task')(on, config);
  //require('@bahmutov/cypress-extends')(on, config);
  return config
}

尝试在 Azure 管道脚本(在 cypress/包含的容器内)中运行 cypress 时出现错误。在本地运行时不会出现此错误。

The function exported by the plugins file threw an error.

We invoked the function exported by `/root/e2e/cypress/plugins/index.js`, but it threw an error.

 Error: Cannot find module '@cypress/code-coverage/task'
Require stack:
- /root/e2e/cypress/plugins/index.js
- /root/.cache/Cypress/9.1.1/Cypress/resources/app/packages/server/lib/plugins/child/run_plugins.js

我正在做的唯一不寻常的事情是:

// cypress/config/cypress.local.json
{
  "extends": "../../cypress.json",
  "baseUrl": "https://localhost:4200"
}

还有一个普通的 cypress.json 配置:

// /cypress.json
{
  "baseUrl": "http://localhost:4200",
  "proxyUrl": "",
  "defaultCommandTimeout": 10000,
  "video" : false,
  "screenshotOnRunFailure" : true,
  "experimentalStudio": true,
  "projectId": "seixri",
  "trashAssetsBeforeRuns" : true,
  "videoUploadOnPasses" : false,
  "retries": {
    "runMode": 0,
    "openMode": 0
  },
  "viewportWidth": 1000,
  "viewportHeight": 1200
}

【问题讨论】:

    标签: azure azure-devops azure-pipelines cypress


    【解决方案1】:

    这里的问题可能是赛普拉斯不支持按照您的方式扩展配置文件,这里也有说明:https://www.cypress.io/blog/2020/06/18/extending-the-cypress-config-file/

    我认为有两种合适的解决方法:

    1.方法:使用单独的配置文件(我的建议)

    由于扩展现有配置文件不起作用,我建议使用单独的配置文件,例如一种用于本地使用,一种用于在 Azure 管道中执行。然后,您可以在 package.json 中简单地添加两个单独的命令,例如:

      "scripts": {
        "cy:ci": "cypress run --config-file cypress/cypress.json",
        "cy:local": "cypress run --config-file cypress/cypress.local.json"
      },
    

    文档:https://docs.cypress.io/guides/references/configuration

    2。方法:在测试中设置配置选项

    赛普拉斯为您提供了直接在测试中覆盖配置的选项。例如,如果您在cypress.json 中配置了以下内容:

    {
      "viewportWidth": 1280,
      "viewportHeight": 720
    }
    

    您可以在测试中更改 viewportWidth,例如:

    Cypress.config('viewportWidth', 800)
    

    文档:https://docs.cypress.io/api/cypress-api/config#Syntax

    【讨论】:

    • 是的,事实证明扩展配置导致了部分问题。
    猜你喜欢
    • 2022-08-04
    • 2020-07-11
    • 2021-07-05
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-21
    • 2022-06-27
    相关资源
    最近更新 更多