cannot run tests when building embroider
Opened this issue · 7 comments
I was able to sucesfully build our app with embroider, but could not run the test suite:
~/app $ ember test -r dot
Environment: test
Building into /private/var/folders/r6/1tb0c_rn22xdhm39d62y6rfh0000gn/T/embroider/dd8397
WARNING: Your build is slower because some babel plugins are non-serializable
cleaning up...
Build Error (PackagerRunner) in node_modules/ember-mocha/mocha/index.js:73
/private/var/folders/r6/1tb0c_rn22xdhm39d62y6rfh0000gn/T/embroider/dd8397/node_modules/ember-mocha/mocha/index.js: Export 'mocha' is not defined (73:2)
71 |
72 | export {
> 73 | mocha,
| ^
74 | describe,
75 | context,
76 | it,
I think this global reexport pattern is not supported with embroider. This seems similar to invalid rexports. See ef4's comment here embroider-build/embroider#169 (comment).
Couple questions:
- do we need this pattern for embroider applications? If not, can we disable it?
- is there a proper way to support this reexporting for embroider? perhaps @ef4 could answer?
I would expect that pattern to already work.
This code gets noticed by embroider and causes the actual mocha library to still be included in vendor.js. That should presumably set window.mocha
.
So the places to look to debug this are:
- Is mocha in vendor.js?
- When it runs, does it notice that it's supposed to set
window.mocha
? Some libraries try to do detection to decide whether they should set globals vs use AMD, etc. If embroider is working right, this code should run under exactly the same conditions are normal ember-cli and do the same things. - I notice that ember-mocha's
treeForAddonTestSupport
is not callingsuper
. Usually that is because it's trying to renamespace its files. In this case though, that's probably vestigial from when the package had a different name (if I recall it used to be ember-cli-mocha?). But in any case, if renaming shenanigans are detected, Embroider will update its babel rules to know about them. Please grab_babel_config_.js
out of the build directory (the one embroider prints as "Building into...") and look for any places that mention mocha and share them.
Ah, interesting.
- I don't see vendor.js in the temporary build directory or
dist/
because I don't think the build command completes successfully. I triedember build -e test
and it errored in the same way above. Am I missing another place to look / isolate the build using theSTAGE
env vars? - If I can get it building after linking ember-mocha and tweaking some lines, I'll see.
- I only found one mention of mocha in
_babel_config.js
. Here is that relevant snippet:
[
"my-app/node_modules/@embroider/core/src/babel-plugin-adjust-imports.js",
{
"rename": {
"@babel/runtime": "ember-cli-babel/@babel/runtime",
"moment": "ember-cli-moment-shim",
"mocha": "ember-mocha/mocha",
"ember-test-helpers": "@ember/test-helpers/ember-test-helpers",
"@babel-decorators/babel-transforms": "@ember-decorators/babel-transforms"
},
I can build the project successfully by linking ember-mocha as of 54a4c9c. Applying super
in treeForAddonTestSupport seemed to have the same effect. My test suite is failing on older ember-mocha API not being found (setupModelTest
), so I'll try to isolate this in a new application.
I don't see vendor.js in the temporary build directory or dist/ because I don't think the build command completes successfully.
Oh yes. In the temporary build directory, look for node_modules/@embroider/synthesized-vendor
. It should contain the mocha js file, and it should also mention that file in its package.json under implicit-scripts
.
I did see the mocha
package there. Here is the revelant snippet from the synthesized-vendor
package.json:
"implicit-test-scripts": [
"./vendor/ember/ember-testing.js",
"./vendor/monkey-patches.js",
"./vendor/mocha/mocha.js",
"./vendor/ember-mocha/mocha-configuration.js",
"./vendor/ember-mocha/ember-mocha-adapter.js",
"./vendor/ember-mocha/test-loader.js"
],
The error only seems to appear in ember-mocha@0.14. You can see in the following repo. I will be upgrading our application to ember-mocha@0.15 anyways, so I will close this issue because I don't see much value to supporting older versions of ember-mocha + embroider.
Thanks, I can see now why the earlier version of ember-mocha wasn't working. It did:
/* global mocha */
export { mocha };
I don't think the ES module spec supports that. Even if a global mocha
binding is available in the ambient scope, you can't reexport it like that. Instead you'd need to make a local binding for it first.