I have installed the jjabrams ESA and wanted to get that in place before actually wiring it up to my OAuth based backend. With the use of the demo-app it wasn't too hard but I am getting two extraneous errors in my unit tests that appear to map back to ESA, they're both similar code blocks:
application-route-mixin.js
_mapSessionEventsToActions: Ember.on('init', function() {
Ember.A([
['authenticationSucceeded', 'sessionAuthenticated'],
['invalidationSucceeded', 'sessionInvalidated']
]).forEach(([event, method]) => {
this.get('session').on(event, Ember.run.bind(this, () => {
this[method](...arguments);
}));
});
}),
addon/services/session.js
_forwardSessionEvents: on('init', function() {
Ember.A([
'authenticationSucceeded',
'invalidationSucceeded'
]).forEach((event) => {
this.get('session').on(event, () => {
this.trigger(event, ...arguments);
});
});
}),
In both cases, the this.get('session') seems to resolve to an undefined object. In a project with 200 or so unit tests I only get one failure for each. The first one comes from the route/application.js where I've mixed in the ApplicationRouteMixin just like your demo-app. The other one is a bit more bizarre considering the error comes from a "it renders" test of a Component which _does not_ inject the session service.
Have you injected the service into the route?
session: Ember.inject.service()
The session used to be injected into everything automatically, but now needs to be done manually (to be in line with other services)
I haven't injected anywhere yet. Does it need to be injected in certain places?
My cunning strategy was to get this in place without deprecations and then come back and wire it up once I had all other deprecations removed.
Anywhere you're accessing this.get("session") you'll need to have injected it into that route/controller.
… although if you're using the mixins they do that for you
yes but I'm never accessing session ... it's just the ESA mixin code. :)
Yeah I got myself confused, I mis-read and thought that code you pasted in was from your app!
So for instance my route/application.js is just:
import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
export default Ember.Route.extend(ApplicationRouteMixin,{
session: Ember.inject.service()
});
where I didn't have the session injection initially -- because the demo app does not -- but I thought maybe it somehow needs it. In both cases though I get the same error.
You don't have to mixin the session service manually as the mixins should do that for you. Did you git clean -dfx?
Yeah the service addition was desperation. :8ball:
WRT to git clean ... I hadn't considered doing this although I did clear out node_modules and bower_modules recently as part of the CLI upgrade.
Just tried git clean and still getting the same results.
please provide some more info - package.json, bower.json, ESA revision, config/environment.js…
here's all three: gist
Run npm update ember-simple-auth to make suer you have the latest code.
`import Session from 'ember-simple-auth/session'`
`import EphemeralStore from 'ember-simple-auth/stores/ephemeral'`
moduleFor 'route:application', 'ApplicationRoute',
needs: ['service:session']
setup: ->
@container.register 'session:main', Session
@container.injection 'service:session', 'session', 'session:main'
@container.register 'session-store:ephemeral', EphemeralStore
@container.injection 'session:main', 'store', 'session-store:ephemeral'
worked for me. it is needed because the session service currently isn't fully migrated to a service and internally still depends on the old session.
@ssendev: the session service is fully migrated to a service - the dependency on the old session isn't going away.
This should be fixed in the latest version of the jj-abrams branch - please reopen if the problem persists.
Hi,
I've just encountered this issue, but I'm trying to setup integration test for component like this:
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import simpleAuthInitializer from '../../initializers/ember-simple-auth';
moduleForComponent('some-component', 'Integration | Component | some component', {
integration: true,
setup() {
simpleAuthInitializer.initialize(this.container);
}
});
test('it renders', function(assert) {
assert.expect(1);
this.render(hbs`{{some-component}}`);
assert.ok(true);
});
I'm hitting this when trying to integration test components: a minimal test case is ember g component-test main-navigation in the dummy app. :smile: So the component has its session injected correctly.
What setup is required for an integration test vs unit test?

@ibroadfo: check the acceptance tests in the dummy app
the ESA helpers seem to require an actual application to have been started, but this doesn't occur in component integration tests.
it's possible that integration tests are the wrong level to be trying to test auth-related stuff on, i guess?
The test helpers are for acceptance tests really. For other kinds of tests I'd probably stub the session.
This issue still occurs on a vanilla ember-cli app when adding the ApplicationRouteMixin to application route; on latest jj-abrams branch.
@bttf: please provide more info on what's actually failing as well as your package.json, bower.json, config/environment.js.
not ok 7 PhantomJS 1.9 - Unit | Route | application: it exists
---
actual: >
null
message: >
Died on test #1 at http://localhost:7357/assets/test-support.js:2934
at test (http://localhost:7357/assets/test-support.js:1826)
at http://localhost:7357/assets/shiiite.js:379
at http://localhost:7357/assets/vendor.js:150
at tryFinally (http://localhost:7357/assets/vendor.js:30)
at http://localhost:7357/assets/vendor.js:156
at http://localhost:7357/assets/test-loader.js:29
at http://localhost:7357/assets/test-loader.js:21
at http://localhost:7357/assets/test-loader.js:40
at http://localhost:7357/assets/test-support.js:6656: 'undefined' is not an object (evaluating '_this.get('session').on')
Log: |
...
Gist here: https://gist.github.com/bttf/85e0fff9c06326ee5f07
Steps to reproduce:
ember new test-app && cd test-appApplicationRouteMixin to application routeAlso tried with ember v2.1 with same results
@bttf: add needs ['service:session'] to the test. As stated above, the test helpers are really for integration tests not unit tests.
Oops, forgot to include the needs dependency. Did that though; still receiving the same error as above.
I understand about the test helpers but in this case I don't think they are being involved? Just trying to test a route that has ApplicationRouteMixin included.
Ah sorry, right. This isn't actually about the test helpers. You probably needs needs: ['service:session', 'session-store:local-storage'] or whatever store you have configured.
That was actually a bug in the code - fixed in 9334d47ae431ebc0e2ae48fc8fe089558e795296
Fix confirmed