From 43f6a1ab9941dce9dc8cc7b2d0abde79e3edd3c6 Mon Sep 17 00:00:00 2001 From: Todd Wolfson Date: Thu, 14 Apr 2016 18:33:34 -0500 Subject: [PATCH] refactor(context): Future-proofed context.html and debug.html for modularity BREAKING CHANGE: Our `context.html` and `debug.html` structures have changed to lean on `context.js` and `debug.js`. This is in preparation for deeper `context.js` changes in #1984. As a result, all `customContextFile` and `customDebugFile` options much update their format to match this new format. --- gruntfile.js | 2 ++ lib/middleware/karma.js | 12 ++++----- static/context.html | 11 +++------ static/context.js | 13 ++++++++++ static/debug.html | 34 +++----------------------- static/debug.js | 29 ++++++++++++++++++++++ test/e2e/support/context/context2.html | 11 +++------ 7 files changed, 60 insertions(+), 52 deletions(-) create mode 100644 static/context.js create mode 100644 static/debug.js diff --git a/gruntfile.js b/gruntfile.js index 2e7282e08..6d644cf4d 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/debug.js', 'test/**/*.js', 'gruntfile.js' ] diff --git a/lib/middleware/karma.js b/lib/middleware/karma.js index 9c3168d72..cbedf28e2 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 debug.js + var jsFiles = ['/karma.js', '/context.js', '/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.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. --> + +