You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by mm...@apache.org on 2014/08/01 20:18:18 UTC
git commit: CB-7251 Add medic reporting for CI
Repository: cordova-plugin-test-framework
Updated Branches:
refs/heads/master 64bab6d52 -> 31c26e15a
CB-7251 Add medic reporting for CI
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework/commit/31c26e15
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework/tree/31c26e15
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework/diff/31c26e15
Branch: refs/heads/master
Commit: 31c26e15aab13ce58fddedd67002140464c4418a
Parents: 64bab6d
Author: Michal Mocny <mm...@gmail.com>
Authored: Fri Aug 1 14:03:46 2014 -0400
Committer: Michal Mocny <mm...@gmail.com>
Committed: Fri Aug 1 14:03:46 2014 -0400
----------------------------------------------------------------------
plugin.xml | 1 +
www/assets/index.html | 1 +
www/assets/jasmine-medic.js | 128 +++++++++++++++++++++++++++++++++++++++
www/jasmine_helpers.js | 7 +--
www/main.js | 24 ++++----
www/medic.js | 53 ++++++++++++++++
www/tests.js | 2 +-
7 files changed, 199 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework/blob/31c26e15/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 3ce8692..cd89503 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -14,6 +14,7 @@
<js-module src="www/tests.js" name="cdvtests" />
<js-module src="www/jasmine_helpers.js" name="jasmine_helpers" />
+ <js-module src="www/medic.js" name="medic" />
<js-module src="www/main.js" name="main" />
<asset src="www/assets" target="cdvtests" />
http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework/blob/31c26e15/www/assets/index.html
----------------------------------------------------------------------
diff --git a/www/assets/index.html b/www/assets/index.html
index 20e0c5f..a2aed0c 100644
--- a/www/assets/index.html
+++ b/www/assets/index.html
@@ -12,6 +12,7 @@
<script type="text/javascript" src="jasmine-2.0.0/jasmine.js"></script>
<script type="text/javascript" src="jasmine-2.0.0/jasmine-html.js"></script>
+ <script type="text/javascript" src="jasmine-medic.js"></script>
<script type="text/javascript" src="../cordova.js"></script>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework/blob/31c26e15/www/assets/jasmine-medic.js
----------------------------------------------------------------------
diff --git a/www/assets/jasmine-medic.js b/www/assets/jasmine-medic.js
new file mode 100644
index 0000000..bc5189e
--- /dev/null
+++ b/www/assets/jasmine-medic.js
@@ -0,0 +1,128 @@
+jasmineRequire.medic = function(j$) {
+ j$.MedicReporter = jasmineRequire.MedicReporter(j$);
+};
+
+jasmineRequire.MedicReporter = function(j$) {
+ var noopTimer = {
+ start: function() {},
+ elapsed: function() { return 0; }
+ };
+
+ function MedicReporter(options) {
+ var env = options.env || {},
+ logoptions = options.log || { logurl: 'http://127.0.0.1:5984/' }, // TODO: http://localhost:6800
+ getContainer = options.getContainer,
+ createElement = options.createElement,
+ createTextNode = options.createTextNode,
+ onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {},
+ timer = options.timer || noopTimer,
+ results = [],
+ specsExecuted = 0,
+ failureCount = 0,
+ pendingSpecCount = 0,
+ symbols;
+
+
+ var serverurl = logoptions.logurl;
+
+ this.initialize = function() {
+ }
+
+ var totalSpecsDefined;
+ this.jasmineStarted = function(options) {
+ totalSpecsDefined = options.totalSpecsDefined || 0;
+ timer.start();
+ };
+
+ var topResults = new j$.ResultsNode({}, "", null),
+ currentParent = topResults;
+
+ this.suiteStarted = function(result) {
+ };
+
+ this.suiteDone = function(result) {
+
+ };
+
+ this.specStarted = function(result) {
+ // Start timing this spec
+ };
+
+ var failures = [];
+ this.specDone = function(result) {
+ if (result.status != "disabled") {
+ specsExecuted++;
+ }
+ if (result.status == "failed") {
+ failureCount++;
+ results.push(result);
+ }
+ if (result.status == "pending") {
+ pendingSpecCount++;
+ }
+ };
+
+ buildResults = function(){
+ var json ={specs:specsExecuted, failures:failureCount, results: results};
+ return json;
+ }
+
+ this.jasmineDone = function() {
+ var p = 'Desktop';
+ var devmodel='none';
+ if(typeof device != 'undefined') {
+ p = device.platform.toLowerCase();
+ devmodel=device.model || device.name;
+ }
+
+ this.postTests({
+ mobilespec:buildResults(),
+ platform:(platformMap.hasOwnProperty(p) ? platformMap[p] : p),
+ version:p,
+ timestamp:Math.round(Math.floor((new Date()).getTime() / 1000)),
+ model:devmodel
+ });
+
+ };
+
+
+ logresult = function(){
+ if(failureCount>0 ) {
+ console.log('[[[ TEST OK ]]]');
+ } else {
+ console.log('[[[ TEST FAILED ]]]');
+ }
+ logfinished();
+ };
+
+ var logfinished = function(){
+ console.log('>>> DONE <<<');
+ };
+
+ this.postTests = function(json) {
+ console.log('posting tests');
+
+ var xhr = new XMLHttpRequest();
+ xhr.open("POST", serverurl+'/result', true);
+ xhr.setRequestHeader("Content-Type","application/json")
+ xhr.send(JSON.stringify(json));
+ }
+ return this;
+ }
+
+ /**
+ * Calculate elapsed time, in Seconds.
+ * @param startMs Start time in Milliseconds
+ * @param finishMs Finish time in Milliseconds
+ * @return Elapsed time in Seconds */
+ function elapsedSec(startMs, finishMs) {
+ return (finishMs - startMs) / 1000;
+ }
+
+ var platformMap = {
+ 'ipod touch':'ios',
+ 'iphone':'ios'
+ };
+
+ return MedicReporter;
+};
http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework/blob/31c26e15/www/jasmine_helpers.js
----------------------------------------------------------------------
diff --git a/www/jasmine_helpers.js b/www/jasmine_helpers.js
index 364bd57..c35ae73 100644
--- a/www/jasmine_helpers.js
+++ b/www/jasmine_helpers.js
@@ -80,15 +80,14 @@ function addJasmineReporters(jasmineInterface, jasmineEnv) {
jasmineInterface.htmlReporter.initialize();
jasmineEnv.addReporter(jasmineInterface.htmlReporter);
- /*
- if (window.medic.enabled) {
+ var medic = require('org.apache.cordova.test-framework.medic');
+ if (medic.enabled) {
jasmineRequire.medic(jasmineInterface.jasmine);
jasmineInterface.MedicReporter = new jasmineInterface.jasmine.MedicReporter({
env: jasmineEnv,
- log: { logurl: window.medic.logurl }
+ log: { logurl: medic.logurl }
});
jasmineInterface.MedicReporter.initialize();
jasmineEnv.addReporter(jasmineInterface.MedicReporter);
}
- */
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework/blob/31c26e15/www/main.js
----------------------------------------------------------------------
diff --git a/www/main.js b/www/main.js
index 255c768..365a811 100644
--- a/www/main.js
+++ b/www/main.js
@@ -21,8 +21,6 @@
'use strict';
-// TODO: re-add medic
-
/******************************************************************************/
function getMode(callback) {
@@ -112,9 +110,11 @@ function wrapConsole() {
}
function createCustomLogger(type) {
+ var medic = require('org.apache.cordova.test-framework.medic');
return function() {
origConsole[type].apply(origConsole, arguments);
- //window.medic.log.apply(window.medic.log, arguments);
+ // TODO: encode log type somehow for medic logs?
+ medic.log.apply(medic, arguments);
appendToOnscreenLog(type, arguments);
setLogVisibility(true);
}
@@ -200,20 +200,20 @@ function runMain() {
/******************************************************************************/
exports.init = function() {
- /*
- window.medic.load(function() {
- if (window.medic.enabled) {
- setMode('auto');
- } else {
- }
- });
- */
// TODO: have a way to opt-out of console wrapping in case line numbers are important.
// ...Or find a custom way to print line numbers using stack or something.
+ // make sure to always wrap when using medic.
attachEvents();
wrapConsole();
- getMode(setMode);
+ var medic = require('org.apache.cordova.test-framework.medic');
+ medic.load(function() {
+ if (medic.enabled) {
+ setMode('auto');
+ } else {
+ getMode(setMode);
+ }
+ });
};
/******************************************************************************/
http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework/blob/31c26e15/www/medic.js
----------------------------------------------------------------------
diff --git a/www/medic.js b/www/medic.js
new file mode 100644
index 0000000..6d4f692
--- /dev/null
+++ b/www/medic.js
@@ -0,0 +1,53 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+'use strict';
+
+exports.logurl = 'http://127.0.0.1:7800';
+
+exports.enabled = false;
+
+exports.log = function() {
+ if (!exports.enabled)
+ return;
+ var xhr = new XMLHttpRequest();
+ xhr.open("POST", exports.logurl, true);
+ xhr.setRequestHeader("Content-Type", "text/plain");
+ xhr.send(Array.prototype.slice.apply(arguments));
+};
+
+exports.load = function (callback) {
+ var xhr = new XMLHttpRequest();
+ xhr.open("GET", "../medic.json", true);
+ xhr.onload = function() {
+ if (xhr.readyState == 4 && xhr.status == 200) {
+ var cfg = JSON.parse(xhr.responseText);
+ exports.logurl = cfg.logurl;
+ exports.enabled = true;
+ console.log('Loaded Medic Config: logurl=' + exports.logurl);
+ }
+ callback();
+ }
+ xhr.onerror = function() {
+ callback();
+ }
+ xhr.send();
+}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-test-framework/blob/31c26e15/www/tests.js
----------------------------------------------------------------------
diff --git a/www/tests.js b/www/tests.js
index 39e42ec..1ee1a5e 100644
--- a/www/tests.js
+++ b/www/tests.js
@@ -59,7 +59,7 @@ function requireAllTestModules() {
}
function createJasmineInterface() {
- var jasmine_helpers = require('./jasmine_helpers');
+ var jasmine_helpers = require('org.apache.cordova.test-framework.jasmine_helpers');
var jasmineInterface = jasmine_helpers.setUpJasmine();
return jasmineInterface;
}