Error: cannot find module electron while testing by mocha and spectron in electron-compile app

Error: cannot find module electron while testing by mocha and spectron in electron-compile app

我尝试使用 electron-prebuilt-compile 包编写 electron 应用程序。我按照说明安装了它,所以在我的 devDependencies 中没有电子包。而不是这个,我有 electron-prebuild-compile 依赖。在使用 mocha + spectron 编写单元测试时,我的代码出现问题。 我有功能模块:

openLinkinExternalWindow( e ) {                                                                                                                                                                                                       
  shell.openExternal(this.link);
}

并且我在模块前面进行 shell 导入:

import { shell } from 'electron';

它在应用程序运行时有效,但是如果我想测试这个模块,出现错误:

Cannot find module 'electron'

我应该怎么做才能避免这个问题?

我使用了 electron-mocha 包而不是 mocha 并且它有效