Skip to content

Commit

Permalink
feat(:sparkles:): add meta information to healthcheck endpoint (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wil Wilsman authored Mar 2, 2020
1 parent 491bc3a commit c67ed5a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
8 changes: 7 additions & 1 deletion src/services/agent-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ export class AgentService {
}

private async handleHealthCheck(_: express.Request, response: express.Response) {
return response.json({ success: true })
return response.json({
success: true,
build: {
number: this.buildService.buildNumber,
url: this.buildService.buildUrl,
},
})
}
}
35 changes: 24 additions & 11 deletions test/unit/services/agent-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,32 @@ describe('AgentService', () => {
it('starts serving dist/public on supplied port', async () => {
await captureStdOut(() => subject.start(configuration))

chai.request(`http://localhost:${configuration.agent.port}`)
await chai.request(`http://localhost:${configuration.agent.port}`)
.get('/percy-agent.js')
.end((error, response) => {
expect(error).to.be.eq(null)
.then((response) => {
expect(response).to.have.status(200)
expect(response).to.have.header('content-type', /application\/javascript/)
})
})

it('sends meta information with the healthcheck endpoint', async () => {
await captureStdOut(() => subject.start(configuration))

await chai.request(`http://localhost:${configuration.agent.port}`)
.get('/percy/healthcheck')
.then((response) => {
expect(response).to.have.status(200)
expect(response).to.be.json
expect(response.body).to.deep.equal({
success: true,
build: {
number: 1322,
url: 'https://percy.io/test/test/builds/659575',
},
})
})
})

it('logs to stdout that it created a build', async () => {
const stdout = await captureStdOut(() => subject.start(configuration))
expect(stdout).to.match(/\[percy\] created build #\d+: https:\/\/percy\.io\/test\/test\/builds\/\d+/)
Expand All @@ -54,20 +71,16 @@ describe('AgentService', () => {
await subject.stop()
})

chai.request(`http://localhost:${configuration.agent.port}`)
await chai.request(`http://localhost:${configuration.agent.port}`)
.get('/percy-agent.js')
.catch(async (error) => {
await expect(error).to.have.property('message', `connect ECONNREFUSED 127.0.0.1:${configuration.agent.port}`)
.catch((error) => {
expect(error).to.have.property('message', `connect ECONNREFUSED 127.0.0.1:${configuration.agent.port}`)
})
})

it('logs to stdout that it finalized a build', async () => {
await captureStdOut(() => subject.start(configuration))

const stdout = await captureStdOut(async () => {
await subject.stop()
})

const stdout = await captureStdOut(() => subject.stop())
expect(stdout).to.match(/\[percy\] finalized build #\d+: https:\/\/percy\.io\/test\/test\/builds\/\d+/)
})
})
Expand Down

0 comments on commit c67ed5a

Please sign in to comment.