首页 > 解决方案 > 赛普拉斯错误 Cypress.moment.duration(时刻未定义)

问题描述

我正在使用 Cypress 并升级到 v8.3.1 版本,并且不断出现新错误。

Cannot read property 'duration' of undefined

Because this error occurred during a after all hook we are skipping all of the remaining tests.

地点:node_modules/@cypress/code-coverage/support.jsat line210

  cy.task('coverageReport', null, {
    timeout: Cypress.moment.duration(3, 'minutes').asMilliseconds(),
                           ^
    log: false
  })

它说duration找不到,因为Cypress.moment不存在。

我检查了更改日志,他们将其删除:

Cypress.moment() has been removed. Please migrate to a different datetime formatter. See our recipe for example replacements. Addresses #8714.

但是由于我没有直接使用它,它在包含的代码覆盖范围内Cypress,我不知道如何修复它。

标签: cypress

解决方案


您不知何故获得了旧版本的@cypress/code-coverage。

也许您升级了赛普拉斯而不是代码覆盖包?

@cypress/code-coverage@3.2.0 - support.js

after(function generateReport() {
  // when all tests finish, lets generate the coverage report
  cy.task('coverageReport', {
    timeout: Cypress.moment.duration(3, 'minutes').asMilliseconds()
  })
})

@cypress/code-coverage@3.9.10 - support.js

after(function generateReport() {
  ...
  cy.task('coverageReport', null, {
    timeout: dayjs.duration(3, 'minutes').asMilliseconds(),
    log: false
  }).then((coverageReportFolder) => {
  ...
})

npm update @cypress/code-coverage应该修复它


推荐阅读