【问题标题】:Exclude protractor files from ng test command从 ng test 命令中排除量角器文件
【发布时间】:2019-12-27 14:11:13
【问题描述】:

在我的项目中,我们有以 .spec.ts 结尾的单元测试文件和以 .prot.spec.ts 结尾的量角器测试用例。现在,当我运行命令“ng test”时,我的量角器文件被拾取,因为它也具有相同的扩展名(.spec.ts),但我不希望它们执行。我尝试在 tsconfig.json、tsconfig.app.json、test.js 中添加“排除”之类的属性,但它似乎不起作用。

我需要知道可以放置配置的确切位置,以便排除量角器文件。

请在下面找到截图:

tsConfig.spec.ts

test.js

tsconfig.ts

Error

【问题讨论】:

  • @Indragith :我们无法在 angular.json 中添加“排除”属性,它会给出以下错误。架构验证失败并出现以下错误:数据路径“”不应具有其他属性(排除)。
  • 您可以将量角器测试的名称更改为 prot.test.ts,然后让量角器配置文件指向 *.test.ts。那么 ng-test 应该只接受 karma 测试,而 ng-e2e 应该接受量角器测试。
  • @SankalanParajuli:是的,这是最后一个选项。谢谢!
  • @pritampanhale:如果我没记错的话,使用最新的 Angular cli 版本,您应该添加 codeCoverageExclude: ['specify the path here'] 而不是 codeCoverage: { exclude : [] }

标签: angular typescript protractor karma-jasmine


【解决方案1】:

在您的 test.js 中,更改上下文中的 glob

const context = require.context('./', true, /^((?!prot).)*\.spec.ts$/);

【讨论】:

    猜你喜欢
    • 2021-02-16
    • 2017-07-03
    • 2017-09-05
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    • 2017-12-11
    • 2014-02-26
    • 1970-01-01
    相关资源
    最近更新 更多