【问题标题】:Configuring Cypress.env() variable to an imported module file将 Cypress.env() 变量配置为导入的模块文件
【发布时间】:2020-06-01 17:28:24
【问题描述】:

我正在尝试在Cypress.io 中设置和配置一个新的env 变量。在文件cypress/plugins/index.js 中,我导入了另一个文件,如下所示:

const { getBranch } = require('path/to/file/goes/here/getBranch');

然后,我尝试像这样设置新的env 变量:

// cypress/plugins/index.js

module.exports = (on, config) => {
  terminalReport.installPlugin(on);

  const configuration = config;
  configuration.env.injectMainBranchId = getBranch('develop');

  // more code below...

但是,这不起作用。但是,如果我硬编码它确实有效的值:

configuration.env.injectMainBranchId = 'develop';

您可以在下面的屏幕截图中看到结果:

这是getBranch模块的虚拟内容:

const getBranch = branch => {
  return branch;
};

module.export = { getBranch };

我做错了什么?

【问题讨论】:

  • module.exports = { getBranch };中的错字
  • 乐于助人:)

标签: javascript import module environment-variables cypress


【解决方案1】:

getBranch 中的错字:

const getBranch = branch => {
  return branch;
};

module.export = { getBranch };

export 应改为exports

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 2018-07-04
    • 2016-01-07
    相关资源
    最近更新 更多