cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sgrebnov <...@git.apache.org>
Subject [GitHub] cordova-paramedic pull request: Paramedic improvements
Date Fri, 08 Apr 2016 09:42:25 GMT
Github user sgrebnov commented on a diff in the pull request:

    https://github.com/apache/cordova-paramedic/pull/3#discussion_r59002202
  
    --- Diff: paramedic-plugin/paramedic.js ---
    @@ -0,0 +1,93 @@
    +/**
    +    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.
    +*/
    +
    +var io = cordova.require('cordova-plugin-paramedic.socket.io');
    +
    +var PARAMEDIC_SERVER_DEFAULT_URL = 'http://127.0.0.1:8008';
    +
    +function Paramedic() {
    +
    +}
    +
    +Paramedic.prototype.initialize = function() {
    +    var me = this;
    +    var connectionUri = loadParamedicServerUrl();
    +    this.socket = io.connect(connectionUri);
    +
    +    this.socket.on('connect', function () {
    +        console.log("Paramedic has been susccessfully connected to server");
    +        if (typeof device != 'undefined') me.socket.emit('deviceInfo', device);
    +    });
    +
    +    this.overrideConsole();
    +    this.injectJasmineReporter();
    +};
    +
    +
    +Paramedic.prototype.overrideConsole = function () {
    +
    +    var origConsole = window.console;
    +    var me = this;
    +
    +    function createCustomLogger(type) {
    +        return function () {
    +            origConsole[type].apply(origConsole, arguments);
    +
    +            me.socket.emit('deviceLog', { type: type, msg: Array.prototype.slice.apply(arguments)
});
    +        };
    +    }
    +    window.console = {
    +        log: createCustomLogger('log'),
    +        warn: createCustomLogger('warn'),
    +        error: createCustomLogger('error'),
    +    };
    +    console.log('Paramedic console has been installed.');
    +};
    +
    +Paramedic.prototype.injectJasmineReporter = function () {
    +    var JasmineParamedicProxy = require('cordova-plugin-paramedic.JasmineParamedicProxy');
    +    var jasmineProxy = new JasmineParamedicProxy(this.socket);
    +    var testsModule = cordova.require("cordova-plugin-test-framework.cdvtests");
    +    var defineAutoTestsOriginal = testsModule.defineAutoTests;
    +
    +    testsModule.defineAutoTests = function () {
    +        defineAutoTestsOriginal();
    +        jasmine.getEnv().addReporter(jasmineProxy);
    +    };
    +};
    +
    +new Paramedic().initialize();
    +
    +function loadParamedicServerUrl() {
    +
    +    try {
    +        // attempt to synchronously load medic config
    +        var xhr = new XMLHttpRequest();
    +        xhr.open("GET", "../medic.json", false);
    --- End diff --
    
    Propose to leave as-is as the chance someone will want/need to change this is very low.
 We should better to get rid of medic.json file usage and pass parameters as query params.
    
    Medic.json is mostly used here to auto start tests. I believe mobile spec and test framework
should only run tests and should know nothing about different target usages like medic/etc.
So I think we should remove medic related functionality from test framework and add support
for special query params like `autoStartTests`, etc
    
    After above is done we should also update paramedic to pass server url as query param
as well.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


Mime
View raw message