【发布时间】:2022-10-01 15:56:46
【问题描述】:
我刚刚升级到 Cypress 10,现在收到来自我用来将交互式用户登录到被测站点的 amplify auth 库的问题。我为此做了一个
cy
扩展。
这是 sdk 中的一个已知问题,它使用了这个
global
变量,通过填充它来克服角度问题:
/**
* AWS Amplify - Currently, the newest versions of Angular (6+) do not provide the shim for the
* global object which was provided in previous versions.
*/
(window as any).global = window;
我已经尝试在 Cypress 10 的许多地方添加它:
- 在扩展文件中
- 在赛普拉斯配置文件中
- 在支持文件中
但没有运气。
FWIW, the gist of the extension
这是完整的堆栈跟踪:
ReferenceError 以下错误源于您的测试代码,而不是 来自赛普拉斯。
全局未定义
当赛普拉斯检测到源自您的测试代码的未捕获错误时 它将自动使当前测试失败。
赛普拉斯无法将此错误与任何特定测试相关联。
我们动态生成了一个新的测试来显示这个失败。看法 堆栈跟踪打印到控制台 在 node_modules/amazon-cognito-identity-js/node_modules/buffer/index.js (http://localhost:4200/__cypress/tests?p=cypress\\support\\e2e.ts:12878:37) 在 __require2 (http://localhost:4200/__cypress/tests?p=cypress\\support\\e2e.ts:17:52) 在 eval (http://localhost:4200/__cypress/tests?p=cypress\\support\\e2e.ts:27843:31) 在 eval (http://localhost:4200/__cypress/tests?p=cypress\\support\\e2e.ts:33508:3) 在 eval () 来自上一个事件: 在 runScriptsFromUrls (http://localhost:4200/__cypress/runner/cypress_runner.js:165206:136) 在 Object.runScripts (http://localhost:4200/__cypress/runner/cypress_runner.js:165221:12) 在 $Cypress.onSpecWindow (http://localhost:4200/__cypress/runner/cypress_runner.js:153378:75)
我试过在扩展文件的顶部添加这个:
let global = {}; (window as any).global = window; /** * amplify-js / cognito auth helper * specific personas are logged-in and their tokens are cached to save on round-trips. */ import Auth, { CognitoUser } from \'@aws-amplify/auth\'; import Amplify from \'@aws-amplify/core\';