@jameslnewell/buildkite-pipelines
Version:
Generate Buildkite pipelines from code.
111 lines • 5.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const lib_1 = require("../lib");
const findSteps_1 = require("./findSteps");
const buildAppAStep = new lib_1.CommandStep()
.setLabel('Building A')
.addCommand('docker build -f Dockerfile.a');
const buildAppBStep = new lib_1.CommandStep()
.setLabel('Building B')
.addCommand('docker build -f Dockerfile.b');
const deployAppAStep = new lib_1.CommandStep()
.setLabel('Deploying A')
.addCommand('deploy image a');
const deployAppBStep = new lib_1.CommandStep()
.setLabel('Deploying B')
.addCommand('deploy image b');
const simpleBuildAndDeployPipeline = new lib_1.Pipeline().addSteps([
buildAppAStep,
buildAppBStep,
deployAppAStep,
deployAppBStep,
]);
const nestedPipeline = new lib_1.Pipeline().addSteps([
new lib_1.GroupStep().setLabel('Building').addSteps([buildAppAStep, buildAppBStep]),
new lib_1.GroupStep()
.setLabel('Deploying')
.addSteps([deployAppAStep, deployAppBStep]),
]);
describe(findSteps_1.findSteps, () => {
test('finds steps which match the predicate', () => {
const steps = (0, findSteps_1.findSteps)(simpleBuildAndDeployPipeline, (step) => {
var _a;
return (step instanceof lib_1.CommandStep &&
((_a = step.getLabel()) === null || _a === void 0 ? void 0 : _a.startsWith('Deploying')) === true);
});
expect(steps).toEqual([deployAppAStep, deployAppBStep]);
});
test('does not find steps which do not match the predicate', () => {
const steps = (0, findSteps_1.findSteps)(simpleBuildAndDeployPipeline, (step) => {
var _a;
return (step instanceof lib_1.CommandStep &&
((_a = step.getLabel()) === null || _a === void 0 ? void 0 : _a.startsWith('Publishing package')) === true);
});
expect(steps).toEqual([]);
});
test('recursively finds nested steps which match the predicate when recursive=true', () => {
const steps = (0, findSteps_1.findSteps)(nestedPipeline, (step) => {
var _a;
return (step instanceof lib_1.CommandStep &&
((_a = step.getLabel()) === null || _a === void 0 ? void 0 : _a.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_1.findSteps)(nestedPipeline, (step) => {
var _a;
return (step instanceof lib_1.CommandStep &&
((_a = step.getLabel()) === null || _a === void 0 ? void 0 : _a.startsWith('Deploying')) === true);
}, { recursive: false });
expect(steps).toEqual([]);
});
test('finds the child steps when given a group directly', () => {
const group = new lib_1.GroupStep()
.setLabel('Deploying')
.addSteps([deployAppAStep, deployAppBStep]);
const steps = (0, findSteps_1.findSteps)(group, (step) => step instanceof lib_1.CommandStep);
expect(steps).toEqual([deployAppAStep, deployAppBStep]);
});
});
describe(findSteps_1.findFirstStep, () => {
test('finds the first step which matches the predicate', () => {
const step = (0, findSteps_1.findFirstStep)(simpleBuildAndDeployPipeline, (step) => {
var _a;
return (step instanceof lib_1.CommandStep &&
((_a = step.getLabel()) === null || _a === void 0 ? void 0 : _a.startsWith('Deploying')) === true);
});
expect(step).toEqual(deployAppAStep);
});
test('does not find a step which do not match the predicate', () => {
const step = (0, findSteps_1.findFirstStep)(simpleBuildAndDeployPipeline, (step) => {
var _a;
return (step instanceof lib_1.CommandStep &&
((_a = step.getLabel()) === null || _a === void 0 ? void 0 : _a.startsWith('Publishing package')) === true);
});
expect(step).toBeUndefined();
});
test('recursively finds nested steps which match the predicate when recursive=true', () => {
const step = (0, findSteps_1.findFirstStep)(nestedPipeline, (step) => {
var _a;
return (step instanceof lib_1.CommandStep &&
((_a = step.getLabel()) === null || _a === void 0 ? void 0 : _a.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_1.findFirstStep)(nestedPipeline, (step) => {
var _a;
return (step instanceof lib_1.CommandStep &&
((_a = step.getLabel()) === null || _a === void 0 ? void 0 : _a.startsWith('Deploying')) === true);
}, { recursive: false });
expect(step).toBeUndefined();
});
test('finds the first child step when given a group directly', () => {
const group = new lib_1.GroupStep()
.setLabel('Deploying')
.addSteps([deployAppAStep, deployAppBStep]);
const step = (0, findSteps_1.findFirstStep)(group, (step) => step instanceof lib_1.CommandStep);
expect(step).toEqual(deployAppAStep);
});
});
//# sourceMappingURL=findSteps.test.js.map