UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

102 lines โ€ข 5.51 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 = (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; // 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 = (0, yarn_1.getYarnInstall)(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 : [ context.packageManagerInfo.isClassic ? "yarn audit" : "yarn npm audit --environment production", // yarn 2 ]), ], allow_failure: true, ...(0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_g = buildConfig.audit) === null || _g === void 0 ? void 0 : _g.artifactsReports, (_h = buildConfig.audit) === null || _h === void 0 ? void 0 : _h.artifacts), } : null; const lintJob = buildConfig.lint !== false ? { name: "๐Ÿ‘ฎ lint", ...base, runnerVariables: { ...constants_1.NODE_RUNNER_BUILD_VARIABLES, ...((_k = (_j = buildConfig.lint) === null || _j === void 0 ? void 0 : _j.runnerVariables) !== null && _k !== void 0 ? _k : {}), }, image: (_m = (_l = buildConfig.lint) === null || _l === void 0 ? void 0 : _l.jobImage) !== null && _m !== void 0 ? _m : defaultImage, cache: (0, createJobCache_1.createJobCacheFromCacheConfigs)(context, (0, cache_1.getNodeCache)(context)), script: [ ...(0, yarn_1.ensureNodeVersion)(context), `cd ${context.build.dir}`, ...yarnInstall, ...((_p = (0, utils_1.ensureArrayOrNull)((_o = buildConfig.lint) === null || _o === void 0 ? void 0 : _o.command)) !== null && _p !== void 0 ? _p : ["yarn lint"]), ], ...(0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_q = buildConfig.lint) === null || _q === void 0 ? void 0 : _q.artifactsReports, (_r = buildConfig.lint) === null || _r === void 0 ? void 0 : _r.artifacts), } : null; const testJob = buildConfig.test !== false ? { name: "๐Ÿงช test", ...base, runnerVariables: { ...constants_1.NODE_RUNNER_BUILD_VARIABLES, ...((_t = (_s = buildConfig.test) === null || _s === void 0 ? void 0 : _s.runnerVariables) !== null && _t !== void 0 ? _t : {}), }, image: (_v = (_u = buildConfig.test) === null || _u === void 0 ? void 0 : _u.jobImage) !== null && _v !== void 0 ? _v : (0, runner_1.getRunnerImage)("jobs-testing-chrome"), cache: (0, createJobCache_1.createJobCacheFromCacheConfigs)(context, (0, cache_1.getNodeCache)(context)), script: [ ...(0, yarn_1.ensureNodeVersion)(context), `cd ${context.build.dir}`, ...yarnInstall, ...((_x = (0, utils_1.ensureArrayOrNull)((_w = buildConfig.test) === null || _w === void 0 ? void 0 : _w.command)) !== null && _x !== void 0 ? _x : ["yarn test"]), ], ...(0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_y = buildConfig.test) === null || _y === void 0 ? void 0 : _y.artifactsReports, (_z = buildConfig.test) === null || _z === void 0 ? void 0 : _z.artifacts), } : null; return [auditJob, lintJob, testJob].filter(utils_1.notNil); }; exports.createNodeTestJobs = createNodeTestJobs; //# sourceMappingURL=testJob.js.map