如何为特定环境的 运行 测试传递自定义参数

How to pass in custom parameter for running tests on particular env

我正在 运行我的测试使用 - .testcaferc.json 文件和我用于 运行 的命令是:node node_modules/testcafe/bin/testcafe

我想为 运行我在不同环境下的不同测试传递一个附加参数。当我尝试在命令中添加该参数时:node node_modules/testcafe/bin/testcafe production 然后我无法添加它,因为它认为它们是测试。

请告诉我该如何处理。

您可以在这种情况下使用环境变量。

设置环境变量

// Enviroment variable set is platform specific
// See https://devexpress.github.io/testcafe/documentation/recipes/configuration/access-environment-variables-in-tests.html#set-environment-variables

export production=true

testcafe chrome test.js

并在测试中使用它

fixture ('Fixture');

test('test', async t => {
   console.log(process.env.production);
});