ember-auto-import
ember-auto-import copied to clipboard
`instanceof` fails in classic mode
I'm rewriting ember-command
as v2 addon. The check I have there to test for links are:
if (something instanceof Link) { ... }
if (something instanceof LinkCommand) { ... }
To ensure embroider compatibility I'm using ember-try for with embroider scenarios. By default, when starting locally, it uses classic mode.
Now I've realized the checks above are failing in classic mode. As these are two different imports under the hood for Link
and LinkCommand
between the transpiled addon and the host app, thus the tests are failing. My theory is, due to the different locations and two different memory pointers, that's why the checks fail.
My workaround was to use a symbol, attach it to the LinkCommand
and check for the existence of the symbol... it is failing, too (I think for the same reason).
When starting the test app in embroider mode: EMBROIDER_TEST_SETUP_FORCE='embroider' ember s
the checks work as expected.
Do you have a PR where this is easily reproducible?
Potentially related:
- https://github.com/embroider-build/ember-auto-import/issues/503
Here is a PR: https://github.com/gossi/ember-command/pull/22
But I think, I failed on CI setup for github, so must be done locally:
- Checkout
-
pnpm install
-
pnpm --filter ember-command run build
-
cd test-app/ && ember s
Notes:
- The last test that is failing is:
Rendering | Component | <CommandElement>: invoke command
- When starting with
EMBROIDER_TEST_SETUP_FORCE='embroider' ember s
that test will pass. - The code in question: https://github.com/gossi/ember-command/blob/80b753cef18b8514f4d4ea89da0583f4724dec93/ember-command/src/-private/instance.ts#L137
Also, I left a comment to this issue within the code to see when I left workarounds. Search for https://github.com/embroider-build/ember-auto-import/issues/588
inside the code.
My workaround: duck-typing and __***__
properties instead of symbols 😞
@NullVoxPopuli that is exactly the issue. The module graph essentially creates two different copies of the module so when you import something from a test file it can never be ===
something that is imported in an app 😞
I am trying to convert a legacy addon into a v2 addon in a project using ember-auto-import and I think I am running into this as well
If the issue here is indeed related to https://github.com/embroider-build/ember-auto-import/issues/503, then I think we can close this now, as the bug has been fixed a wile ago! Can someone confirm?
I took recent main branch from ember-command
today with [email protected]
to run the try exam with the [email protected]
and that worked.
I think, this means, this can be closed. Thanks a lot everybody :)