【问题标题】:how can i run a specific angular spec test file in NX workspace?如何在 NX 工作区中运行特定的角度规格测试文件?
【发布时间】:2018-07-28 01:57:38
【问题描述】:

有没有办法在 Nx 工作空间中运行特定的角度规格测试文件?

最近我将我的 Angular 4 cli 应用程序移到了 Nx 工作空间。以前我使用 fdescribe 来实现此功能。
所以请建议我在 Nx 工作空间中是否有任何选项可以执行此操作?

【问题讨论】:

    标签: angular angular-cli karma-jasmine ngrx nrwl


    【解决方案1】:

    这对我有用

     nx test --test-file example.spec.ts
    

    【讨论】:

    • 您甚至可以更具体并添加 --test-name-pattern=regex 以针对该文件中的特定测试。
    • 您需要指定项目名称,(工作区可能有多个项目)。就像这样:nx test projectName --test-file example.spec.ts
    【解决方案2】:

    这对我有用:

    nx run <project-name>:test --testFile=<file-name>
    

    【讨论】:

      【解决方案3】:

      这与我们对单个应用执行此操作的方式相同,但请注意您应该使用 --app='your-app-name' 和 ng test,因此最终命令如下所示,

      ng test --app='app1'
      

      【讨论】:

      • 如何测试它的库?
      • Libs 不能单独测试,我们可以在 lib 的 spec 文件中添加 fdescribe 并在使用该 lib 的应用程序上运行测试。
      • 得到了解决方案。我必须添加一个app。 Angular cli 需要 main.ts。通过使用该库的应用程序,我们可以执行该库的测试
      【解决方案4】:

      对我来说,watch 标签起到了神奇的作用:

      ng test --watch

      在运行所有内容之前,它为我提供了以下选项:

       › Press a to run all tests.
       › Press f to run only failed tests.
       › Press p to filter by a filename regex pattern.
       › Press t to filter by a test name regex pattern.
       › Press q to quit watch mode.
       › Press Enter to trigger a test run.
      

      选择 'p' 选项并输入 xy.service.spec.ts 效果很好。

      注意:我使用的不是最新版本 ("@nrwl/nx": "7.4.0")

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-06
        • 2022-08-14
        • 1970-01-01
        • 2022-08-15
        • 2013-10-29
        • 1970-01-01
        • 2021-12-05
        • 2021-08-22
        相关资源
        最近更新 更多