Cypress – 安装 ‘del’ 模块时出现错误,无法打开 Cypress。

huangapple go评论66阅读模式
英文:

Cypress - error occurs when I installed 'del' module, cant open cypress

问题

我安装了del模块:https://docs.cypress.io/api/plugins/after-spec-api#Delete-the-recorded-video-if-the-spec-passed

然后我配置了Cypress配置,但这行代码:

const del = require('del')

导致Cypress无法正常工作(甚至无法选择任何浏览器):

Cypress – 安装 ‘del’ 模块时出现错误,无法打开 Cypress。
Cypress – 安装 ‘del’ 模块时出现错误,无法打开 Cypress。

当我注释掉这行代码(const del = require('del'))时,Cypress正常工作。

我该如何修复它?

  • Cypress版本:12.5
  • del版本:7.0.0
英文:

I installed del module:
https://docs.cypress.io/api/plugins/after-spec-api#Delete-the-recorded-video-if-the-spec-passed

then I configured cypress config but this line:

const del = require('del')

makes that cypress is not working (I cant even select any browser):
Cypress – 安装 ‘del’ 模块时出现错误,无法打开 Cypress。
Cypress – 安装 ‘del’ 模块时出现错误,无法打开 Cypress。

When I commented out this line (const del = require('del')), cypress worked normally.

How can I fix it?

  • Cypress version: 12.5
  • del version: 7.0.0

答案1

得分: 1

The latest version of del v7.0.0 isn't compatible with the example code Cypress gives.

You could downgrade to v6.1.1 and the sample code will run.

npm install del@6.1.1

I would remove ver 7.0.0 first to be sure you get the older version installed.


You can use ver 7.0.0 and alter the code to use dynamic import.

The newest version also changes the function names to deleteAsync and deleteSync, so the usage is slightly different.

Here's the changes to the Cypress sample code:

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on('after:spec', (spec, results) => {
        if (results && results.stats.failures === 0 && results.video) {
          return import('del').then(del => {
            return del.deleteSync(results.video)
          })
        }
      })
    },
  },
})
英文:

The latest version of del v7.0.0 isn't compatible with the example code Cypress gives.

You could downgrade to v6.1.1 and the sample code will run.

npm install del@6.1.1

I would remove ver 7.0.0 first to be sure you get the older version installed.


You can use ver 7.0.0 and alter the code to use dynamic import.

The newest version also changes the function names to deleteAsync and deleteSync, so the usage is slightly different.

Here's the changes to the Cypress sample code:

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on('after:spec', (spec, results) => {
        if (results && results.stats.failures === 0 && results.video) {
          return import('del').then(del => {
            return del.deleteSync(results.video)
          })
        }
      })
    },
  },
})

huangapple
  • 本文由 发表于 2023年2月24日 01:39:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75548408.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定