Cypress:Electron 不支持 .finally()?

Cypress: Electron doesn't support .finally()?

Electron 3.x 添加了对 javascript .finally()

的支持

我对此有疑问,因为我的 Vue 应用程序在处理 axios 请求时实际上使用了 .finally。

并且 运行 使用 electron 的赛普拉斯测试由于 .finally() 而失败。 ...

I cannot ask the team to refactor code for a problem only with a test suite and only with the 'auto' mode because we're still working on local culture to accept to spend time across testing. If I ask this to the devs, someone will shutdown testing...

问题:有没有办法让 Electron 能够消化这种语法?

webapp 是用 Laravel 5.8.x、Vue 2 和 axios 制作的,由 webmix(webpack 链)转译。

您有两个选择:

  1. 将 cypress 升级到 3.5.0uses Electron 5.

  2. 或者,使用 polyfill。

    首先,安装 es-shims/Promise.prototype.finally:

    npm install -D promise.prototype.finally
    

    然后,在您的 cypress/support/index.js:

    const { implementation: FinallyPolyfill } = require('promise.prototype.finally');
    
    function loadPolyfill ( win ) {
        win.Promise.prototype.finally = FinallyPolyfill;
    }
    
    // polyfill AUT's Promise
    Cypress.on('window:before:load', win => {
        loadPolyfill(win);
    });
    
    // polyfill Cypress runner's wrapper window Promise
    before(() => {
        loadPolyfill(window);
    });