typescript Cypress -安装“del”模块时发生错误,无法打开Cypress

jjjwad0x  于 2023-02-25  发布在  TypeScript
关注(0)|答案(1)|浏览(143)

我安装了del模块:www.example.comhttps://docs.cypress.io/api/plugins/after-spec-api#Delete-the-recorded-video-if-the-spec-passed
然后我配置了cypress config,但是这一行:

const del = require('del')

使得Cypress无法正常工作(我甚至不能选择任何浏览器):第一节第一节第一节第一节第一次
当我注解掉这一行(const del = require('del '))时,cypress工作正常。
我该怎么修呢?

  • Cypress版本:12.5
  • 删除版本:7.0.0
qmelpv7a

qmelpv7a1#

del v7.0.0的最新版本与Cypress给出的示例代码不兼容。
您可以降级到v6.1.1,示例代码将运行。

npm install del@6.1.1

我会先删除7.0.0版本,以确保您安装了旧版本。
您可以使用7.0.0版并更改代码以使用dynamic import
最新版本还将函数名更改为deleteAsyncdeleteSync,因此用法略有不同。
以下是对Cypress示例代码的更改:

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)
          })
        }
      })
    },
  },
})

相关问题