@jameslnewell/buildkite-pipelines
Version:
Generate Buildkite pipelines from code.
203 lines (202 loc) • 8.96 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const _CommandStep = require("./CommandStep");
const _Plugin = require("./Plugin");
const _contrib = require("./contrib");
const installCommand = 'yarn install';
const buildCommand = 'yarn run build';
const dockerPlugin = 'docker#v3.11.0';
// test("foo", () => {
// const step = new CommandStep()
// .setKey("i-am-awesome")
// .setLabel(":yarn: install")
// .addCommand(installCommand)
// .env({ GITHUB_TOKEN: "ghp_xxx" })
// .addPlugin([])
// .build();
// console.log(step);
// });
describe(_CommandStep.CommandStep.name, ()=>{
describe('command', ()=>{
test('array when single value', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(installCommand).build();
expect(step).toHaveProperty('commands', [
installCommand
]);
});
test('array when multiple commands provided', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(installCommand).addCommand(buildCommand).build();
expect(step).toHaveProperty('commands', [
installCommand,
buildCommand
]);
});
});
describe('env', ()=>{
test('undefined when undefined', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').build();
expect(step).not.toHaveProperty('env');
});
test('defined when object', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').env('FOO', 'bar').build();
expect(step).toHaveProperty('env.FOO', 'bar');
});
});
describe('plugins', ()=>{
test('undefined when not defined', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':');
expect(step.build()).not.toHaveProperty('plugins');
});
test('defined when object', async ()=>{
const object = await new _CommandStep.CommandStep().addCommand(':').addPlugin({
[dockerPlugin]: null
}).build();
expect(object).toHaveProperty('plugins.0', {
[dockerPlugin]: null
});
});
test('defined when builder', async ()=>{
const object = await new _CommandStep.CommandStep().addCommand(':').addPlugin(new _Plugin.Plugin().setName(dockerPlugin)).build();
expect(object).toHaveProperty('plugins.0', {
[dockerPlugin]: null
});
});
test('can add multiple', async ()=>{
const object = await new _CommandStep.CommandStep().command(':').addPlugins([
new _contrib.ECRPlugin(),
new _Plugin.Plugin(dockerPlugin)
]).build();
expect(object).toHaveProperty('plugins.0', {
[_contrib.ECRPlugin.PLUGIN]: {}
});
expect(object).toHaveProperty('plugins.1', {
[dockerPlugin]: null
});
});
});
describe('parallelism', ()=>{
test('undefined by default', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').build();
expect(step).not.toHaveProperty('parallelism');
});
test('defined when 3', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').setParallelism(3).build();
expect(step).toHaveProperty('parallelism', 3);
});
});
describe('skip', ()=>{
test('undefined by default', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').build();
expect(step).not.toHaveProperty('skip');
});
test('defined when true', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').setSkip(true).build();
expect(step).toHaveProperty('skip', true);
});
test('defined when false', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').setSkip(false).build();
expect(step).toHaveProperty('skip', false);
});
});
describe('concurrency', ()=>{
test('undefined by default', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').build();
expect(step).not.toHaveProperty('concurrency');
});
test('defined when 1', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').concurrency('test', 1).build();
expect(step).toHaveProperty('concurrency', 1);
});
});
describe('concurrency_group', ()=>{
test('undefined by default', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').build();
expect(step).not.toHaveProperty('concurrency_group');
});
test('defined when 1', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').concurrency('test', 1).build();
expect(step).toHaveProperty('concurrency_group', 'test');
});
});
describe('soft_fail', ()=>{
test('undefined by default', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').build();
expect(step).not.toHaveProperty('soft_fail');
});
test('defined when true', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').setSoftFail(true).build();
expect(step).toHaveProperty('soft_fail', true);
});
});
describe('timeout_in_minutes', ()=>{
test('undefined by default', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').build();
expect(step).not.toHaveProperty('timeout_in_minutes');
});
test('defined when 2', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').timeout(2).build();
expect(step).toHaveProperty('timeout_in_minutes', 2);
});
});
describe('agents', ()=>{
test('undefined by default', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').build();
expect(step).not.toHaveProperty('agents');
});
test('defined when queue specified', async ()=>{
const step = await new _CommandStep.CommandStep().addCommand(':').agent('queue', 'arm').build();
expect(step).toHaveProperty('agents', {
queue: 'arm'
});
});
});
describe('retries', ()=>{
test('no retry property when no retries are set', async ()=>{
const step = await new _CommandStep.CommandStep().build();
expect(step).not.toHaveProperty('retry');
});
test('no manual retry property when only automatic retries are set', async ()=>{
const step = await new _CommandStep.CommandStep().addAutomaticRetry({
exit_status: '*'
}).build();
expect(step).not.toHaveProperty('retry.manual');
});
test('no automatic retry property when only manual retry is set', async ()=>{
const step = await new _CommandStep.CommandStep().setManualRetry(true).build();
expect(step).not.toHaveProperty('retry.automatic');
});
test('has manual retry property when manual retry is false', async ()=>{
const step = await new _CommandStep.CommandStep().setManualRetry(false).build();
expect(step).toHaveProperty('retry.manual', false);
});
test('has manual retry property when manual retry is true', async ()=>{
const step = await new _CommandStep.CommandStep().setManualRetry(true).build();
expect(step).toHaveProperty('retry.manual', true);
});
test('has manual retry property when manual retry is an object', async ()=>{
const step = await new _CommandStep.CommandStep().setManualRetry({
permit_on_passed: false,
reason: 'Cannot retry a successful deployment'
}).build();
expect(step).toHaveProperty('retry.manual', {
permit_on_passed: false,
reason: 'Cannot retry a successful deployment'
});
});
test('has automatic retry property when automatic retry is added', async ()=>{
const step = await new _CommandStep.CommandStep().addAutomaticRetry({
exit_status: 139,
limit: 1
}).build();
expect(step).toHaveProperty('retry.automatic', [
{
exit_status: 139,
limit: 1
}
]);
});
});
});
//# sourceMappingURL=CommandStep.test.js.map