Javascript 如何在Cypress和我们的应用程序之间导入通用配置?

Javascript 如何在Cypress和我们的应用程序之间导入通用配置?,javascript,typescript,cypress,sapper,Javascript,Typescript,Cypress,Sapper,为了在我的应用程序和用于oauth等外部服务的cypress设置之间共享公共配置,我创建了一个rootapp.config.js文件: const oauth2Endpoint=process.env.CI\u ENVIRONMENT\u NAME=='production' ? 'https://connect.company.com' : 'https://staging.connect.company.com'; 导出默认值{ oauth2:{ 端点:oauth2Endpoint, 授权U

为了在我的应用程序和用于oauth等外部服务的cypress设置之间共享公共配置,我创建了一个root
app.config.js
文件:

const oauth2Endpoint=process.env.CI\u ENVIRONMENT\u NAME=='production'
? 'https://connect.company.com'
: 'https://staging.connect.company.com';
导出默认值{
oauth2:{
端点:oauth2Endpoint,
授权URL:“${oauth2Endpoint}/oauth2/authorize`,
令牌URL:`${oauth2Endpoint}/oauth2/token`,
callbackURL:'http://localhost:3000/oauth',
logoutUrl:`${oauth2Endpoint}/oauth2/logout?客户端\u id=${process.env.CONNECT\u应用程序\u id}`
}
}
此文件已正确导入,并且在
src/server.js
下运行良好:

从“../app.config”导入配置;
console.log(config);
//后端服务器的东西。
因此,我在
cypress/support/commands.ts
文件上应用了相同的逻辑:

/@请参见https://on.cypress.io/custom-commands
从“../../app.config”导入配置;
add('login',(loginId:string='user\u default',password:string='test1234')=>{
柏树原木({
消息:`登录到staging.connect.company.com,身份:${loginId}:${password}`,
控制台操作:()=>({
罗吉尼,
密码,
}),
});
console.log(config);
赛义德请求({
方法:“POST”,
url:config.oauth2.authorizationURL,
表单:true,//我们正在提交一个常规表单正文
正文:{
罗吉尼,
密码,
},
});
});
但这在命令使用时产生了以下错误:

TypeError: Cannot read property 'oauth2' of undefined
如果我将
app.config.js
文件复制到
cypress.config.ts
文件(使用更新的相关导入),它将正常工作。但是,我对此不感兴趣,因为我想共享此文件

我如何解决这个问题

如果有帮助,下面是
cypress/tsconfig.json
文件内容:

{
“编译器选项”:{
“目标”:“es5”,
“lib”:[“es5”,“dom”],
“类型”:[“柏树”]
},
“包括”:[“***.ts”]
}

另外请注意,我在这个项目中使用了Sapper,但我不确信这是问题的根源。

我不确定Sapper,但我会使用
const appConfig=require('pathToAppConfigFile')
并根据需要使用变量