Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setupBrowserFakes doesn't work if your service injections are namespaced #420

Open
elwayman02 opened this issue Sep 28, 2024 · 2 comments
Open

Comments

@elwayman02
Copy link

In the current Ember world where we don't yet have a specific pattern for importing a service class and injecting it directly, it's a common practice to properly namespace service injections so you know where they're coming from. Since many addons provide services that may have duplicate names, this is the only way to ensure you're using the service instance you expected to inject.

However, the way setupBrowserFakes is written doesn't account for this possibility, causing test mocking to fail.

Given the following service injection:

import { type NavigatorService } from 'ember-browser-services/types';

// ...

@service('ember-browser-services@browser/navigator')
declare navigator: NavigatorService;

setupBrowserFakes will not correctly replace the proxy values, because it registers the browser fakes to browser/navigator rather than ember-browser-services@browser/navigator (and so on for the other services).

This can be seen here: https://github.com/CrowdStrike/ember-browser-services/blob/main/ember-browser-services/src/test-support/index.ts#L39-L66

We need to devise a way to support both injection patterns within this addon's test-support.

@NullVoxPopuli
Copy link
Contributor

it's a common practice to properly namespace service injections

via @? is that supported by ember? (like, would it work in embroider/webpack/vite?)
are there docs or an RFC on this?

@ef4
Copy link

ef4 commented Sep 29, 2024

The @ doesn't work under embroider with staticAddonTrees enabled (which will be a default in the next major). I wouldn't recommend anybody use it.

I appreciate the desire to make it clearer where a service is coming from but that needs to happen via a real import, like in ember-polaris-service. Otherwise you're just making the "Ember apps are hard to build and optimize because they don't use real imports" problem worse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants