sonar-js-coverage-convertor
Version:
Convert Istanbul coverage reports to SonarQube Generic Data format for Polymer app usage
121 lines (120 loc) • 4.51 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @license
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
const chalk = require("chalk");
const cleankill = require("cleankill");
const freeport = require("freeport");
const selenium = require("selenium-standalone");
const which = require("which");
const promisify = require("promisify-node");
const SELENIUM_OVERRIDES = require(`${process.env.PWD}/package.json`)["selenium-overrides"] || require('../package.json')['selenium-overrides'];
// console.log("running from here", __dirname);
// console.log("nodepath", process.env.NODE_PATH);
// console.log("pwd", process.env.PWD);
function checkSeleniumEnvironment() {
return __awaiter(this, void 0, void 0, function* () {
try {
console.log("yield which java");
yield promisify(which)('java');
return;
}
catch (error) {
console.error("caught error which java", error);
}
let message = 'java is not present on your PATH.';
if (process.platform === 'win32') {
message += `\n\n Please install it: https://java.com/download/\n\n`;
}
else if (process.platform === 'linux') {
try {
yield promisify(which)('apt-get');
message = message + '\n\n sudo apt-get install default-jre\n\n';
}
catch (error) {
// There's not a clear default package for yum distros.
}
}
throw message;
});
}
exports.checkSeleniumEnvironment = checkSeleniumEnvironment;
function startSeleniumServer(wct, args) {
return __awaiter(this, void 0, void 0, function* () {
wct.emit('log:info', 'Starting Selenium server for local browsers');
yield checkSeleniumEnvironment();
console.log("after yielding");
const opts = { args: args, install: false };
return seleniumStart(wct, opts);
});
}
exports.startSeleniumServer = startSeleniumServer;
function installAndStartSeleniumServer(wct, args) {
return __awaiter(this, void 0, void 0, function* () {
wct.emit('log:info', 'Installing and starting Selenium server for local browsers');
yield checkSeleniumEnvironment();
const opts = { args: args, install: true };
return seleniumStart(wct, opts);
});
}
exports.installAndStartSeleniumServer = installAndStartSeleniumServer;
function seleniumStart(wct, opts) {
return __awaiter(this, void 0, void 0, function* () {
const port = yield promisify(freeport)();
// See below.
const log = [];
function onOutput(data) {
const message = data.toString();
log.push(message);
wct.emit('log:debug', message);
}
const config = SELENIUM_OVERRIDES || {};
config.seleniumArgs = ['-port', port.toString()].concat(opts.args);
// Bookkeeping once the process starts.
config.spawnCb = function (server) {
// Make sure that we interrupt the selenium server ASAP.
cleankill.onInterrupt(function (done) {
server.kill();
done();
});
server.stdout.on('data', onOutput);
server.stderr.on('data', onOutput);
};
console.log("opts installlllllll? ", opts);
if (opts.install) {
try {
const options = SELENIUM_OVERRIDES || {};
options.logger = onOutput;
yield promisify(selenium.install)(options);
}
catch (error) {
log.forEach((line) => wct.emit('log:info', line));
throw error;
}
}
try {
yield promisify(selenium.start)(config);
}
catch (error) {
log.forEach((line) => wct.emit('log:info', line));
throw error;
}
wct.emit('log:info', 'Selenium server running on port', chalk.yellow(port.toString()));
return port;
});
}