fix(core): silent failures when linking forge dependencies in tests - #3219
Conversation
| "lint:fix": "prettier --write .", | ||
| "link:prepare": "lerna exec -- node ../../../tools/silent.js yarn link --link-folder ../../../.links --silent --no-bin-links", | ||
| "link:prepare": "lerna exec -- yarn link --silent --no-bin-links --link-folder ../../../.links", | ||
| "link:remove": "lerna exec -- yarn unlink --silent --no-bin-links --link-folder ../../../.links", |
There was a problem hiding this comment.
Added this script to help remove links in after mocha hooks.
| for (const packageName of Object.keys(packageJson.devDependencies)) { | ||
| if (packageName.startsWith('@electron-forge/')) { | ||
| if (task) task.output = `${packageManager} link --link-folder ${linkFolder} ${packageName}`; | ||
| await yarnOrNpmSpawn(['link', '--link-folder', linkFolder, packageName], { |
| task: async (_, task) => { | ||
| await initLink(dir, task); | ||
| }, | ||
| exitOnError: true, |
There was a problem hiding this comment.
Separated the linking task, and made it exitOnError: true so it no longer silently fails in tests. It will only run when LINK_FORGE_DEPENDENCIES_ON_INIT is truthy.
erickzhao
left a comment
There was a problem hiding this comment.
Small note: it seems like the new yarn link:prepare command yields a lot of warnings if you run it twice in a row. Looks like running yarn link:remove between runs fixes that.
Not sure if that's expected behaviour but it used to just pass if you ran it consecutively.
@erickzhao Thanks for catching that 🙏 ^_^ I fixed and reintroduced the |

Summarize your changes:
When I was trying to debug another problem in a PR by @caoxiemeihao (#3178), I noticed we were getting silent errors when it came to linking forge dependencies in tests involving
api.init().This PR fixes the linking of local forge dependencies in our tests that use
api.init.How does this PR help?
api.init. For example, if changes are made across multiple forge packages, and if package linking silently fails in those related tests, then those tests are not properly testing changes that were made, and they're instead testing already-published packages, which makes them incorrect.