UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

82 lines (81 loc) โ€ข 5.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createNodeTestJobs = void 0; const runner_1 = require("../../runner"); const context_1 = require("../../types/context"); const utils_1 = require("../../utils"); const createArtifactsConfig_1 = require("../base/createArtifactsConfig"); const cache_1 = require("./cache"); const constants_1 = require("./constants"); const yarn_1 = require("./yarn"); const createJobCache_1 = require("../cache/createJobCache"); const createNodeTestJobs = async context => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3; // don't run tests after release // TODO: this will be replaced by using rules if (context.trigger === "taggedRelease") { return []; } // if its not a standalone build, we don't need to run tests if (context.type === "component" && !(0, context_1.componentContextIsStandaloneBuild)(context)) { return []; } const defaultImage = (0, runner_1.getRunnerImage)("jobs-default"); const base = { variables: { APP_PATH: context.build.dir, ...(context.type === "component" ? { ...context.environment.jobOnlyVars.build.envVars } : {}) }, stage: "test", needs: [] }; const buildConfig = context.build.config; const [yarnInstall, packageManagerInfo, nodeCache] = await Promise.all([(0, yarn_1.getYarnInstall)(context), context.packageManagerInfo, (0, cache_1.getNodeCache)(context)]); const auditJob = buildConfig.audit !== false ? { name: "๐Ÿ›ก audit", ...base, runnerVariables: { ...constants_1.NODE_RUNNER_BUILD_VARIABLES, ...((_b = (_a = buildConfig.audit) === null || _a === void 0 ? void 0 : _a.runnerVariables) !== null && _b !== void 0 ? _b : {}) }, image: (_d = (_c = buildConfig.audit) === null || _c === void 0 ? void 0 : _c.jobImage) !== null && _d !== void 0 ? _d : defaultImage, cache: undefined, // audit does not need yarn install and no cache script: [`cd ${context.build.dir}`, ...((_f = (0, utils_1.ensureArrayOrNull)((_e = buildConfig.audit) === null || _e === void 0 ? void 0 : _e.command)) !== null && _f !== void 0 ? _f : [packageManagerInfo.isClassic ? "yarn audit --level critical" : "yarn npm audit --environment production --severity critical" // yarn 2 ])], allow_failure: (_h = (_g = buildConfig.audit) === null || _g === void 0 ? void 0 : _g.allowFailure) !== null && _h !== void 0 ? _h : true, ...(0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_j = buildConfig.audit) === null || _j === void 0 ? void 0 : _j.artifactsReports, (_k = buildConfig.audit) === null || _k === void 0 ? void 0 : _k.artifacts) } : null; const lintJob = buildConfig.lint !== false ? { name: "๐Ÿ‘ฎ lint", ...base, runnerVariables: { ...constants_1.NODE_RUNNER_BUILD_VARIABLES, ...((_m = (_l = buildConfig.lint) === null || _l === void 0 ? void 0 : _l.runnerVariables) !== null && _m !== void 0 ? _m : {}) }, image: (_p = (_o = buildConfig.lint) === null || _o === void 0 ? void 0 : _o.jobImage) !== null && _p !== void 0 ? _p : defaultImage, cache: (0, createJobCache_1.createJobCacheFromCacheConfigs)(context, nodeCache), script: [...(0, yarn_1.ensureNodeVersion)(context), `cd ${context.build.dir}`, ...yarnInstall, ...((_r = (0, utils_1.ensureArrayOrNull)((_q = buildConfig.lint) === null || _q === void 0 ? void 0 : _q.command)) !== null && _r !== void 0 ? _r : ["yarn lint"])], allow_failure: (_s = buildConfig.lint) === null || _s === void 0 ? void 0 : _s.allowFailure, ...(0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_t = buildConfig.lint) === null || _t === void 0 ? void 0 : _t.artifactsReports, (_u = buildConfig.lint) === null || _u === void 0 ? void 0 : _u.artifacts) } : null; const testJob = buildConfig.test !== false ? { name: "๐Ÿงช test", ...base, runnerVariables: { ...constants_1.NODE_RUNNER_BUILD_VARIABLES, ...((_w = (_v = buildConfig.test) === null || _v === void 0 ? void 0 : _v.runnerVariables) !== null && _w !== void 0 ? _w : {}) }, image: (_y = (_x = buildConfig.test) === null || _x === void 0 ? void 0 : _x.jobImage) !== null && _y !== void 0 ? _y : (0, runner_1.getRunnerImage)("jobs-testing-chrome"), cache: (0, createJobCache_1.createJobCacheFromCacheConfigs)(context, nodeCache), script: [...(0, yarn_1.ensureNodeVersion)(context), `cd ${context.build.dir}`, ...yarnInstall, ...((_0 = (0, utils_1.ensureArrayOrNull)((_z = buildConfig.test) === null || _z === void 0 ? void 0 : _z.command)) !== null && _0 !== void 0 ? _0 : ["yarn test"])], allow_failure: (_1 = buildConfig.test) === null || _1 === void 0 ? void 0 : _1.allowFailure, ...(0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_2 = buildConfig.test) === null || _2 === void 0 ? void 0 : _2.artifactsReports, (_3 = buildConfig.test) === null || _3 === void 0 ? void 0 : _3.artifacts) } : null; return [auditJob, lintJob, testJob].filter(utils_1.notNil); }; exports.createNodeTestJobs = createNodeTestJobs;