Absolute paths lead to "Error: Cannot find module" since introduction of native TypeScript support in Cypress@4.4.0

Absolute paths lead to "Error: Cannot find module" since introduction of native TypeScript support in Cypress@4.4.0

项目

我有一个包含大约 100 个 ui 测试的网络应用程序,我想摆脱 cypress-webpack-preprocessor,因为在 Cypress@4.4.0 中原生添加了 typescript 支持。我已更新到最新版本的 Cypress,但无法再在我的测试中使用绝对路径 - 我想这应该是可能的。

问题

虽然这有效

import { DateFormatter } from "./../../../../src/util/formatter/date-formatter";

这不是

import { DateFormatter } from "src/util/formatter/date-formatter";

无论我在 tsconfig.json 中更改什么,它总是显示此错误消息

Error: Cannot find module '<file in my project>' from '<path to my test file>'

可重现的例子

为了测试这一点,我遵循了最小 Cypress - TypeScript example until the section Tip: Sharing code between UI and test 的说明,它工作得很好,但如果我用绝对路径替换相对路径,它就不再工作了。

这是一个github non-working example

编辑:进一步研究

我发现这个 cypress 问题 typescript compilerOptions not reflected and this comment 表明 cypress 忽略了 tsconfig.json complierOptions 因此无法添加 baseUrlpaths 选项。

编辑

已在 Cypress@5.0.0

中修复

这实际上是 Cypress 中的一个错误,很快就会根据这个 comment

修复

A user's tsconfig.json is not loaded by Cypress. This is covered by this issue and is being addressed by this PR, which will be released in v5.0 in the near future. [...] it will fix any issues with baseUrl/paths config.