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

[QUESTION] Test extended built-in adapters #77

Closed
sly7-7 opened this issue Apr 11, 2016 · 8 comments
Closed

[QUESTION] Test extended built-in adapters #77

sly7-7 opened this issue Apr 11, 2016 · 8 comments

Comments

@sly7-7
Copy link
Contributor

sly7-7 commented Apr 11, 2016

I cleanup my own Piwik adapter using the built-in one. I just have some customization for the adapter (like sending custom dimensions).

I have define a app/metrics-adapters/piwik.js, like this:

import PiwikAdapter from 'ember-metrics/metrics-adapters/piwik';

export default PiwikAdapter.extend({
  identify(options = {}) {
    this._super(...arguments);
    window._paq.push(['setCustomDimension', 1, options.organizationName]);
    window._paq.push(['setCustomDimension', 2, options.userId]);
  }
});

So far, so good, but when I wanted to test it, I can"t find a way to resolve ember-metrics/metrics-adapters/piwik.

In the needs property of my unit test, I tried to add a reference to ember-metrics@metrics-adapter:piwik with no success, I encounter this error: Attempting to register an unknown factory: 'ember-metrics@metrics-adapter:piwik'.
When referencing ember-metrics@metrics-adapter:base, it seems like the BaseAdapter is beeing correctly resolved.

So my question: How can I test an extended adapter ?

@poteto
Copy link
Collaborator

poteto commented Apr 11, 2016

You need to import the one from your app:

needs: ['metrics-adapter:piwik']

the ember-metrics@... form will try to resolve it on the addon's namespace instead.

@sly7-7
Copy link
Contributor Author

sly7-7 commented Apr 11, 2016

@poteto Thank you for your answer. Actually, I'm unit testing this adapter, so I thought it was not a need, but the subject of the module. I will try your suggestion tomorrow and let you know if that works.

@sly7-7
Copy link
Contributor Author

sly7-7 commented Apr 12, 2016

I tried, but it does not work. Here is the adapter:

//app/metrics-adapters/piwik.js
import PiwikAdapter from 'ember-metrics/metrics-adapters/piwik';

export default PiwikAdapter.extend({
  identify(options = {}) {
    this._super(...arguments);
    window._paq.push(['setCustomDimension', 1, options.organizationName]);
    window._paq.push(['setCustomDimension', 2, options.userId]);
  }
});

and the test, using ember-mocha

/* jshint expr:true */
import { expect } from 'chai';
import {
  beforeEach
} from 'mocha';
import {
  describeModule,
  it
} from 'ember-mocha';

describeModule(
  'metrics-adapter:piwik',
  'PiwikAdapter',
  {
    needs: ['metrics-adapter:piwik']
  },
  function() {
    let config;

    beforeEach(function () {
      config = { piwikUrl: 'someUrl', siteId: 42 };
    });

    it('exists', function() {
      var adapter = this.subject({ config });
      expect(adapter).to.be.ok;
    });
  }
);

The following error is thrown:
Could not find moduleember-metrics/metrics-adapters/piwikimported fromfrontend/metrics-adapters/piwik`

It seemed to me that I should add the dependency to the ember-metrics piwik adapter, but if I do that I have the above error, ie Attempting to register an unknown factory:ember-metrics@metrics-adapter:piwik`

@poteto
Copy link
Collaborator

poteto commented Apr 30, 2016

Sorry about the delay! Can you share what your config / env looks like?

@sly7-7
Copy link
Contributor Author

sly7-7 commented May 6, 2016

Hi, I'm sorry for the delay. I don't know when I will go back to work (kind of burn out for the moment), but for sure, as soon as I can I will try to keep this up to date

@Leooo
Copy link
Contributor

Leooo commented Jul 20, 2017

@poteto, having the same problem while unit testing a metrics-adapter that I export from an addon. I added ember-metrics in both the dependencies and devDependencies of my addon's package.json, and tried:

moduleFor('metrics-adapter:google-analytics', 'google-analytics metrics-adapter', {
  needs: [
    'service:logger',
    'service:configService',
    'service:metrics',
    'ember-metrics@metrics-adapter:google-analytics'
  ]
});

Which fails with Attempting to register an unknown factory: 'ember-metrics@metrics-adapter:google-analytics'

while removing the needs: ember-metrics@metrics-adapter:google-analytics line leads to:

Could not find module `ember-metrics/metrics-adapters/google-analytics` imported from `ember-commons/metrics-adapters/google-analytics`

my metrics-adapter itself starts with:

mport GoogleAnalyticsAdapter from 'ember-metrics/metrics-adapters/google-analytics';
import Ember from 'ember';
const {inject, copy, computed, Logger} = Ember;

export default GoogleAnalyticsAdapter.extend({
//..

and works well except for the failing test

@Leooo
Copy link
Contributor

Leooo commented Jul 20, 2017

@poteto, forget it it was as simple as setting the metricsAdapters ENV variable in my dummy app config, thanks

@sly7-7
Copy link
Contributor Author

sly7-7 commented Mar 9, 2018

@poteto I'm sorry letting this one so long. If you still interrested I could work on, otherwise I will juste close. Your call 😺

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

4 participants