如何解决赛普拉斯测试无法识别node_modules封装类型
我的(Typescript)应用程序的赛普拉斯测试无法识别已安装的软件包的类型。这是我的顶级目录结构:
cypress
node_modules
src
我的cypress/tsconfig.json
文件如下:
{
"compilerOptions": {
"strict": true,"baseUrl": "../node_modules","paths": {
"~/*": ["../src/*"]
},"jsx": "react","target": "es6","lib": ["es6","dom","es2017.string"],"types": ["cypress"]
},"include": ["**/*.ts"]
}
在我的一个规格文件中,我具有以下导入:
import * as faker from 'faker';
import { DeepPartial } from 'utility-types';
faker
的类型在DefinitelyTypes(@types/faker
)中定义,而utility-types
的类型作为*.d.ts
文件包含在该包中。 faker
导入没有问题,但是utility-types
导入给出了找不到模块'实用程序类型'或其对应的类型声明。错误。
我已经尝试将*.d.ts
文件从node_modules目录显式地包含到tsconfig.json
,compilerOptions.types
和compilerOptions.typeRoots
属性下的include
文件中,但是无济于事。
我还创建了如下的“假”(?)类型,以便进行编译:
declare module 'utility-types' {
export type DeepPartial<T> = {};
}
这允许应用程序进行编译,并且在运行时解决了程序包,因此问题似乎在于查找类型,而不是模块本身。
为什么赛普拉斯没有找到这些软件包的类型?
解决方法
您可以尝试将cur.execute("select format('%s,%s,%s','one','two','three') from foo where bar = %s",('baz',))
设置为moduleResolution
https://www.typescriptlang.org/docs/handbook/module-resolution.html#module-resolution-strategies
我尝试使用此配置导入node
:导入有效,并且测试运行正常
utility-types
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。