From a527fa5ff199b80f8e5faded5de8c59fefbf62da Mon Sep 17 00:00:00 2001 From: Kumar McMillan Date: Mon, 22 Nov 2010 09:51:10 -0600 Subject: [PATCH] Adds support to run QUnit tests in CI with JS TestNet --- media/js/zamboni/jstestnet.js | 101 ++++++++++++++++++++++++++++++ media/js/zamboni/tests/suite.json | 1 + urls.py | 6 +- 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 media/js/zamboni/jstestnet.js diff --git a/media/js/zamboni/jstestnet.js b/media/js/zamboni/jstestnet.js new file mode 100644 index 0000000000..c4dd027e8c --- /dev/null +++ b/media/js/zamboni/jstestnet.js @@ -0,0 +1,101 @@ + +// +// Adapter for JS TestNet +// https://github.com/kumar303/jstestnet +// +// Be sure this file is loaded *after* qunit/testrunner.js or whatever else +// you're using + +(function() { + + var canPost = false; + try { + canPost = !!window.top.postMessage; + } catch(e){} + if (!canPost) { + return; + } + + function postMsg(data) { + var msg = ''; + for (var k in data) { + if (msg.length > 0) { + msg += '&'; + } + msg += k + '=' + encodeURI(data[k]); + } + window.top.postMessage(msg, '*'); + } + + // QUnit (jQuery) + // http://docs.jquery.com/QUnit + if ( typeof QUnit !== "undefined" ) { + + QUnit.begin = function() { + postMsg({ + action: 'hello', + user_agent: navigator.userAgent + }); + }; + + QUnit.done = function(failures, total) { + // // Clean up the HTML (remove any un-needed test markup) + // $("nothiddendiv").remove(); + // $("loadediframe").remove(); + // $("dl").remove(); + // $("main").remove(); + // + // // Show any collapsed results + // $('ol').show(); + + postMsg({ + action: 'done', + failures: failures, + total: total + }); + }; + + QUnit.log = function(result, message) { + // Strip out html: + message = message.replace(/<(?:.|\s)*?>/g, ''); + postMsg({ + action: 'log', + result: result, + message: message + }); + }; + + QUnit.moduleStart = function(name) { + postMsg({ + action: 'set_module', + name: name + }); + }; + + QUnit.testStart = function(name) { + postMsg({ + action: 'set_test', + name: name + }); + }; + + // window.TestSwarm.serialize = function(){ + // // Clean up the HTML (remove any un-needed test markup) + // remove("nothiddendiv"); + // remove("loadediframe"); + // remove("dl"); + // remove("main"); + // + // // Show any collapsed results + // var ol = document.getElementsByTagName("ol"); + // for ( var i = 0; i < ol.length; i++ ) { + // ol[i].style.display = "block"; + // } + // + // return trimSerialize(); + // }; + } else { + throw new Error("Cannot adapt to jstestnet: Unknown test runner"); + } + +})(); diff --git a/media/js/zamboni/tests/suite.json b/media/js/zamboni/tests/suite.json index bb608aafcf..7d98add399 100644 --- a/media/js/zamboni/tests/suite.json +++ b/media/js/zamboni/tests/suite.json @@ -1,6 +1,7 @@ { "name": "Main Test Suite", "extra_media_urls": [ + "js/zamboni/jstestnet.js", "js/zamboni/tests.js", "js/zamboni/devhub.js" ] diff --git a/urls.py b/urls.py index 9d44aad44a..d0392bda82 100644 --- a/urls.py +++ b/urls.py @@ -141,7 +141,11 @@ if 'django_qunit' in settings.INSTALLED_APPS: import django_qunit.views import jingo ctx = django_qunit.views.get_suite_context(request, path) - return jingo.render(request, 'qunit.html', ctx) + response = jingo.render(request, 'qunit.html', ctx) + # This allows another site to embed the QUnit suite + # in an iframe (for CI). + response['x-frame-options'] = '' + return response urlpatterns += patterns('', url(r'^qunit/(?P.*)', zamboni_qunit),