codecombat/app/views/TestView.coffee

80 lines
2.3 KiB
CoffeeScript
Raw Normal View History

CocoView = require 'views/kinds/CocoView'
template = require 'templates/test'
requireUtils = require 'lib/requireUtils'
TEST_REQUIRE_PREFIX = 'test/app/'
TEST_URL_PREFIX = '/test/'
2014-06-07 21:15:57 -04:00
module.exports = TestView = class TestView extends CocoView
2014-06-30 22:16:26 -04:00
id: 'test-view'
template: template
reloadOnClose: true
2014-06-30 22:16:26 -04:00
# INITIALIZE
constructor: (options, @subPath='') ->
super(options)
@subPath = @subPath[1..] if @subPath[0] is '/'
@loadTestingLibs()
loadTestingLibs: ->
@queue = new createjs.LoadQueue()
@queue.on('complete', @scriptsLoaded, @)
for f in ['jasmine', 'jasmine-html', 'boot', 'mock-ajax', 'test-app']
@queue.loadFile({
src: "/javascripts/#{f}.js"
type: createjs.LoadQueue.JAVASCRIPT
})
2014-06-30 22:16:26 -04:00
scriptsLoaded: ->
@initSpecFiles()
@render()
2014-06-07 21:15:57 -04:00
TestView.runTests(@specFiles)
window.runJasmine()
2014-06-30 22:16:26 -04:00
# RENDER DATA
2014-06-30 22:16:26 -04:00
getRenderData: ->
c = super(arguments...)
c.parentFolders = requireUtils.getParentFolders(@subPath, TEST_URL_PREFIX)
c.children = requireUtils.parseImmediateChildren(@specFiles, @subPath, TEST_REQUIRE_PREFIX, TEST_URL_PREFIX)
parts = @subPath.split('/')
c.currentFolder = parts[parts.length-1] or parts[parts.length-2] or 'All'
c
2014-06-30 22:16:26 -04:00
# RUNNING TESTS
2014-06-30 22:16:26 -04:00
initSpecFiles: ->
2014-06-07 21:15:57 -04:00
@specFiles = TestView.getAllSpecFiles()
if @subPath
prefix = TEST_REQUIRE_PREFIX + @subPath
@specFiles = (f for f in @specFiles when f.startsWith prefix)
2014-06-07 21:15:57 -04:00
@runTests: (specFiles) ->
specFiles ?= @getAllSpecFiles()
describe 'CodeCombat Client', =>
2014-06-06 20:08:49 -04:00
jasmine.Ajax.install()
beforeEach ->
2014-06-06 20:08:49 -04:00
jasmine.Ajax.requests.reset()
Backbone.Mediator.init()
Backbone.Mediator.setValidationEnabled false
# TODO Stubbify more things
# * document.location
# * firebase
# * all the services that load in main.html
2014-06-30 22:16:26 -04:00
afterEach ->
# TODO Clean up more things
# * Events
2014-06-30 22:16:26 -04:00
2014-06-07 21:15:57 -04:00
require f for f in specFiles # runs the tests
@getAllSpecFiles = ->
allFiles = window.require.list()
(f for f in allFiles when f.indexOf('.spec') > -1)
destroy: ->
# hack to get jasmine tests to properly run again on clicking links, and make sure if you
# leave this page (say, back to the main site) that test stuff doesn't follow you.
2014-06-30 22:16:26 -04:00
document.location.reload()