|
| 1 | +import * as chai from 'chai'; |
| 2 | +import * as chaiAsPromised from 'chai-as-promised'; |
| 3 | +import { prepareCommands } from '../../src/api/process'; |
| 4 | +import { CommandType } from '../../src/api/config'; |
| 5 | + |
| 6 | +chai.use(chaiAsPromised); |
| 7 | +const expect = chai.expect; |
| 8 | + |
| 9 | +describe('Test preparing commands', () => { |
| 10 | + it(`filter and sort commands for git type`, () => { |
| 11 | + const process: any = { |
| 12 | + build_id: 502, |
| 13 | + job_id: 2123, |
| 14 | + status: 'queued', |
| 15 | + commands: |
| 16 | + [ { command: 'git clone https://github.com/Izak88/d3-bundle.git -b master .', type: 'git' }, |
| 17 | + { command: 'git fetch origin master', type: 'git' }, |
| 18 | + { command: 'git checkout 582e1e2ece8ec7a866885913dd4d8d088068edd5 .', type: 'git' }, |
| 19 | + { command: 'nvm install $NODE_VERSION', type: 'install' }, |
| 20 | + { command: 'npm install', type: 'install' }, |
| 21 | + { command: 'npm run-script test', type: 'script' } ], |
| 22 | + cache: [ 'node_modules' ], |
| 23 | + repo_name: 'Izak88/d3-bundle', |
| 24 | + branch: 'master', |
| 25 | + env: [ 'NODE_VERSION=8' ], |
| 26 | + image_name: 'abstruse', |
| 27 | + exposed_ports: null, |
| 28 | + log: [] |
| 29 | + }; |
| 30 | + |
| 31 | + const types = [CommandType.git]; |
| 32 | + let commands = prepareCommands(process, types); |
| 33 | + |
| 34 | + expect(commands[0].command).to.include('git clone https://github.com/Izak88/d3-bundle.'); |
| 35 | + expect(commands[1].command).to.equals('git fetch origin master'); |
| 36 | + expect(commands[2].command).to.include('git checkout 582e1e2ece8ec7a866885913dd4d8d088068edd5'); |
| 37 | + expect(commands.length).to.equals(3); |
| 38 | + }); |
| 39 | + |
| 40 | + it(`filter and sort commands for install and script`, () => { |
| 41 | + const process: any = { |
| 42 | + build_id: 502, |
| 43 | + job_id: 2123, |
| 44 | + status: 'queued', |
| 45 | + commands: |
| 46 | + [ { command: 'git clone https://github.com/Izak88/d3-bundle.git -b master .', type: 'git' }, |
| 47 | + { command: 'git fetch origin master', type: 'git' }, |
| 48 | + { command: 'git checkout 582e1e2ece8ec7a866885913dd4d8d088068edd5 .', type: 'git' }, |
| 49 | + { command: 'nvm install $NODE_VERSION', type: 'install' }, |
| 50 | + { command: 'npm install', type: 'install' }, |
| 51 | + { command: 'npm run-script test', type: 'script' } ], |
| 52 | + cache: [ 'node_modules' ], |
| 53 | + repo_name: 'Izak88/d3-bundle', |
| 54 | + branch: 'master', |
| 55 | + env: [ 'NODE_VERSION=8' ], |
| 56 | + image_name: 'abstruse', |
| 57 | + exposed_ports: null, |
| 58 | + log: [] |
| 59 | + }; |
| 60 | + |
| 61 | + const types = [CommandType.install, CommandType.script]; |
| 62 | + let commands = prepareCommands(process, types); |
| 63 | + |
| 64 | + expect(commands[0].command).to.equals('nvm install $NODE_VERSION'); |
| 65 | + expect(commands[1].command).to.equals('npm install'); |
| 66 | + expect(commands[2].command).to.equals('npm run-script test'); |
| 67 | + expect(commands.length).to.equals(3); |
| 68 | + }); |
| 69 | + |
| 70 | + it(`filter and sort commands for install and script`, () => { |
| 71 | + const process: any = { |
| 72 | + build_id: 502, |
| 73 | + job_id: 2123, |
| 74 | + status: 'queued', |
| 75 | + commands: |
| 76 | + [ { command: 'git clone https://github.com/Izak88/d3-bundle.git -b master .', type: 'git' }, |
| 77 | + { command: 'git fetch origin master', type: 'git' }, |
| 78 | + { command: 'npm run-script test', type: 'script' }, |
| 79 | + { command: 'git checkout 582e1e2ece8ec7a866885913dd4d8d088068edd5 .', type: 'git' }, |
| 80 | + { command: 'nvm install $NODE_VERSION', type: 'install' }, |
| 81 | + { command: 'npm install', type: 'install' } ], |
| 82 | + cache: [ 'node_modules' ], |
| 83 | + repo_name: 'Izak88/d3-bundle', |
| 84 | + branch: 'master', |
| 85 | + env: [ 'NODE_VERSION=8' ], |
| 86 | + image_name: 'abstruse', |
| 87 | + exposed_ports: null, |
| 88 | + log: [] |
| 89 | + }; |
| 90 | + |
| 91 | + const types = [CommandType.install, CommandType.script]; |
| 92 | + let commands = prepareCommands(process, types); |
| 93 | + |
| 94 | + expect(commands[0].command).to.equals('nvm install $NODE_VERSION'); |
| 95 | + expect(commands[1].command).to.equals('npm install'); |
| 96 | + expect(commands[2].command).to.equals('npm run-script test'); |
| 97 | + expect(commands.length).to.equals(3); |
| 98 | + }); |
| 99 | + |
| 100 | + it(`filter and sort commands for install and script`, () => { |
| 101 | + const process: any = { |
| 102 | + build_id: 502, |
| 103 | + job_id: 2123, |
| 104 | + status: 'queued', |
| 105 | + commands: |
| 106 | + [ { command: 'git clone https://github.com/Izak88/d3-bundle.git -b master .', type: 'git' }, |
| 107 | + { command: 'git fetch origin master', type: 'git' }, |
| 108 | + { command: 'npm run-script test', type: 'script' }, |
| 109 | + { command: 'git checkout 582e1e2ece8ec7a866885913dd4d8d088068edd5 .', type: 'git' }, |
| 110 | + { command: 'node ./test.js', type: 'script' }, |
| 111 | + { command: 'node deploy.js', type: 'deploy' }, |
| 112 | + { command: 'node success.js', type: 'after_success' }, |
| 113 | + { command: 'node deploy2.js', type: 'deploy' }, |
| 114 | + { command: 'node after_failure.js', type: 'after_failure' }, |
| 115 | + { command: 'node before_deploy.js', type: 'before_deploy' }, |
| 116 | + { command: 'node after_success.js', type: 'after_success' }, |
| 117 | + { command: 'node install.js', type: 'install' }, |
| 118 | + { command: 'node after_deploy2.js', type: 'after_deploy' }, |
| 119 | + { command: 'node after_script.js', type: 'after_script' }, |
| 120 | + { command: 'npm install', type: 'install' } ], |
| 121 | + cache: [ 'node_modules' ], |
| 122 | + repo_name: 'Izak88/d3-bundle', |
| 123 | + branch: 'master', |
| 124 | + env: [ 'NODE_VERSION=8' ], |
| 125 | + image_name: 'abstruse', |
| 126 | + exposed_ports: null, |
| 127 | + log: [] |
| 128 | + }; |
| 129 | + |
| 130 | + const types = [CommandType.git, CommandType.script, CommandType.after_failure, |
| 131 | + CommandType.deploy, CommandType.after_success, CommandType.before_deploy]; |
| 132 | + let commands = prepareCommands(process, types); |
| 133 | + |
| 134 | + expect(commands[0].command).to.include('git clone https://github.com/Izak88/d3-bundle.'); |
| 135 | + expect(commands[1].command).to.equals('git fetch origin master'); |
| 136 | + expect(commands[2].command).to.include('git checkout 582e1e2ece8ec7a866885913dd4d8d088068edd5'); |
| 137 | + expect(commands[3].command).to.equals('npm run-script test'); |
| 138 | + expect(commands[4].command).to.equals('node ./test.js'); |
| 139 | + expect(commands[5].command).to.equals('node success.js'); |
| 140 | + expect(commands[6].command).to.equals('node after_success.js'); |
| 141 | + expect(commands[7].command).to.equals('node after_failure.js'); |
| 142 | + expect(commands[8].command).to.equals('node before_deploy.js'); |
| 143 | + expect(commands[9].command).to.equals('node deploy.js'); |
| 144 | + expect(commands[10].command).to.equals('node deploy2.js'); |
| 145 | + expect(commands.length).to.equals(11); |
| 146 | + }); |
| 147 | + |
| 148 | + it(`filter and sort commands for install and script`, () => { |
| 149 | + const process: any = { |
| 150 | + build_id: 502, |
| 151 | + job_id: 2123, |
| 152 | + status: 'queued', |
| 153 | + commands: |
| 154 | + [ { command: 'git clone https://github.com/Izak88/d3-bundle.git -b master .', type: 'git' }, |
| 155 | + { command: 'git fetch origin master', type: 'git' }, |
| 156 | + { command: 'npm run-script test', type: 'script' }, |
| 157 | + { command: 'git checkout 582e1e2ece8ec7a866885913dd4d8d088068edd5 .', type: 'git' }, |
| 158 | + { command: 'node ./test.js', type: 'script' }, |
| 159 | + { command: 'node deploy.js', type: 'deploy' }, |
| 160 | + { command: 'node success.js', type: 'after_success' }, |
| 161 | + { command: 'node deploy2.js', type: 'deploy' }, |
| 162 | + { command: 'node after_failure.js', type: 'after_failure' }, |
| 163 | + { command: 'node before_deploy.js', type: 'before_deploy' }, |
| 164 | + { command: 'node after_success.js', type: 'after_success' }, |
| 165 | + { command: 'node install.js', type: 'install' }, |
| 166 | + { command: 'node after_deploy2.js', type: 'after_deploy' }, |
| 167 | + { command: 'node after_script.js', type: 'after_script' }, |
| 168 | + { command: 'npm install', type: 'install' } ], |
| 169 | + cache: [ 'node_modules' ], |
| 170 | + repo_name: 'Izak88/d3-bundle', |
| 171 | + branch: 'master', |
| 172 | + env: [ 'NODE_VERSION=8' ], |
| 173 | + image_name: 'abstruse', |
| 174 | + exposed_ports: null, |
| 175 | + log: [] |
| 176 | + }; |
| 177 | + |
| 178 | + const types = [CommandType.install, CommandType.after_success]; |
| 179 | + let commands = prepareCommands(process, types); |
| 180 | + |
| 181 | + expect(commands[0].command).to.equals('node install.js'); |
| 182 | + expect(commands[1].command).to.equals('npm install'); |
| 183 | + expect(commands[2].command).to.equals('node success.js'); |
| 184 | + expect(commands[3].command).to.equals('node after_success.js'); |
| 185 | + expect(commands.length).to.equals(4); |
| 186 | + }); |
| 187 | +}); |
0 commit comments