cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nikhilkh <...@git.apache.org>
Subject [GitHub] cordova-paramedic pull request: Paramedic improvements
Date Tue, 05 Apr 2016 00:41:10 GMT
Github user nikhilkh commented on a diff in the pull request:

    https://github.com/apache/cordova-paramedic/pull/3#discussion_r58472035
  
    --- Diff: lib/paramedic.js ---
    @@ -0,0 +1,205 @@
    +#!/usr/bin/env node
    +
    +var exec = require('./utils').exec,
    +    shell = require('shelljs'),
    +    Server = require('./LocalServer'),
    +    Q = require('q'),
    +    tmp = require('tmp'),
    +    PluginsManager = require('./PluginsManager'),
    +    path = require('path'),
    +    Q = require('q'),
    +    fs = require('fs'),
    +    getReporters = require('./Reporters'),
    +    logger = require('./utils').logger;
    +
    +function ParamedicRunner(config, _callback) {
    +    this.tempFolder = null;
    +    this.pluginsManager = null;
    +
    +    this.config = config;
    +
    +    exec.setVerboseLevel(config.isVerbose());
    +}
    +
    +ParamedicRunner.prototype.run = function() {
    +    var self = this;
    +
    +    return Q().then(function() {
    +        self.createTempProject();
    +        self.prepareProjectToRunTests();
    +        return Server.startServer(self.config.getPorts(), self.config.getExternalServerUrl(),
self.config.getUseTunnel());
    +    })
    +    .then(function(server) {
    +        self.server = server;
    +
    +        self.injectReporters();
    +        self.subcribeForEvents();
    +
    +        var connectionUrl = server.getConnectionUrl() || 
    +                            server.getStandartUrlForPlatform(self.config.getPlatformId());
    +        self.writeMedicConnectionUrl(connectionUrl);
    +
    +        return self.runTests();
    +    })
    +    .fin(function() {
    +        self.cleanUpProject();
    +    });
    +};
    +
    +ParamedicRunner.prototype.createTempProject = function() {
    +    this.tempFolder = tmp.dirSync();
    +    tmp.setGracefulCleanup();
    +    logger.info("cordova-paramedic: creating temp project at " + this.tempFolder.name);
    +    exec('cordova create ' + this.tempFolder.name);
    +    shell.pushd(this.tempFolder.name);
    +};
    +
    +ParamedicRunner.prototype.prepareProjectToRunTests = function() {
    +    this.installPlugins();
    +    this.setUpStartPage();
    +    this.installPlatform();
    +    this.checkPlatformRequirements();
    +};
    +
    +ParamedicRunner.prototype.installPlugins = function() {
    +    logger.info("cordova-paramedic: installing plugins");
    +    this.pluginsManager = new PluginsManager(this.tempFolder.name, this.storedCWD);
    +    this.pluginsManager.installPlugins(this.config.getPlugins());
    +    this.pluginsManager.installTestsForExistingPlugins();
    +    this.pluginsManager.installSinglePlugin('cordova-plugin-test-framework');
    +    this.pluginsManager.installSinglePlugin('cordova-plugin-device');
    +    this.pluginsManager.installSinglePlugin(path.join(__dirname, '../paramedic-plugin'));
    +};
    +
    +ParamedicRunner.prototype.setUpStartPage = function() {
    +    logger.normal("cordova-paramedic: setting app start page to test page");
    +    shell.sed('-i', 'src="index.html"', 'src="cdvtests/index.html"', 'config.xml');
    +};
    +
    +ParamedicRunner.prototype.installPlatform = function() {
    +    logger.normal("cordova-paramedic: adding platform : " + this.config.getPlatform());
    +    exec('cordova platform add ' + this.config.getPlatform());
    +};
    +
    +ParamedicRunner.prototype.checkPlatformRequirements = function() {
    +    logger.normal("cordova-paramedic: checking requirements for platform " + this.config.getPlatformId());
    +    var result = exec('cordova requirements ' + this.config.getPlatformId());
    +
    +    if (result.code !== 0) 
    +        throw new Error('Platform requirements check has failed!');
    +};
    +
    +ParamedicRunner.prototype.injectReporters = function() {
    +    var self = this;
    +    var reporters = getReporters(self.config.getReportSavePath());
    +
    +    ['jasmineStarted', 'specStarted', 'specDone',
    +    'suiteStarted', 'suiteDone', 'jasmineDone'].forEach(function(route) {
    +        reporters.forEach(function(reporter) {
    +            if (reporter[route] instanceof Function)
    +                self.server.on(route, reporter[route].bind(reporter));
    +        });
    +    });
    +};
    +
    +ParamedicRunner.prototype.subcribeForEvents = function() {
    +    this.server.on('deviceLog', function(data) {
    +        logger.verbose('device|console.' + data.type + ': '  + data.msg[0]);
    +    });
    +
    +    this.server.on('deviceInfo', function(data) {
    +        logger.info('cordova-paramedic: Device info: ' + JSON.stringify(data));
    +    });
    +};
    +
    +ParamedicRunner.prototype.writeMedicConnectionUrl = function(url) {
    +    logger.normal("cordova-paramedic: writing medic log url to project " + url);
    +    fs.writeFileSync(path.join("www","medic.json"), JSON.stringify({logurl:url}));
    +};
    +
    +ParamedicRunner.prototype.runTests = function() {
    +    var self = this;
    +
    +    return Q.promise(function(resolve, reject) {
    +        self.server.on('jasmineDone', function(data) {
    +            logger.info('cordova-paramedic: tests have been completed');
    +
    +            var isTestPassed = data.specResults.specFailed === 0;
    +
    +            resolve(isTestPassed);
    +        });
    +
    +        self.server.on('disconnect', function() {
    +            reject(new Error('device is disconnected before passing the tests'));
    +        });
    +
    +        var command = self.getCommandForStartingTests();
    +        logger.normal('cordova-paramedic: running command ' + command);
    +
    +        exec(command, function(code, output) {
    +            if(code) 
    +                return reject(new Error(command + " returned error code " + code));
    --- End diff --
    
    `output` needs to be logged to help with diagnosing errors.


---
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