【问题标题】:Unable to run mocha test locally with firebase无法使用 firebase 在本地运行 mocha 测试
【发布时间】:2019-01-30 20:49:50
【问题描述】:

我正在开发一个基于反应的前端应用程序,我正在使用 mocha / 酶进行单元测试。

堆栈包括用于测试的 webpack、react、mocha + 酶,以及用于 auth / db / 等的 firebase。

当我尝试运行 npm test 时,由于 firebase 出现以下错误:

WEBPACK  Compiled successfully in 3412ms

 MOCHA  Testing...

 RUNTIME EXCEPTION  Exception occurred while loading your tests

TypeError: Cannot read property 'stringify' of undefined
    at Module.eval (webpack:///./node_modules/@firebase/webchannel-wrapper/dist/index.esm.js?:31:308)
    at eval (webpack:///./node_modules/@firebase/webchannel-wrapper/dist/index.esm.js?:136:30)
    ...

npm ERR! Test failed.  See above for more details.

什么可能导致此错误?这在我导入 firebase 之前没有发生。有没有我应该调整的 webpack 配置?

【问题讨论】:

  • 我对 vue + mocha-webpack 有同样的问题。
  • 如果你弄清楚了,一定要告诉我,这让我发疯。
  • vue + mocha + webpack 也有同样的问题,有什么消息吗?

标签: reactjs firebase webpack mocha.js


【解决方案1】:

所以,我刚刚想通了。这似乎是如何加载测试的问题,导致 firebase 包以“web”模式加载,即使 mocha 测试过程正在以“节点”模式构建......或类似的东西。

无论如何,这是帮助我解决此问题的链接:https://github.com/firebase/firebase-js-sdk/issues/1455#issuecomment-455712500

基本上,捆绑时忽略节点模块(特别是 firebase)。

【讨论】:

    猜你喜欢
    • 2023-03-23
    • 2020-09-05
    • 2018-10-22
    • 1970-01-01
    • 2019-12-03
    • 1970-01-01
    • 1970-01-01
    • 2021-05-18
    • 2018-09-26
    相关资源
    最近更新 更多