UNPKG

@atomist/sdm-pack-spring

Version:

Atomist software delivery machine extension pack for Spring and Spring Boot applications

101 lines 4.38 kB
"use strict"; /* * Copyright © 2018 Atomist, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 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 }); const automation_client_1 = require("@atomist/automation-client"); const fileGlobs_1 = require("@atomist/automation-client/lib/project/fileGlobs"); const sdm_1 = require("@atomist/sdm"); const XmldocFileParser_1 = require("../../xml/XmldocFileParser"); const mavenCommand_1 = require("../mavenCommand"); /** * Goal to execute Maven tests. Shows failures or errors if there are any. * @type {GoalWithFulfillment} */ class MavenTest extends sdm_1.GoalWithFulfillment { constructor() { super({ uniqueName: "maven-test", environment: sdm_1.IndependentOfEnvironment, workingDescription: "Testing", completedDescription: "Tests succeeded", failedDescription: "Tests failed", }); this.with({ name: "maven-test", goalExecutor: executeMavenTest, }); } } exports.MavenTest = MavenTest; function executeMavenTest(goalInvocation) { const { credentials, id } = goalInvocation; return goalInvocation.configuration.sdm.projectLoader.doWithProject({ id, credentials, readOnly: true }, (p) => __awaiter(this, void 0, void 0, function* () { const mavenCommand = yield mavenCommand_1.determineMavenCommand(p); const result = yield sdm_1.spawnAndWatch({ command: mavenCommand, args: ["test"] }, { cwd: p.baseDir }, new sdm_1.LoggingProgressLog("maven-test", "info"), {}); const r = yield getJUnitTestResults(p); const prefix = r.tests === 1 ? `1 test` : `${r.tests} tests`; if (result.code === 0) { return { code: 0, phase: r.tests > 0 ? prefix : undefined, }; } else { const messages = [prefix]; if (r.failures > 0) { messages.push(`${r.failures} failed`); } if (r.errors > 0) { messages.push(`${r.errors} with errors`); } return { code: 1, phase: messages.join(", "), }; } })); } function getJUnitTestResults(p) { return __awaiter(this, void 0, void 0, function* () { const oldExcludes = fileGlobs_1.DefaultExcludes; fileGlobs_1.DefaultExcludes.splice(0, fileGlobs_1.DefaultExcludes.length); // necessary evil const testFailures = yield automation_client_1.astUtils.gatherFromMatches(p, new XmldocFileParser_1.XmldocFileParser(), "target/surefire-reports/*.xml", "/testsuite", m => { return { tests: +m.tests, failures: +m.failures, errors: +m.errors, }; }); fileGlobs_1.DefaultExcludes.push(...oldExcludes); return testFailures .reduce((previousValue, currentValue) => { return { tests: previousValue.tests + currentValue.tests, failures: previousValue.failures + currentValue.failures, errors: previousValue.errors + currentValue.errors, }; }); }); } //# sourceMappingURL=mavenTest.js.map