@stryker-mutator/core
Version:
The extendable JavaScript mutation testing framework
56 lines • 2.3 kB
JavaScript
import { commonTokens, tokens } from '@stryker-mutator/api/plugin';
import { errorToString } from '@stryker-mutator/util';
import { initializerTokens } from './index.js';
const getName = (packageName) => {
return packageName.replace('@stryker-mutator/', '').replace('stryker-', '').split('-')[0];
};
const mapSearchResultToPromptOption = (searchResults) => searchResults.objects.map((result) => ({
name: getName(result.package.name),
pkg: result.package,
}));
const handleResult = (from) => (response) => {
if (response.statusCode === 200 && response.result) {
return response.result;
}
else {
throw new Error(`Path ${from} resulted in http status code: ${response.statusCode}.`);
}
};
export class NpmClient {
constructor(log, innerNpmClient) {
this.log = log;
this.innerNpmClient = innerNpmClient;
}
getTestRunnerOptions() {
return this.search(`/-/v1/search?text=keywords:${encodeURIComponent('@stryker-mutator/test-runner-plugin')}`).then(mapSearchResultToPromptOption);
}
getTestReporterOptions() {
return this.search(`/-/v1/search?text=keywords:${encodeURIComponent('@stryker-mutator/reporter-plugin')}`).then(mapSearchResultToPromptOption);
}
getAdditionalConfig(pkgInfo) {
const path = `/${encodeURIComponent(pkgInfo.name)}@${pkgInfo.version}`;
return this.innerNpmClient
.get(path)
.then(handleResult(path))
.catch((err) => {
this.log.warn(`Could not fetch additional initialization config for dependency ${pkgInfo.name}. You might need to configure it manually`, err);
return pkgInfo;
});
}
search(path) {
this.log.debug(`Searching: ${path}`);
return this.innerNpmClient
.get(path)
.then(handleResult(path))
.catch((err) => {
this.log.error(`Unable to reach 'https://registry.npmjs.com' (for query ${path}). Please check your internet connection.`, errorToString(err));
const result = {
objects: [],
total: 0,
};
return result;
});
}
}
NpmClient.inject = tokens(commonTokens.logger, initializerTokens.restClientNpm);
//# sourceMappingURL=npm-client.js.map