ember testing

after running `generate app foo` you'll also get
a basic test for your new ember app.

you can run the tests for as specific app with:

  rake js:dev <app>
  rake js:dev quizzes

Change-Id: I55c53e875c06d44ae553100bf8d73a4ee83ba278
Reviewed-on: https://gerrit.instructure.com/26023
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jason Madsen <jmadsen@instructure.com>
Product-Review: Ryan Florence <ryanf@instructure.com>
QA-Review: Ryan Florence <ryanf@instructure.com>
This commit is contained in:
Ryan Florence 2013-11-05 12:35:10 -07:00
parent 5a1fbff086
commit cc75168558
6 changed files with 43 additions and 4 deletions

View File

@ -10,7 +10,7 @@ module Canvas
JS_ROOT = "#{Rails.root}/public/javascripts" JS_ROOT = "#{Rails.root}/public/javascripts"
def matcher def matcher
ENV['JS_SPEC_MATCHER'] || '**/*Spec.js' ENV['JS_SPEC_MATCHER'] || '**/*{Spec,.spec}.js'
end end
# get all regular canvas (and plugin) bundles # get all regular canvas (and plugin) bundles

View File

@ -2,7 +2,16 @@ require 'timeout'
namespace :js do namespace :js do
desc 'run testem as you develop, can use `rake js:dev <ember app name>`'
task :dev do task :dev do
app = ARGV[1]
if app
ENV['JS_SPEC_MATCHER'] = "**/#{app}/**/*.spec.js"
unless File.exists?("app/coffeescripts/ember/#{app}")
puts "no app found at app/coffeescripts/ember/#{app}"
exit
end
end
Rake::Task['js:generate_runner'].invoke Rake::Task['js:generate_runner'].invoke
exec('testem -f config/testem.yml') exec('testem -f config/testem.yml')
end end

View File

@ -17,7 +17,9 @@ exports.present = function(appName) {
exports.templates = [ exports.templates = [
'new_app/config/app.coffee.hbs', 'new_app/config/app.coffee.hbs',
'new_app/config/routes.coffee.hbs', 'new_app/config/routes.coffee.hbs',
'new_app/templates/application.hbs.hbs' 'new_app/templates/application.hbs.hbs',
'new_app/tests/app.coffee.hbs',
'new_app/tests/app.spec.coffee.hbs'
]; ];
exports.savePath = function(template, env) { exports.savePath = function(template, env) {
@ -25,7 +27,9 @@ exports.savePath = function(template, env) {
return { return {
'new_app/config/app.coffee.hbs': 'app/coffeescripts/ember/'+env.appName+'/config/app.coffee', 'new_app/config/app.coffee.hbs': 'app/coffeescripts/ember/'+env.appName+'/config/app.coffee',
'new_app/config/routes.coffee.hbs': 'app/coffeescripts/ember/'+env.appName+'/config/routes.coffee', 'new_app/config/routes.coffee.hbs': 'app/coffeescripts/ember/'+env.appName+'/config/routes.coffee',
'new_app/templates/application.hbs.hbs': 'app/coffeescripts/ember/'+env.appName+'/templates/'+env.appName+'.hbs' 'new_app/templates/application.hbs.hbs': 'app/coffeescripts/ember/'+env.appName+'/templates/'+env.appName+'.hbs',
'new_app/tests/app.coffee.hbs': 'app/coffeescripts/ember/'+env.appName+'/tests/app.coffee',
'new_app/tests/app.spec.coffee.hbs': 'app/coffeescripts/ember/'+env.appName+'/tests/app.spec.coffee'
}[template]; }[template];
}; };

View File

@ -0,0 +1,14 @@
define ['../main'], (Application) ->
App = Application.create
LOG_ACTIVE_GENERATION: yes
LOG_MODULE_RESOLVER: yes
LOG_TRANSITIONS: yes
LOG_TRANSITIONS_INTERNAL: yes
LOG_VIEW_LOOKUPS: yes
rootElement: '#fixtures'
history: 'none'
App.setupForTesting()
App.injectTestHelpers()
App.advanceReadiness()
App

View File

@ -0,0 +1,11 @@
define ['./app', 'ember'], (App, Ember) ->
module '{{appName}}', ->
setup: ->
App.reset()
Ember.run(App, App.advanceReadiness)
test 'says hello', ->
visit('/').then ->
equal(find('h1').html().trim(), 'HELLO!')

View File

@ -105,9 +105,10 @@
var onSpecsLoaded = null; var onSpecsLoaded = null;
require(<%= require(<%=
Dir[ Dir[
"public/javascripts/#{matcher}",
"spec/javascripts/compiled/#{matcher}", "spec/javascripts/compiled/#{matcher}",
"spec/plugins/*/javascripts/compiled/#{matcher}" "spec/plugins/*/javascripts/compiled/#{matcher}"
].map{ |file| file.sub(/\.js$/, '') }.inspect ].map{ |file| file.sub(/\.js$/, '').sub(/public\/javascripts\//, '') }.inspect
%>, function() { %>, function() {
specsLoading = false; specsLoading = false;
if (onSpecsLoaded) onSpecsLoaded(); if (onSpecsLoaded) onSpecsLoaded();