【问题标题】:Why is Mocha not working with Yarn Berry?为什么 Mocha 不与 Yarn Berry 合作?
【发布时间】:2021-09-25 04:12:12
【问题描述】:

我正在尝试使用 mocha 进行一个非常简单的测试(没有配置文件,没有其他标志,只有 mochayarn2testee.js 文件),但它总是给我 0 passing。见鬼,它甚至不会运行任何文件!

// testee.js

console.log('test') // No output

describe('something', () => {
    it('Should run', () => {
        console.log('test 2') // No output either
    })
})
$ yarn mocha testee.js

  0 passing (1ms)

我正在使用的工具:

  • 摩卡9.0.2
  • Yarn Berry 2.4.2

Yarn 2 不支持 mocha 吗?我应该使用其他东西吗?我总是将 mocha 用于我的所有测试文件,如果真的是这样的话,也许是时候迁移了。

注意:我尝试使用 yarn 1 并且它完美无缺。另外,Mocha 找到了testee.js 文件,否则它会给我not found 错误而不是0 passing

【问题讨论】:

标签: mocha.js yarnpkg yarnpkg-v2 yarn-v2


【解决方案1】:

Mocha 9 使用 ESM 优先方法进行导入 https://github.com/mochajs/mocha/releases/tag/v9.0.0

带有默认 PnP 安装方案的 Yarn 2+ 尚不支持 ESM,因为 Node API 缺少一些功能来实现这一点

目前,如果你想使用 Mocha 9,你必须使用 node_modules 安装方案和 Yarn 2+,将你的配置更改为: .yarnrc.yml

nodeLinker: node-modules
...

并运行 yarn 以使用 node_modules 重新安装您的项目

您可以在此处跟踪 ESM 对 Yarn PnP 的支持: https://github.com/yarnpkg/berry/issues/638

【讨论】:

    猜你喜欢
    • 2020-11-09
    • 2021-08-03
    • 2020-12-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-12
    • 1970-01-01
    • 2021-09-05
    • 2022-08-20
    相关资源
    最近更新 更多