【问题标题】:Cypress - adding Cucumber柏树 - 加入黄瓜
【发布时间】:2021-08-19 10:08:39
【问题描述】:

这是一个非常基本的问题,但是由于我从来没有做过前端开发人员,所以 js 和 ts 对我来说还是很陌生的。

我正在尝试将 Cucumber 功能添加到 Cypress 测试套件中。我已经安装了 cypress-cucumber-preprocessor 包,但是当我能找到的所有操作指南和信息都使用 js 作为示例时,我遇到了问题。

我应该把它放到 index.js 文件中:

const cucumber = require('cypress-cucumber-preprocessor').default

module.exports = (on, config) => {
    on('file:preprocessor', cucumber())
}

由于测试套件有一个 index.ts 文件,这自然不能复制粘贴。如何将其转换为 .ts?

【问题讨论】:

    标签: typescript cypress


    【解决方案1】:

    该特定代码应该在index.ts 中工作

    import { default as cucumber } from 'cypress-cucumber-preprocessor'
    // or just 
    import cucumber from 'cypress-cucumber-preprocessor'
    
    export default (on, config) => {
        on('file:preprocessor', cucumber())
    }
    

    安装:

    npm install --save-dev cypress-cucumber-preprocessor
    npm install --save-dev @types/cypress-cucumber-preprocessor
    

    一般cypress-realworld-app 有打字稿作为示例的来源(但不是黄瓜)。

    【讨论】:

    • 谢谢。这给了我以下错误:“TS7016:找不到模块'cypress-cucumber-preprocessor'的声明文件”。显然,黄瓜预处理器没有(完全)安装?我已经运行了 npm install --save-dev cypress-cucumber-preprocessor,它是以下所有方法指定的:blog.knoldus.com/cypress-with-cucumber
    • 我错过了from,但那是另一回事。
    • 那行得通。但是,当我添加“on('file:preprocessor', cucumber())” 行时,cypress 返回:“TypeError: cypress_cucumber_preprocessor_1.default is not a function”。
    • 如果我删除 accisting 默认导入并使用您在上面给我的那个(无论如何它都未使用),我会抱怨“TS7006:参数'on'隐含地具有'any'类型。” “配置”也一样。我可以让 IntelliJ 从使用中推断参数类型,这消除了错误,但 cypress 仍然抱怨并拒绝加载。
    猜你喜欢
    • 2022-10-25
    • 1970-01-01
    • 2022-12-06
    • 1970-01-01
    • 2022-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多