【问题标题】:include option for ng test is not workingng 测试的包含选项不起作用
【发布时间】:2020-07-08 07:46:57
【问题描述】:

我正在尝试使用 ng 测试使用 Karma 和 Jasmine 运行单元测试。当我发出以下命令时:

ng test --watch=false --code-coverage --main ./src/main/resources/public/scripts/xyz/workspace/commons/interceptors/mgr.ng.spec.ts

它没有任何问题。

当我尝试使用以下命令运行该目录中的所有脚本时:

ng test --watch=false --code-coverage --include=src/main/resources/public/scripts/xyz/workspace/commons/interceptors/*.ng.spec.ts

我收到以下错误:

Specified patterns: "src/main/resources/public/scripts/xyz/workspace/commons/interceptors/*.ng.spec.ts" did not match any spec files

知道这里发生了什么吗?我尝试了很多变体,但似乎 include 选项根本不起作用。

【问题讨论】:

    标签: angular typescript jasmine karma-jasmine karma-runner


    【解决方案1】:

    试试ng test --watch=false --code-coverage --include="src/main/resources/public/scripts/xyz/workspace/commons/interceptors/*.ng.spec.ts"

    如果你能发布你的项目结构也会很有帮助。

    【讨论】:

      【解决方案2】:

      以下是在特定文件夹及其所有子文件夹/子目录下运行测试文件的命令

      ng test --include='src/app/modulefolder/**/*.spec.ts'
      

      【讨论】:

        【解决方案3】:

        我不确定这是否受支持。

        这里有一个解决方案: https://github.com/angular/angular-cli/issues/3603#issuecomment-523794137

        【讨论】:

        • 感谢您的回答,但该链接中提供的解决方案抛出了“未处理的异常..”我尝试了:以下内容:ng test ./src/main/resources/public/scripts/xyz/workspace /commons/拦截器
        【解决方案4】:

        哦,您不需要在路径周围添加引号吗?另外,如果您愿意,您可以使用--include的其他方式@

        ng test --include relative_or_absolute_path_here

        或

        ng test --include="relative_or_absolute_path_here"

        https://angular.io/cli/test

        【讨论】:

          【解决方案5】:

          ng test --include=src/app/my-folder

          为我工作。没有引号。没有*。

          Per the angular docs,

          相对于工作区或项目根目录,要包含的文件的整体。 有两种特殊情况:

          • 当提供目录路径时,所有以“.spec.@(ts|tsx)”结尾的规范文件都将包括在内

          • 当提供了文件路径并且存在匹配的规范文件时,它将被包含进来

          注意,我在 Powershell 中进行了测试。在不同的操作系统/终端上可能需要转义序列和不同的斜线。

          【讨论】:

            猜你喜欢
            • 2015-05-06
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-03-07
            • 1970-01-01
            • 2017-03-11
            • 1970-01-01
            相关资源
            最近更新 更多