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

Commit

Permalink
feat: add "init:after_ssh_pool" event (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
delmendo authored and gregberge committed Mar 1, 2019
1 parent 0fcc0f9 commit e864338
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/shipit-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ Log using Shipit, same API as `console.log`.
shipit.log('hello %s', 'world')
```

## Workflow tasks

When the system initializes it automatically emits events:
* Emit event "init"
* Emit event "init:after_ssh_pool"

Each shipit task also generates events:
* Emit event "task_start"
* Emit event "task_stop"
* Emit event "task_err"
* Emit event "task_not_found"

Inside the task events, you can test for the task name.
```js
shipit.on("task_start", (event) => {
if (event.task == "first_task"){
shipit.log("I'm the first task");
}
});
```
## License

MIT
Expand Down
1 change: 1 addition & 0 deletions packages/shipit-cli/src/Shipit.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class Shipit extends Orchestrator {

this.pool = new ConnectionPool(servers, options)

this.emit('init:after_ssh_pool')
return this
}

Expand Down
16 changes: 16 additions & 0 deletions packages/shipit-cli/src/Shipit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ describe('Shipit', () => {
shipit.initialize()
expect(shipit.initSshPool).toBeCalled()
})
it('should emit a "init" event', async () => {
const spy = jest.fn()
shipit.on('init', spy)
expect(spy).toHaveBeenCalledTimes(0)
shipit.initialize()
expect(spy).toHaveBeenCalledTimes(1)
})

})

describe('#initSshPool', () => {
Expand All @@ -63,6 +71,14 @@ describe('Shipit', () => {
expect(shipit.pool.connections[0].remote.user).toBe('deploy')
expect(shipit.pool.connections[0].remote.host).toBe('my-server')
})
it('should emit a "init:after_ssh_pool" event', async () => {
shipit.config = { servers: ['deploy@my-server'] }
const spy = jest.fn()
shipit.on('init:after_ssh_pool', spy)
expect(spy).toHaveBeenCalledTimes(0)
shipit.initSshPool()
expect(spy).toHaveBeenCalledTimes(1)
})
})

describe('#local', () => {
Expand Down

0 comments on commit e864338

Please sign in to comment.