Hi,
long story short: Importing @forge/bridge breaks unit-tests. I seem to remember finding a topic about that issue, but couldn’t locate it anymore.
If this is a duplicate or it is already known, I apologise for the duplicate.
The import:
import {invoke} from '@forge/bridge'
The error:
Error: Cannot find module '@forge/bridge'
Complete Require Stack
Require stack:
- C:\Users\daniel.kleissl\Documents\razzfazz\repos\RnR\plugin\static\wizard\test\views\wizardView.spec.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\daniel.kleissl\Documents\razzfazz\repos\RnR\plugin\static\wizard\test\views\/wizardView.spec.js:6:1)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Module._compile (C:\Users\daniel.kleissl\Documents\razzfazz\repos\RnR\plugin\static\wizard\node_modules\pirates\lib\index.js:136:24)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.newLoader [as .js] (C:\Users\daniel.kleissl\Documents\razzfazz\repos\RnR\plugin\static\wizard\node_modules\pirates\lib\index.js:141:7)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:190:29)
at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
at async Promise.all (index 0)
at ESMLoader.import (node:internal/modules/esm/loader:281:24)
at importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
at formattedImport (C:\Users\daniel.kleissl\Documents\razzfazz\repos\RnR\plugin\static\wizard\node_modules\mocha\lib\nodejs\esm-utils.js:9:14)
at Object.exports.requireOrImport (C:\Users\daniel.kleissl\Documents\razzfazz\repos\RnR\plugin\static\wizard\node_modules\mocha\lib\nodejs\esm-utils.js:42:28)
at Object.exports.loadFilesAsync (C:\Users\daniel.kleissl\Documents\razzfazz\repos\RnR\plugin\static\wizard\node_modules\mocha\lib\nodejs\esm-utils.js:100:20)
at singleRun (C:\Users\daniel.kleissl\Documents\razzfazz\repos\RnR\plugin\static\wizard\node_modules\mocha\lib\cli\run-helpers.js:125:3)
at Object.exports.handler (C:\Users\daniel.kleissl\Documents\razzfazz\repos\RnR\plugin\static\wizard\node_modules\mocha\lib\cli\run.js:370:5)
At the moment this means having to work around with programming patterns to avoid importing any file or module that directly references the bridge, which makes writing tests rather inconvenient at times.
We use mocha, chai and sinon as test stack. As far as I am aware there is no way to mock modules BEFORE import using this stack similar to jest’s mock modules. If any of you know another workaround I did not think of I would be grateful.
Also, If this bug is not already known, it would be great if this could be fixed in future versions.
Regards,
Daniel