无法 运行 使用 firebase 在本地进行 mocha 测试

Unable to run mocha test locally with firebase

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

堆栈包括用于测试的 webpack、react、mocha + enzyme 以及用于 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 配置?

所以,我刚刚弄明白了。这似乎是如何加载测试的问题,导致 firebase 包以 "web" 模式加载,即使 mocha 测试过程正在 "node" 模式下构建......或类似的东西.

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

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