I created a basic test app that uses the OMDb API (The Open Movie Database), and with some help from SO posters everything is working fine.
I added ember-simple-auth (version 1.0.0) to the project, and got the dev side of things going. Basically there's a simple login screen to get into the main app. It's working as expected.
However, my two basic acceptance tests are now not working. After adding the ember-simple-auth components and functionality to the app, to the acceptance test file I added:
import { currentSession, authenticateSession, invalidateSession } from 'movie-example/tests/helpers/ember-simple-auth';
and in a test itself, I added:
authenticateSession();
The test now fails, saying:
Cannot read property '__container__' of undefined
Moreover, if I comment out the import line and the authenticateSession() call, the test still fails, but because the DOM is apparently completely empty.
The whole thing is available in a repo if anyone is curious/willing: git#github.com:bdrsgg/ember-movie-example.git (branch = feature/ember-simple-auth)
I assume there's some configuration issue I'm getting wrong, or something like that. Appreciate any help anyone can offer.
EDITED TO ADD:
The issue definitely seems to center on authentication. For example, if I remove the AuthenticatedRouteMixin calls from the routes, and leave out authenticateSession() calls, the tests pass.
Turned out I was just not declaring an earlier application variable correctly. Long story short, when I changed authenticateSession() to authenticateSession(this.application), things worked as expected.
Related
I have this in my testem.js
launch_in_ci: ['Chromium'],
launch_in_dev: ['Chrome'],
Is there any way to run ember test and specify CI/dev environment?
I know I can use this solution but this looks like not the right way since I have configuration file.
Here is how testem chooses which config to use:
https://github.com/testem/testem/blob/50ca9c274ec904d77a90915840349142231aadff/lib/config.js#L294 (I just searched for launch_in_dev on their github
appMode is passed in to the constructor here: https://github.com/testem/testem/blob/50ca9c274ec904d77a90915840349142231aadff/lib/config.js#L44
that Config class is required here: https://github.com/testem/testem/blob/50ca9c274ec904d77a90915840349142231aadff/lib/api.js#L4
and constructed here: https://github.com/testem/testem/blob/50ca9c274ec904d77a90915840349142231aadff/lib/api.js#L53
So we need to find out how options is set and when setup is called.
options in Api is set here: https://github.com/testem/testem/blob/50ca9c274ec904d77a90915840349142231aadff/lib/api.js#L74-L86 (startDev and startCi -- these seem fairly specific -- hopefully we're close to finding the answer.)
those methods are both called here: https://github.com/testem/testem/blob/50ca9c274ec904d77a90915840349142231aadff/testem.js#L79-L81
and now what we're looking for is how progOptions gets built.
It comes from here: https://github.com/testem/testem/blob/50ca9c274ec904d77a90915840349142231aadff/testem.js#L5
which is from https://www.npmjs.com/package/commander
which means we need to read through all the following config below where commander is required.
App mode is set: https://github.com/testem/testem/blob/50ca9c274ec904d77a90915840349142231aadff/testem.js#L8-L52
in the evaluation of each of these.
Which maybe means that this is normally not an automated switch and ember is abstracting this for us.
So let's hop on over to ember-cli:
a search brought me to this file: https://github.com/ember-cli/ember-cli/blob/b24b73b388934796ca915ca665b48a27c857199b/lib/tasks/test.js#L13
but here it looks like ember is always running CI.
so.. idk. I'll leave this here for others to go spelunking, but I gotta do some chores now.
I have installed the Emberjs starter-kit from Github: ember-starter-kit
And placed it here
And everything seems to work fine, but when I try the testing environment, by using the ?test command, it seems to fail
This all happens while I haven't made any changes to the starter-kit.
The only thing I can think of that might cause problems with the testing is the fact that fertilemedia.com has mod_rewrite (a .htaccess) at root level, but I could not find anything online about mod_rewrite interfering with the emberjs tests.
I've also tried adding:
App.Router.reopen({
rootURL: '/playground/ember/starterkit/'
});
But this does not seem to have any effect.
Since I've made no changes to the starter-kit, and the non-test page seems to work fine, what am I doing wrong?
I have a function inside another function that is supposedly getting called, according to my expect(Parse.User.Login).toHaveBeenCalled() line, but there are some console statements inside the callback to that which aren't showing up.
Is there some type of dependency I'm missing on my unit test causing the callback not to have called? I think it is getting to the server, because it tells me I need a Parse.initialize with the application keys if that's not present.
How do I resolve it?
It just occurred to me, maybe that's something in Parse.js telling me I need the Parse.initialize(keys,keys). I changed the parse keys to nonsense, and its not telling me they're wrong, so it must be that parse isn't being touched at all. No request is being sent to the server.
I've been putting up a few questions about this, but now I guess this can't be done with Karma-jasmine -- at least the way the app is set up right now. It's depending on a web service to give the errors, instead of having an angular directive set up up front to detect the errors in the fields beforehand.
I'm a newbie at this obviously, or I would have recognized this sooner:
This type of testing, where you are depending on responses from the server and that's that, should be delegated to E2E tests.
Meaning, here what am I supposed to test that wouldn't be just hardcoding the desired response right into the jasmine Spy? What would that do to just set the rootScope to a user attribute? Maybe, if state.go changed the view to another page, and then acted on the $rootScope data, this would make sense. But for now, there's no point. I'm not designing the next step, nor do I know what it is at the moment, so I can only sit back.
I am typically searching for answers here but I finlly gotten to the point where I can't find a good answer.
I am looking to build an ember app which only initially loads in the things that it needs just to start and open the main route. All other controllers, views, templates, etc. Would be loaded lazily when a specific route gets triggered.
I have found a good example of how to accomplIsh this here:
http://madhatted.com/2013/6/29/lazy-loading-with-ember
My main question is to determine what build tools out there support this theory of lazy loading application code? So far, I've seen that Brunch, Yeoman, and Ember App Kit seemed to minify and concatenate all the scripts and templates. I am very happy with minification but need those files separate. I have thought about just putting this code into the app/assets location so that it gets copied over without concat but it does not get minified.
Does anyone have a solution? Thanks!
You can do this with brunch by adding the following to your brunch config
files: {
javascripts: {
joinTo: {
'javascripts/app.js': /^app(\/|\\)(?!admin)/, // concat everything in app, except /app/admin
'javascripts/vendor.js': /^vendor/,
'javascripts/admin.js': /^app(\/|\\)admin/ // concat only /app/admin
}
}
}
Grunt (used in yeoman and ember app kit) is ridiculously flexible, so I'm sure you can set up the same thing there by diving into Gruntfile.js
The question was: "I am looking to build an ember app which only initially loads in the things that it needs just to start and open the main route. All other controllers, views, templates, etc. Would be loaded lazily when a specific route gets triggered.".
Ember expects to have anything it needs right there when the page gets loaded. I wouldn't be wrong, but lazy loading of routes doesn't seem to be a feature of Ember. Ember CLI is the same. It uses bundling and minification to reduce the overload. But everything should be there to make it work.
Instead, people like me would like to load things only when they are required.
When you try to implement lazy loading in Ember, everything should be represented by a module (file.js): a route, a module; a controller, a module; and so on.
You should follow a schema (like POD), to which apply a mechanism to find things where they are supposed to be.
Every module should know its dependencies. But some of them are very frequent (route, controller, template).
You should use a module loader for the browser. It can be requirejs or whatever you like. But ES6 is at the door. Let's think about that.
Many people use beforeModel hook to achieve a result. I did it, and it works, if you don't use link-to component. Otherwise everything crashes. Why? Because of href computed property. When a link-to has been inserted, an href is calculated for it. Because of that, Ember looks for the route where the link points to. If the route doesn't exist, one is created from route:basic.
A solution could be the preloading of all the routes represented by all link-tos inserted in the page. Too much expensive!
An integration to this answer can be found at Lazy loading route definitions in Ember.js
For an initial solution to lazy loading of routes organized in POD, have a look at https://github.com/ricottatosta/ember-wiz. It is an ES6 based approach, which relay on SystemJS as module loader.
When using sinatra-r18n to handle internationalisation, the r18n lib exposes a variable t for use within your helpers, routes and templates, as per these instructions.
I have written a simple unit test using rack-unit to confirm that some of my pluralisations work but the test throws an error claiming t is nil.
I've tried referencing it via app.t, MySillyApp.t (where MySillyApp is the name of my Sinatra app), MySillyApp.settings.t etc and none of them give me access to the t I need.
What I am trying to achieve is a confirmation that my translation files include all the keys I need corresponding to plurals of various metric units my app needs to understand. Perhaps there is a more direct way of testing this without going via the Sinatra app itself. I'd welcome any insight here.
I had similar task to check localized strings in my Cucumber scenarios.
I've made working example.
Here you can find how strings got translated.
This file halps to understand how to add R18n support to your testing framework:
require 'r18n-core'
...
class SinCucR18nWorld
...
include R18n::Helpers
end
As you can see instead of rack/unit I'm using RSpec/Cucumber, sorry.