appcenter-cli
Version:
Command line tool for Visual Studio App Center
112 lines (111 loc) • 5.42 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PrepareTestsCommand = void 0;
const commandline_1 = require("../../../util/commandline");
const interaction_1 = require("../../../util/interaction");
const parameters_parser_1 = require("./parameters-parser");
const included_files_parser_1 = require("./included-files-parser");
const interaction_2 = require("./interaction");
const help_messages_1 = require("./help-messages");
const _ = require("lodash");
const pfs = require("../../../util/misc/promisfied-fs");
class PrepareTestsCommand extends commandline_1.Command {
constructor(args) {
super(args);
if (typeof this.testParameters === "string") {
this.testParameters = [this.testParameters];
}
if (typeof this.include === "string") {
this.include = [this.include];
}
}
// Override this if you need to validate options
validateOptions() {
return __awaiter(this, void 0, void 0, function* () {
return;
});
}
// TODO: There is technical debt here.
// There is a lot of confusion and even duplicated code with respect to test params,
// included files and responsibility of prepare vs run.
runNoClient() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield this.validateOptions();
const manifestPath = yield interaction_2.progressWithResult("Preparing tests", this.prepareManifest());
yield this.addIncludedFilesAndTestParametersToManifest(manifestPath);
interaction_1.out.text(this.getSuccessMessage(manifestPath));
return commandline_1.success();
}
catch (err) {
return commandline_1.failure(commandline_1.ErrorCodes.Exception, err.message);
}
});
}
addIncludedFilesAndTestParametersToManifest(manifestPath) {
return __awaiter(this, void 0, void 0, function* () {
const manifestJson = yield pfs.readFile(manifestPath, "utf8");
const manifest = JSON.parse(manifestJson);
yield this.addIncludedFiles(manifest);
yield this.addTestParameters(manifest);
const modifiedJson = JSON.stringify(manifest, null, 1);
yield pfs.writeFile(manifestPath, modifiedJson);
});
}
addIncludedFiles(manifest) {
return __awaiter(this, void 0, void 0, function* () {
yield included_files_parser_1.processIncludedFiles(manifest, this.include, this.artifactsDir, this.getSourceRootDir());
});
}
addTestParameters(manifest) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.testParameters) {
return;
}
const parsedParameters = parameters_parser_1.parseTestParameters(this.testParameters);
_.merge(manifest.testFramework.data, parsedParameters || {});
});
}
prepareManifest() {
throw new Error("prepareManifest method must be overriden in derived classes");
}
getSuccessMessage(manifestPath) {
return `Tests are ready to run. Manifest file was written to ${manifestPath}`;
}
getSourceRootDir() {
throw new Error("getSourceRootDir method must be overriden in derived classes");
}
}
__decorate([
commandline_1.help(help_messages_1.Messages.TestCloud.Arguments.PrepareArtifactsDir),
commandline_1.longName("artifacts-dir"),
commandline_1.hasArg,
commandline_1.required
], PrepareTestsCommand.prototype, "artifactsDir", void 0);
__decorate([
commandline_1.help(help_messages_1.Messages.TestCloud.Arguments.Include),
commandline_1.longName("include"),
commandline_1.hasArg
], PrepareTestsCommand.prototype, "include", void 0);
__decorate([
commandline_1.help(help_messages_1.Messages.TestCloud.Arguments.TestParameter),
commandline_1.longName("test-parameter"),
commandline_1.shortName("p"),
commandline_1.hasArg
], PrepareTestsCommand.prototype, "testParameters", void 0);
exports.PrepareTestsCommand = PrepareTestsCommand;