首页 > 解决方案 > 如何从 tsdoc / typedoc 中正确排除测试文件

问题描述

我正在测试一些不同的文档引擎,我想为我们的大型项目尝试 typedoc。我们在整个项目中都有各种测试文件(somefile.test.ts或)。someotherfile.test.tsx我正在努力让 typedoc 忽略这些文件。我做了npm i -D typedoc,然后在我的 tsconfig.json

{
  "compilerOptions": {
    "configOptions": "some_options"
  },
  "include": ["src"],
  "typedocOptions": {
    "out": "docs",
    "entryPoints": "src/index.tsx",
    "exclude": [
      "**/*.test.ts*",
      "**/*.test.tsx*"
    ]
  }
}

然后我运行我的 npm 命令"tsdoc": "typedoc"- npm run tsdoc。Typedoc 遍历我的文件并在我的测试文件中发现大量的打字稿 linting 错误,因此它无法运行。(我们最近更新了我们的@types/jest, 所以 eslint 和 ts 抱怨Property 'toEqual' does not exist on type 'Assertion'Property 'toMatchSnapshot' does not exist on type 'Assertion'.eslint 和 ts 抱怨这些事情,但这并不能阻止测试运行。但是我的问题typedocOptions是它没有正确忽略这些文件?

标签: typescriptjsdocdocumentation-generationtypedoctsdoc

解决方案


这完全是在黑暗中拍摄,但我猜测它会在它尝试生成文档之前typedoc运行,以创建文件之间的链接。如果/给出错误tsc,它可能无法检查要排除的文件。tsceslint

我建议调查一下为什么 Jest 升级会搞砸事情。一旦编译器/检查错误消失,我想typedoc会合作。您也可以告诉tsc/eslint忽略这些文件,但我想不编译测试文件会导致进一步的问题。


推荐阅读