"Uncaught SyntaxError: Invalid or unexpected token" occurs when running e2e test for the angular app using cypress framework

"Uncaught SyntaxError: Invalid or unexpected token" occurs when running e2e test for the angular app using cypress framework

我正在使用cypress 为我们的angular 应用程序做e2e 测试,当cypress 自动打开应用程序主页时,出现错误,并在浏览器控制台打印"Uncaught SyntaxError: Invalid or unexpected token" 就像附上的截图显示,vendor.xxx.js文件中似乎有乱码,但该文件是由angular框架自动编译生成的,在我们日常使用中没有问题。 不是每次用cypress启动运行都会出现这个错误,如果我在浏览器中手动输入URL访问应用程序,这个错误就会消失,我不确定是不是cypress的bug当它触发或启动浏览器进行测试时,毕竟它是cypress框架操纵浏览器。该错误发生在内置的 Eletron 浏览器和由 cypress 控制的 chrome 浏览器中。使用的cypress版本是3.4.0,如果有大佬指点一下,不胜感激

function d3_asin(x){
  return x > 1 half ??: x < -1 ? half :math.asin(x);
}

 function d3_asin(x){
   return ((x = Math.exp(x)) - 1 / x) / 2;
 }

The same file run on the standalone Chrome was loaded correctly,so it had to be issue with Cypress encoding. After some googling we found that Cypress settings has default settings with this property:

"modifyObstructiveCode": true

after setting it to false it work well.

它可能不理想,但您尝试添加

Cypress.on('uncaught:exception', (err, runnable) => {
    // returning false here prevents Cypress from
    // failing the test
    return false
  })

到您的 index.js 支持文件夹下?

如果有未捕获的异常,这将阻止您的测试失败。

您可以通过将文件 browserslist 的名称更改为 .browserslistrc 来解决它。 我有同样的问题它帮助了我。 查看以下问题:

https://github.com/cypress-io/cypress/issues/8864