【问题标题】:Mocha & Typescript and recursively loadingMocha & Typescript 和递归加载
【发布时间】:2018-05-06 22:22:58
【问题描述】:

使用这个脚本:

"test": "./node_modules/mocha/bin/mocha --recursive --require ts-node/register ./test/**/*.spec.ts --opts ./test/mocha.opts",

我尝试在树中加载一些测试文件:

.
├── controllers
│   ├── admin
│   │   └── users.spec.ts
│   ├── authentications.spec.ts

但是,users.spec.ts 测试文件不会被加载,但 authentications.spec.ts 会。

我的 mocha.opts 文件如下所示:

--timeout 5000

我也尝试过删除--recursive 标志,只是有一个glob,但它不起作用。

我不知道问题出在ts-node 还是mocha

有什么想法吗?

【问题讨论】:

  • 我也有同样的问题。使用 ./test/**/**/*.spec.ts(两个 ** 路径)允许 mocha 找到并运行较低级别的测试(在您的情况下为 users.spec.ts),但代价是它不再找到较高级别的测试。
  • ./test/**/*.spec.ts --opts 将解析包含 .spec.ts 的文件夹 ./test/**/*.spec.ts --opts 将解析 test/ --> folder 中的文件
  • 尝试用单引号 './test/**/**/*.spec.ts' source 包裹路径

标签: typescript mocha.js typescript-typings typescript2.0


【解决方案1】:

您似乎也问了这个问题here,并得到了一个很好的答案:引用 glob 参数,以便它由 mocha(递归)而不是 shell(非递归)扩展:

"test": "mocha --require ts-node/register 'test/**/*.spec.ts' --opts ./test/mocha.opts"

【讨论】:

    【解决方案2】:

    这里似乎确实有一个错误,无论是 mocha 对--recursive 的处理还是与ts-node 的一些交互我不知道。

    您可以通过使用以下命令告诉 mocha 专门查找嵌套更深的文件夹来解决此问题:

    mocha --recursive --require ts-node/register ./test/**/*.spec.ts ./test/**/**/*.spec.ts --opts ./test/mocha.opts
    

    例如,告诉它专门查看子 (/**/) 和孙 (/**/**/) 目录。

    【讨论】:

      【解决方案3】:

      对我来说,问题实际上是我在测试中有一个only

      【讨论】:

        猜你喜欢
        • 2014-09-08
        • 2021-07-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-30
        • 2018-06-18
        • 2023-03-02
        • 2016-12-13
        相关资源
        最近更新 更多