More consistent output for test runs, test fix
This commit is contained in:
Родитель
21c9831294
Коммит
27806cf154
|
@ -32,7 +32,7 @@ function statusIcon ({ status }) {
|
|||
}
|
||||
|
||||
function printLine (testRun) {
|
||||
return `${statusIcon(testRun)} #${testRun.number} ${testRun.commit_branch}:${testRun.commit_sha.slice(0, 6)} ${testRun.status}`
|
||||
return `${statusIcon(testRun)} #${testRun.number} ${testRun.commit_branch}:${testRun.commit_sha.slice(0, 7)} ${testRun.status}`
|
||||
}
|
||||
|
||||
function limit (testRuns, count) {
|
||||
|
@ -98,5 +98,6 @@ function* render (pipeline, { heroku, watch }) {
|
|||
}
|
||||
|
||||
module.exports = {
|
||||
render
|
||||
render,
|
||||
printLine
|
||||
}
|
||||
|
|
|
@ -2,17 +2,21 @@ const api = require('./heroku-api')
|
|||
const cli = require('heroku-cli-util')
|
||||
const wait = require('co-wait')
|
||||
|
||||
/* eslint-disable no-unused-vars */
|
||||
const PENDING = 'pending'
|
||||
const CREATING = 'creating'
|
||||
/* eslint-enable no-unused-vars */
|
||||
|
||||
const BUILDING = 'building'
|
||||
const RUNNING = 'running'
|
||||
const ERRORED = 'errored'
|
||||
const FAILED = 'failed'
|
||||
const SUCCEEDED = 'succeeded'
|
||||
|
||||
// Need to export this before requiring RenderTestRuns to avoid circular dependnecy
|
||||
module.exports.STATES = {
|
||||
PENDING, CREATING, BUILDING, RUNNING, ERRORED, FAILED, SUCCEEDED
|
||||
}
|
||||
|
||||
const RenderTestRuns = require('./render-test-runs')
|
||||
|
||||
const TERMINAL_STATES = [SUCCEEDED, FAILED, ERRORED]
|
||||
const RUNNING_STATES = [RUNNING].concat(TERMINAL_STATES)
|
||||
const BUILDING_STATES = [BUILDING, RUNNING].concat(TERMINAL_STATES)
|
||||
|
@ -53,8 +57,6 @@ function stream (url) {
|
|||
}
|
||||
|
||||
function * display (pipeline, number, { heroku }) {
|
||||
cli.styledHeader(`Test run #${number} setup\n`)
|
||||
|
||||
let testRun = yield api.testRun(heroku, pipeline.id, number)
|
||||
|
||||
testRun = yield waitForStates(BUILDING_STATES, testRun, { heroku })
|
||||
|
@ -63,24 +65,12 @@ function * display (pipeline, number, { heroku }) {
|
|||
|
||||
testRun = yield waitForStates(RUNNING_STATES, testRun, { heroku })
|
||||
|
||||
cli.styledHeader(`Test run #${number} output\n`)
|
||||
|
||||
yield stream(testRun.output_stream_url)
|
||||
|
||||
cli.styledHeader(`Test run #${number} status\n`)
|
||||
|
||||
testRun = yield waitForStates(TERMINAL_STATES, testRun, { heroku })
|
||||
|
||||
const repo = yield api.pipelineRepository(heroku, pipeline.id)
|
||||
|
||||
cli.log(/* newline 💃 */)
|
||||
cli.styledHash({
|
||||
pipeline: pipeline.name,
|
||||
repo: repo.repository.name,
|
||||
status: testRun.status,
|
||||
commit: `[${testRun.commit_sha.slice(0, 6)}] ${testRun.commit_message}`,
|
||||
branch: testRun.commit_branch
|
||||
})
|
||||
cli.log(RenderTestRuns.printLine(testRun))
|
||||
|
||||
return testRun
|
||||
}
|
||||
|
@ -90,10 +80,9 @@ function * displayAndExit (pipeline, number, { heroku }) {
|
|||
process.exit(testRun.exit_code)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Object.assign(module.exports, {
|
||||
isTerminal,
|
||||
isNotTerminal,
|
||||
display,
|
||||
displayAndExit,
|
||||
STATES: { PENDING, CREATING, BUILDING, RUNNING, ERRORED, FAILED, SUCCEEDED }
|
||||
}
|
||||
displayAndExit
|
||||
})
|
||||
|
|
|
@ -3,13 +3,16 @@
|
|||
const nock = require('nock')
|
||||
const expect = require('chai').expect
|
||||
const cli = require('heroku-cli-util')
|
||||
const sinon = require('sinon')
|
||||
const cmd = require('../../../commands/ci/last')
|
||||
|
||||
describe('heroku ci:last', function () {
|
||||
let app, coupling
|
||||
let app, coupling, testRun, setupOutput, testOutput
|
||||
|
||||
beforeEach(function () {
|
||||
cli.mockConsole()
|
||||
sinon.stub(process, 'exit')
|
||||
|
||||
app = '123-app'
|
||||
|
||||
coupling = {
|
||||
|
@ -18,32 +21,57 @@ describe('heroku ci:last', function () {
|
|||
name: '123-abc'
|
||||
}
|
||||
}
|
||||
|
||||
testRun = {
|
||||
id: '123-abc',
|
||||
number: 123,
|
||||
output_stream_url: 'https://output.com/tests',
|
||||
setup_stream_url: 'https://output.com/setup',
|
||||
pipeline: coupling.pipeline,
|
||||
status: 'succeeded',
|
||||
commit_sha: '123abc456def',
|
||||
commit_branch: 'master'
|
||||
}
|
||||
|
||||
setupOutput = ''
|
||||
testOutput = ''
|
||||
})
|
||||
|
||||
it('when pipeline has runs, displays the results of the latest run', function () {
|
||||
let num = 1234
|
||||
afterEach(function () {
|
||||
process.exit.restore()
|
||||
})
|
||||
|
||||
it('when pipeline has runs, displays the results of the latest run', function* () {
|
||||
const api = nock('https://api.heroku.com')
|
||||
.get(`/apps/${app}/pipeline-couplings`)
|
||||
.reply(200, coupling)
|
||||
.get(`/pipelines/${coupling.pipeline.id}/test-runs`)
|
||||
.reply(200, [testRun])
|
||||
.get(`/pipelines/${coupling.pipeline.id}/test-runs/${testRun.number}`)
|
||||
.reply(200, testRun)
|
||||
|
||||
const streamAPI = nock('https://output.com')
|
||||
.get('/setup')
|
||||
.reply(200, setupOutput)
|
||||
.get('/tests')
|
||||
.reply(200, testOutput)
|
||||
|
||||
yield cmd.run({ app })
|
||||
expect(cli.stdout).to.contain(`✓ #${testRun.number}`)
|
||||
|
||||
api.done()
|
||||
streamAPI.done()
|
||||
})
|
||||
|
||||
it('when pipeline does not have any runs, reports that there are no runs', function* () {
|
||||
let api = nock('https://api.heroku.com')
|
||||
.get(`/apps/${app}/pipeline-couplings`)
|
||||
.reply(200, coupling)
|
||||
.get(`/pipelines/${coupling.pipeline.id}/test-runs`)
|
||||
.reply(200, [{number: num}])
|
||||
.reply(200, [])
|
||||
|
||||
return cmd.run({ app }).then(() => {
|
||||
expect(cli.stdout).to.contain(`=== Test run #${num} setup`)
|
||||
api.done()
|
||||
})
|
||||
})
|
||||
|
||||
it('when pipeline does not have any runs, reports that there are no runs', function () {
|
||||
let api = nock('https://api.heroku.com')
|
||||
.get(`/apps/${app}/pipeline-couplings`)
|
||||
.reply(200, coupling)
|
||||
.get(`/pipelines/${coupling.pipeline.id}/test-runs`)
|
||||
.reply(200, null)
|
||||
|
||||
return cmd.run({ app }).then(() => {
|
||||
expect(cli.stderr).to.contain('No Heroku CI runs found')
|
||||
api.done()
|
||||
})
|
||||
yield cmd.run({ app })
|
||||
expect(cli.stderr).to.contain('No Heroku CI runs found')
|
||||
api.done()
|
||||
})
|
||||
})
|
||||
|
|
Загрузка…
Ссылка в новой задаче