【问题标题】:Writing Cypress Tasks in Typescript在 Typescript 中编写 Cypress 任务
【发布时间】:2019-07-29 14:51:09
【问题描述】:

有没有一种方法可以与 Cypress Typescript `预处理器模式一起在 Typescript 中编写任务?

这里的例子使用了JavaScript插件文件:

https://github.com/cypress-io/cypress-example-recipes/tree/master/examples/preprocessors__typescript-webpack

具体

https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/preprocessors__typescript-webpack/cypress/plugins/index.js

不过,这似乎有点鸡和蛋的问题。

经过大量测试,我找不到一种方法来编写 Typescript 插件并将其包含到 JavaScript 插件文件中。无需先通过tsc 编译文件,然后再打开 cypress。

Gitter 中提到使用ts-node/register 来做,但我想不通。

https://gitter.im/cypress-io/cypress/archives/2019/04/08

【问题讨论】:

  • 我也找不到任何方法 :( 你有任何运气或解决方法吗?我能够实现的更多是将 plugins/index.js 文件视为 ts 与 //@ts-check 和JSDoc

标签: typescript cypress


【解决方案1】:

您应该从安装节点类型定义开始:

npm install --save-dev @types/node

从那里,您可以继续将所有 require 语句替换为导入,将所有 export.module 替换为打字稿导出等。由于这都是 Node,您应该能够像迁移任何普通文件一样迁移赛普拉斯任务文件NodeJS 文件。

最好的方法是从某个目录开始,然后从那里开始,不断修复构建错误。

【讨论】:

    猜你喜欢
    • 2017-01-27
    • 2022-11-26
    • 2017-12-13
    • 1970-01-01
    • 2015-11-29
    • 2015-12-31
    • 1970-01-01
    • 2015-09-04
    • 1970-01-01
    相关资源
    最近更新 更多