@catladder/cli
Version:
Panter cli tool for cloud CI/CD and DevOps
92 lines โข 4.83 kB
JavaScript
;
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;
// 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,
}
: {}),
},
runnerVariables: constants_1.NODE_RUNNER_BUILD_VARIABLES,
stage: "test",
needs: [],
envMode: "none",
};
const buildConfig = context.build.config;
const yarnInstall = (0, yarn_1.getYarnInstall)(context);
const auditJob = buildConfig.audit !== false
? {
name: "๐ก audit",
...base,
image: (_b = (_a = buildConfig.audit) === null || _a === void 0 ? void 0 : _a.jobImage) !== null && _b !== void 0 ? _b : defaultImage,
cache: undefined, // audit does not need yarn install and no cache
script: [
`cd ${context.build.dir}`,
...((_d = (0, utils_1.ensureArrayOrNull)((_c = buildConfig.audit) === null || _c === void 0 ? void 0 : _c.command)) !== null && _d !== void 0 ? _d : [
context.packageManagerInfo.isClassic
? "yarn audit"
: "yarn npm audit --environment production", // yarn 2
]),
],
allow_failure: true,
...(0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_e = buildConfig.audit) === null || _e === void 0 ? void 0 : _e.artifactsReports, (_f = buildConfig.audit) === null || _f === void 0 ? void 0 : _f.artifacts),
}
: null;
const lintJob = buildConfig.lint !== false
? {
name: "๐ฎ lint",
...base,
image: (_h = (_g = buildConfig.lint) === null || _g === void 0 ? void 0 : _g.jobImage) !== null && _h !== void 0 ? _h : defaultImage,
cache: (0, createJobCache_1.createJobCacheFromCacheConfigs)(context, (0, cache_1.getNodeCache)(context)),
script: [
...(0, yarn_1.ensureNodeVersion)(context),
`cd ${context.build.dir}`,
...yarnInstall,
...((_k = (0, utils_1.ensureArrayOrNull)((_j = buildConfig.lint) === null || _j === void 0 ? void 0 : _j.command)) !== null && _k !== void 0 ? _k : ["yarn lint"]),
],
...(0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_l = buildConfig.lint) === null || _l === void 0 ? void 0 : _l.artifactsReports, (_m = buildConfig.lint) === null || _m === void 0 ? void 0 : _m.artifacts),
}
: null;
const testJob = buildConfig.test !== false
? {
name: "๐งช test",
...base,
image: (_p = (_o = buildConfig.test) === null || _o === void 0 ? void 0 : _o.jobImage) !== null && _p !== void 0 ? _p : (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,
...((_r = (0, utils_1.ensureArrayOrNull)((_q = buildConfig.test) === null || _q === void 0 ? void 0 : _q.command)) !== null && _r !== void 0 ? _r : ["yarn test"]),
],
...(0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_s = buildConfig.test) === null || _s === void 0 ? void 0 : _s.artifactsReports, (_t = buildConfig.test) === null || _t === void 0 ? void 0 : _t.artifacts),
}
: null;
return [auditJob, lintJob, testJob].filter(utils_1.notNil);
};
exports.createNodeTestJobs = createNodeTestJobs;
//# sourceMappingURL=testJob.js.map