UNPKG

@jameslnewell/buildkite-pipelines

Version:
102 lines (101 loc) 4.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _lib = require("../lib"); const _findSteps = require("./findSteps"); const buildAppAStep = new _lib.CommandStep().setLabel('Building A').addCommand('docker build -f Dockerfile.a'); const buildAppBStep = new _lib.CommandStep().setLabel('Building B').addCommand('docker build -f Dockerfile.b'); const deployAppAStep = new _lib.CommandStep().setLabel('Deploying A').addCommand('deploy image a'); const deployAppBStep = new _lib.CommandStep().setLabel('Deploying B').addCommand('deploy image b'); const simpleBuildAndDeployPipeline = new _lib.Pipeline().addSteps([ buildAppAStep, buildAppBStep, deployAppAStep, deployAppBStep ]); const nestedPipeline = new _lib.Pipeline().addSteps([ new _lib.GroupStep().setLabel('Building').addSteps([ buildAppAStep, buildAppBStep ]), new _lib.GroupStep().setLabel('Deploying').addSteps([ deployAppAStep, deployAppBStep ]) ]); describe(_findSteps.findSteps, ()=>{ test('finds steps which match the predicate', ()=>{ const steps = (0, _findSteps.findSteps)(simpleBuildAndDeployPipeline, (step)=>{ var _step_getLabel; return step instanceof _lib.CommandStep && ((_step_getLabel = step.getLabel()) === null || _step_getLabel === void 0 ? void 0 : _step_getLabel.startsWith('Deploying')) === true; }); expect(steps).toEqual([ deployAppAStep, deployAppBStep ]); }); test('does not find steps which do not match the predicate', ()=>{ const steps = (0, _findSteps.findSteps)(simpleBuildAndDeployPipeline, (step)=>{ var _step_getLabel; return step instanceof _lib.CommandStep && ((_step_getLabel = step.getLabel()) === null || _step_getLabel === void 0 ? void 0 : _step_getLabel.startsWith('Publishing package')) === true; }); expect(steps).toEqual([]); }); test('recursively finds nested steps which match the predicate when recursive=true', ()=>{ const steps = (0, _findSteps.findSteps)(nestedPipeline, (step)=>{ var _step_getLabel; return step instanceof _lib.CommandStep && ((_step_getLabel = step.getLabel()) === null || _step_getLabel === void 0 ? void 0 : _step_getLabel.startsWith('Deploying')) === true; }, { recursive: true }); expect(steps).toEqual([ deployAppAStep, deployAppBStep ]); }); test('does not find nested steps which match the predicate when recursive=false', ()=>{ const steps = (0, _findSteps.findSteps)(nestedPipeline, (step)=>{ var _step_getLabel; return step instanceof _lib.CommandStep && ((_step_getLabel = step.getLabel()) === null || _step_getLabel === void 0 ? void 0 : _step_getLabel.startsWith('Deploying')) === true; }, { recursive: false }); expect(steps).toEqual([]); }); }); describe(_findSteps.findFirstStep, ()=>{ test('finds the first step which matches the predicate', ()=>{ const step = (0, _findSteps.findFirstStep)(simpleBuildAndDeployPipeline, (step)=>{ var _step_getLabel; return step instanceof _lib.CommandStep && ((_step_getLabel = step.getLabel()) === null || _step_getLabel === void 0 ? void 0 : _step_getLabel.startsWith('Deploying')) === true; }); expect(step).toEqual(deployAppAStep); }); test('does not find a step which do not match the predicate', ()=>{ const step = (0, _findSteps.findFirstStep)(simpleBuildAndDeployPipeline, (step)=>{ var _step_getLabel; return step instanceof _lib.CommandStep && ((_step_getLabel = step.getLabel()) === null || _step_getLabel === void 0 ? void 0 : _step_getLabel.startsWith('Publishing package')) === true; }); expect(step).toBeUndefined(); }); test('recursively finds nested steps which match the predicate when recursive=true', ()=>{ const step = (0, _findSteps.findFirstStep)(nestedPipeline, (step)=>{ var _step_getLabel; return step instanceof _lib.CommandStep && ((_step_getLabel = step.getLabel()) === null || _step_getLabel === void 0 ? void 0 : _step_getLabel.startsWith('Deploying')) === true; }, { recursive: true }); expect(step).toEqual(deployAppAStep); }); test('does not find nested steps which match the predicate when recursive=false', ()=>{ const step = (0, _findSteps.findFirstStep)(nestedPipeline, (step)=>{ var _step_getLabel; return step instanceof _lib.CommandStep && ((_step_getLabel = step.getLabel()) === null || _step_getLabel === void 0 ? void 0 : _step_getLabel.startsWith('Deploying')) === true; }, { recursive: false }); expect(step).toBeUndefined(); }); }); //# sourceMappingURL=findSteps.test.js.map