【发布时间】:2021-12-03 18:22:06
【问题描述】:
我有一个 Nx 驱动的 Angular 项目,并且面临一个问题,即在 cypress.env.json 文件中提供的值不会覆盖 cypress.json 配置文件的 env 对象中的相应条目
这是我第一次尝试在 Nx 驱动的项目中进行此操作,在非 Nx 角度项目中,这种行为在赛普拉斯开箱即用。
复制步骤
在 e2e 应用程序的 cypress.json 文件中,添加一个 env 对象属性,并将一个空值分配给某个变量名称属性:
// cypress.json
"env": {
"MY_VAR": "abc"
}
在与 cypress.json 相同的位置创建一个 cypress.env.json 文件,其键与刚刚添加到 cypress.json 的 env 变量名称匹配:
// cypress.env.json
{
"MY_VAR": "xyz"
}
现在创建一个简单的测试套件来断言 env 变量等于 cypress.env.json 中的值
// create a test spec containing this
describe('When reading the MY_VAR env variable', () => {
it('should match the value in our cypress.env.json file', () => {
cy.log('MY_VAR = ' + Cypress.env('MY_VAR'))
expect(Cypress.env('MY_VAR')).to.eq('xyz');
});
});
通过 nx e2e 运行器 (nx run app-name:e2e) 运行此套件时,将引发断言错误:
AssertionError: expected 'abc' to equal 'xyz'
+ expected - actual
-'abc'
+'xyz'
我已经验证了我的非 Nx angular\cypress 项目的行为按预期工作 - 值得注意的是,我的另一个项目中的 cypress.env.json 与 cypress.json 文件一起位于项目的根目录中。
我尝试在我的 Nx 项目的根目录中找到 cypress.env.json 文件,而不是在 cypress.json 旁边的 apps/my-app-e2e/src 中,但这并没有什么区别。
我是否误解了如何通过 Nx 实现这一目标?
项目依赖如下:
Node : 12.16.3
OS : darwin x64
npm : 6.14.5
nx : 12.9.0
@nrwl/angular : 12.9.0
@nrwl/cli : 12.9.0
@nrwl/cypress : 12.9.0
@nrwl/devkit : 12.9.0
@nrwl/eslint-plugin-nx : 12.9.0
@nrwl/express : Not Found
@nrwl/jest : 12.9.0
@nrwl/linter : 12.9.0
@nrwl/nest : 12.9.0
@nrwl/next : Not Found
@nrwl/node : 12.9.0
@nrwl/nx-cloud : 12.3.13
@nrwl/react : Not Found
@nrwl/schematics : Not Found
@nrwl/tao : 12.9.0
@nrwl/web : Not Found
@nrwl/workspace : 12.9.0
@nrwl/storybook : 12.9.0
@nrwl/gatsby : Not Found
typescript : 4.3.5
【问题讨论】:
标签: angular cypress nrwl-nx nrwl