Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Commit e864338

Browse files
delmendogregberge
authored andcommitted
feat: add "init:after_ssh_pool" event (#230)
1 parent 0fcc0f9 commit e864338

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

packages/shipit-cli/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ Log using Shipit, same API as `console.log`.
128128
shipit.log('hello %s', 'world')
129129
```
130130

131+
## Workflow tasks
132+
133+
When the system initializes it automatically emits events:
134+
* Emit event "init"
135+
* Emit event "init:after_ssh_pool"
136+
137+
Each shipit task also generates events:
138+
* Emit event "task_start"
139+
* Emit event "task_stop"
140+
* Emit event "task_err"
141+
* Emit event "task_not_found"
142+
143+
Inside the task events, you can test for the task name.
144+
```js
145+
shipit.on("task_start", (event) => {
146+
if (event.task == "first_task"){
147+
shipit.log("I'm the first task");
148+
}
149+
});
150+
```
131151
## License
132152

133153
MIT

packages/shipit-cli/src/Shipit.js

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class Shipit extends Orchestrator {
166166

167167
this.pool = new ConnectionPool(servers, options)
168168

169+
this.emit('init:after_ssh_pool')
169170
return this
170171
}
171172

packages/shipit-cli/src/Shipit.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ describe('Shipit', () => {
5252
shipit.initialize()
5353
expect(shipit.initSshPool).toBeCalled()
5454
})
55+
it('should emit a "init" event', async () => {
56+
const spy = jest.fn()
57+
shipit.on('init', spy)
58+
expect(spy).toHaveBeenCalledTimes(0)
59+
shipit.initialize()
60+
expect(spy).toHaveBeenCalledTimes(1)
61+
})
62+
5563
})
5664

5765
describe('#initSshPool', () => {
@@ -63,6 +71,14 @@ describe('Shipit', () => {
6371
expect(shipit.pool.connections[0].remote.user).toBe('deploy')
6472
expect(shipit.pool.connections[0].remote.host).toBe('my-server')
6573
})
74+
it('should emit a "init:after_ssh_pool" event', async () => {
75+
shipit.config = { servers: ['deploy@my-server'] }
76+
const spy = jest.fn()
77+
shipit.on('init:after_ssh_pool', spy)
78+
expect(spy).toHaveBeenCalledTimes(0)
79+
shipit.initSshPool()
80+
expect(spy).toHaveBeenCalledTimes(1)
81+
})
6682
})
6783

6884
describe('#local', () => {

0 commit comments

Comments
 (0)