diff --git a/gruntfile.js b/gruntfile.js index 2e7282e08..ddde28a63 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -76,6 +76,8 @@ module.exports = function (grunt) { '<%= files.grunt %>', '<%= files.scripts %>', '<%= files.client %>', + 'static/context.js', + 'static/context-debug.js', 'test/**/*.js', 'gruntfile.js' ] diff --git a/lib/middleware/karma.js b/lib/middleware/karma.js index 9c3168d72..d58af6bb7 100644 --- a/lib/middleware/karma.js +++ b/lib/middleware/karma.js @@ -114,8 +114,10 @@ var createKarmaMiddleware = function ( }) } - // serve karma.js - if (requestUrl === '/karma.js') { + // serve karma.js, context.js, and context-debug.js + var jsFiles = ['/karma.js', '/context.js', '/context-debug.js'] + var isRequestingJsFile = jsFiles.indexOf(requestUrl) !== -1 + if (isRequestingJsFile) { return serveStaticFile(requestUrl, response, function (data) { return data.replace('%KARMA_URL_ROOT%', urlRoot) .replace('%KARMA_VERSION%', VERSION) @@ -195,11 +197,7 @@ var createKarmaMiddleware = function ( return util.format(" '%s': '%s'", filePath, file.sha) }) - var clientConfig = '' - - if (requestUrl === '/debug.html') { - clientConfig = 'window.__karma__.config = ' + JSON.stringify(client) + ';\n' - } + var clientConfig = 'window.__karma__.config = ' + JSON.stringify(client) + ';\n' mappings = 'window.__karma__.files = {\n' + mappings.join(',\n') + '\n};\n' diff --git a/static/context-debug.js b/static/context-debug.js new file mode 100644 index 000000000..0cbd64f2f --- /dev/null +++ b/static/context-debug.js @@ -0,0 +1,29 @@ +// Override the Karma setup for local debugging +window.__karma__.info = function (info) { + if (info.dump && window.console) window.console.log(info.dump) +} +window.__karma__.complete = function () { + if (window.console) window.console.log('Skipped ' + this.skipped + ' tests') +} +window.__karma__.store = function () {} +window.__karma__.skipped = 0 +window.__karma__.result = window.console ? function (result) { + if (result.skipped) { + this.skipped++ + return + } + var msg = result.success ? 'SUCCESS ' : 'FAILED ' + window.console.log(msg + result.suite.join(' ') + ' ' + result.description) + + for (var i = 0; i < result.log.length; i++) { + // Throwing error without losing stack trace + (function (err) { + setTimeout(function () { + throw err + }) + })(result.log[i]) + } +} : function () {} +window.__karma__.loaded = function () { + this.start() +} diff --git a/static/context.html b/static/context.html index 1269eea7c..2da2d0d52 100644 --- a/static/context.html +++ b/static/context.html @@ -15,14 +15,11 @@ to have already been created so they can insert their magic into it. For example, if loaded before body, Angular Scenario test framework fails to find the body and crashes and burns in an epic manner. --> + +