Use jest to mock electron in tests

Summary:
Replacing our custom electron-stubs transform with a mocked module.

This will now be the default impl for tests, and we can override it by mocking as needed.

Reviewed By: passy

Differential Revision: D17979659

fbshipit-source-id: a26994158d439fa7dc1ca38225294106fc4e1559
This commit is contained in:
John Knox
2019-10-18 10:06:29 -07:00
committed by Facebook Github Bot
parent 14dd792829
commit fdee0ef7b7
3 changed files with 32 additions and 6 deletions

View File

@@ -63,12 +63,8 @@ function transform({filename, options, src}) {
if (process.env.BUILD_HEADLESS) {
plugins.push(require('./electron-stubs.js'));
plugins.push(require('./electron-requires.js'));
} else if (options.isTestRunner) {
if (process.env.USE_ELECTRON_STUBS) {
plugins.push(require('./electron-stubs.js'));
}
} else {
}
if (!options.isTestRunner) {
// Replacing require statements with electronRequire to prevent metro from
// resolving them. electronRequire are resolved during runtime by electron.
// As the tests are not bundled by metro and run in @jest-runner/electron,