gpt4 book ai didi

typescript - 为 Cypress 指定 tsconfig.json 位置

转载 作者:行者123 更新时间:2023-12-04 11:16:42 25 4
gpt4 key购买 nike

我正在尝试使用带有 Typescript 的 Cypress,但 Cypress 找不到 tsconfig.json我为它创建的文件。我也有一个自定义的目录结构(因为我讨厌根目录中有一堆配置文件,所以我把它们放在一个配置目录中)。
项目目录结构

/
├── package.json
├── configs/
│ ├── cypress.json
├── src/
│ ├── cypress/
│ │ ├── tsconfig.json
Cypress 打开命令
//  package.json

"scripts": {
"cypress:open": "cypress open --config-file configs/cypress.json"
},
在上面的脚本中, --config-file flag 告诉 cypress cypress.json 的位置config 文件,这很棒,因为我可以将该文件放在任何我想要的地方。但是,现在我需要指示 Cypress 在哪里可以找到它 tsconfig.json文件。
/configs/cypress.json (告诉 Cypress cypress/ 目录在哪里)
{
"fixturesFolder": "src/cypress/fixtures",
"integrationFolder": "src/cypress/integration",
"pluginsFile": "src/cypress/plugins/index.js",
"screenshotsFolder": "src/cypress/screenshots",
"videosFolder": "src/cypress/videos",
"supportFile": "src/cypress/support/index.js"
}

// is there no option to set tsconfig.json path????
official documentation说只要把它放在 cypress/目录。根据文档,应该在 /cypress/tsconfig.json ,但在我的项目中它位于 /src/cypress/tsconfig.json .
这是我试图放置 tsconfig.json 的位置文件:
/src/cypress/tsconfig.json //Error: "Couldn't find tsconfig.json. tsconfig-paths will be skipped"

/src/tsconfig.json //Error: "Couldn't find tsconfig.json. tsconfig-paths will be skipped"

/cypress/tsconfig.json //Error: "Couldn't find tsconfig.json. tsconfig-paths will be skipped"

/tsconfig.json // Works!! But not where I want this file to live...
如何指示 Cypress 在哪里查找我希望它使用的 tsconf.json 文件? cypress.json中是否有选项?配置文件,或者我可以使用的 CLI 标志???
我不想用杂项配置文件弄乱我的项目根目录,而且我的项目和测试套件实际上有单独的 tsconfig 文件。显式设置文件路径会很棒。

最佳答案

虽然这不是您想听到的答案,tsconfig.json将目录标记为 typescript 项目的根目录,就像 package.json将目录标记为 node.js 项目的根目录。这些文件可帮助 IDE 等工具了解您的项目。
我认为你应该只考虑搬家 tsconfig.json当你开始把你的 package.json在其他一些文件夹中也是如此。
另见:https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

关于typescript - 为 Cypress 指定 tsconfig.json 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64141729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com