UNPKG

stryker

Version:
82 lines 3.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var util_1 = require("@stryker-mutator/util"); var plugin_1 = require("stryker-api/plugin"); var _1 = require("."); var getName = function (packageName) { return packageName.split('-')[1]; }; var mapSearchResultToPromptOption = function (searchResults) { return searchResults.results.map(function (result) { return ({ name: getName(result.package.name), npm: result.package.name }); }); }; var handleResult = function (from) { return function (response) { if (response.statusCode === 200 && response.result) { return response.result; } else { throw new Error("Query " + from + " resulted in http status code: " + response.statusCode + "."); } }; }; var NpmClient = /** @class */ (function () { function NpmClient(log, searchClient, packageClient) { this.log = log; this.searchClient = searchClient; this.packageClient = packageClient; } NpmClient.prototype.getTestRunnerOptions = function () { return this.search('/v2/search?q=keywords:stryker-test-runner') .then(mapSearchResultToPromptOption); }; NpmClient.prototype.getTestFrameworkOptions = function (testRunnerFilter) { return this.search('/v2/search?q=keywords:stryker-test-framework') .then(function (searchResult) { if (testRunnerFilter) { searchResult.results = searchResult.results.filter(function (framework) { return framework.package.keywords.indexOf(testRunnerFilter) >= 0; }); } return searchResult; }) .then(mapSearchResultToPromptOption); }; NpmClient.prototype.getMutatorOptions = function () { return this.search('/v2/search?q=keywords:stryker-mutator') .then(mapSearchResultToPromptOption); }; NpmClient.prototype.getTranspilerOptions = function () { return this.search('/v2/search?q=keywords:stryker-transpiler') .then(mapSearchResultToPromptOption); }; NpmClient.prototype.getTestReporterOptions = function () { return this.search("/v2/search?q=keywords:stryker-reporter") .then(mapSearchResultToPromptOption); }; NpmClient.prototype.getAdditionalConfig = function (packageName) { var _this = this; return this.packageClient.get("/" + packageName + "/latest") .then(handleResult(_1.BASE_NPM_PACKAGE + "/" + packageName)) .then(function (pkg) { return pkg.initStrykerConfig || {}; }) .catch(function (err) { _this.log.warn("Could not fetch additional initialization config for dependency " + packageName + ". You might need to configure it manually", err); return {}; }); }; NpmClient.prototype.search = function (query) { var _this = this; var call = _1.BASE_NPM_SEARCH + query; this.log.debug("Searching: " + call); return this.searchClient.get(query) .then(handleResult(call)) .catch(function (err) { _this.log.error("Unable to reach " + _1.BASE_NPM_SEARCH + " (for query " + query + "). Please check your internet connection.", util_1.errorToString(err)); var result = { results: [], total: 0 }; return result; }); }; NpmClient.inject = plugin_1.tokens(plugin_1.commonTokens.logger, _1.initializerTokens.restClientNpmSearch, _1.initializerTokens.restClientNpm); return NpmClient; }()); exports.default = NpmClient; //# sourceMappingURL=NpmClient.js.map