I'm attempting to perform integration/acceptance tests for my Ember app. I'm specifically testing user authentication (e.g. – submitting the login form) and protected pages/states that require authenticated users.
General notes about my app:
- Using Ember App Kit
- Using ember-simple-auth for authentication
- I have api-stubs for my ember-simple-auth forms to hit using the Devise authorizer. These work fine when running the app in-browser.
I have three problems:
1. Devise Authenticator & Ephemeral Storage
From the ember-simple-auth API, it refers to using Ephemeral storage for tests. I have done so, much like this. However, it seems that the sessions is still getting stored in local storage. If I do not perform localStorage.clear()
in each test setup/teardown tests fail because I remain logged in when each test runs after the first.
Am I able to prevent storing the session in local storage between each test when I'm using the Devise authenticator for my app?
2. Multiple Acceptance Tests
If I attempt to log in a user in more than 1 test()
, my tests spin off into an infinite loop. The first test will pass, but when the second test submits the login form the entire test suite stops and reboots.
Integration Test #1
App = null
module('Acceptance - Page #1',
setup: ->
App = startApp()
teardown: ->
Ember.run(App, 'destroy')
)
test('page #1 behind authentication', ->
expect(1)
visit('/page-1')
fillIn('input#identification', '[email protected]')
fillIn('input#password', 'password')
click('button[type="submit"]')
andThen(->
equal(true, true) # This test works fine
)
)
Integration Test #2
App = null
module('Acceptance - Page #2',
setup: ->
App = startApp()
teardown: ->
Ember.run(App, 'destroy')
)
test('page #2 behind authentication', ->
expect(1)
visit('/page-2')
fillIn('input#identification', '[email protected]')
fillIn('input#password', 'password')
click('button[type="submit"]')
andThen(->
equal(true, true) # Never runs, tests start over, infinite loop begins
)
)
3. EAK api-stubs & Testem
EAK's api-stubs do not seem to be available for Testem, so the "log in" process in these acceptance test when run via the command line/Testem fail.
I attempted setting up sinon.js, but above mentioned issues have prevented me from deciding if it's actually working correctly or not. What is the best way to successfully stub logging in a user with ember-simple-auth? Is it possible to use EAK's api-stubs for Testem?