Skip to content

Commit

Permalink
Merge 844d66d into 1cd87ad
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjbarton authored Oct 17, 2019
2 parents 1cd87ad + 844d66d commit 7e03d1f
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/browser_collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class BrowserCollection {
if (results.skipped && config.failOnSkippedTests) {
return 1
}
if (results.success + results.failed === 0 && !config.failOnEmptyTestSuite) {
return 0
if (results.success + results.failed === 0 && !!config.failOnEmptyTestSuite) {
return 1
}
if (results.error) {
return 1
Expand Down
4 changes: 3 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class Server extends KarmaEventEmitter {

const emitRunCompleteIfAllBrowsersDone = () => {
if (Object.keys(singleRunDoneBrowsers).every((key) => singleRunDoneBrowsers[key])) {
this.emit('run_complete', singleRunBrowsers, singleRunBrowsers.getResults(singleRunBrowserNotCaptured, config.failOnEmptyTestSuite, config.failOnFailingTestSuite))
this.emit('run_complete', singleRunBrowsers, singleRunBrowsers.getResults(singleRunBrowserNotCaptured, config))
}
}

Expand All @@ -309,6 +309,8 @@ class Server extends KarmaEventEmitter {
singleRunDoneBrowsers[completedBrowser.id] = true
emitRunCompleteIfAllBrowsersDone()
})

// This is the normal exit trigger.
this.on('browser_complete_with_no_more_retries', function (completedBrowser) {
singleRunDoneBrowsers[completedBrowser.id] = true

Expand Down
2 changes: 1 addition & 1 deletion test/unit/browser_collection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe('BrowserCollection', () => {
const results = {
success: 0,
failed: 0,
error: true
error: false
}
it('shall pass if failOnEmptyTestSuite not is set', () => {
const res = collection.calculateExitCode(results)
Expand Down
91 changes: 82 additions & 9 deletions test/unit/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('server', () => {
browsers: ['fake'],
singleRun: true,
logLevel: 'OFF',
plugins: [],
browserDisconnectTolerance: 0
}

Expand Down Expand Up @@ -271,20 +272,92 @@ describe('server', () => {
server.emit('browser_register', {})
expect(browsersReady).to.have.been.called
})
describe('should exit with exit code', () => {
let resolveExitCode

it('should exit with error exit code on load errors', async () => {
mockProcess(process)
async function exitCode () {
return new Promise((resolve) => {
resolveExitCode = resolve
})
}

it('1 on load errors', async () => {
mockProcess(process)

await server._start(mockConfig, mockLauncher, null, mockFileList, browserCollection, mockExecutor, (exitCode) => {
resolveExitCode(exitCode)
})
server.loadErrors.push(['TestError', 'Test'])
fileListOnResolve()

function mockProcess (process) {
sinon.stub(process, 'kill').callsFake((pid, ev) => process.emit(ev))
}

await server._start(mockConfig, mockLauncher, null, mockFileList, browserCollection, mockExecutor, (exitCode) => {
expect(exitCode).to.have.equal(1)
expect(await exitCode()).to.have.equal(1)
})

server.loadErrors.push(['TestError', 'Test'])
fileListOnResolve()
it('given on run_complete', async () => {
mockProcess(process)

function mockProcess (process) {
sinon.stub(process, 'kill').callsFake((pid, ev) => process.emit(ev))
}
await server._start(mockConfig, mockLauncher, null, mockFileList, browserCollection, mockExecutor, (exitCode) => {
resolveExitCode(exitCode)
})

server.emit('run_complete', browserCollection, { exitCode: 15 })

function mockProcess (process) {
sinon.stub(process, 'kill').callsFake((pid, ev) => process.emit(ev))
}
expect(await exitCode()).to.have.equal(15)
})

it('1 on browser_process_failure (singleRunBrowserNotCaptured)', async () => {
mockProcess(process)

await server._start(mockConfig, mockLauncher, null, mockFileList, browserCollection, mockExecutor, (exitCode) => {
resolveExitCode(exitCode)
})

server.emit('browser_process_failure', { id: 'fake' })

function mockProcess (process) {
sinon.stub(process, 'kill').callsFake((pid, ev) => process.emit(ev))
}
expect(await exitCode()).to.have.equal(1)
})

it('0 on browser_complete_with_no_more_retries', async () => {
mockProcess(process)

await server._start(mockConfig, mockLauncher, null, mockFileList, browserCollection, mockExecutor, (exitCode) => {
resolveExitCode(exitCode)
})

server.emit('browser_complete_with_no_more_retries', { id: 'fake' })

function mockProcess (process) {
sinon.stub(process, 'kill').callsFake((pid, ev) => process.emit(ev))
}
expect(await exitCode()).to.have.equal(0)
})

it('1 on browser_complete_with_no_more_retries with config.failOnEmptyTestSuite', async () => {
mockProcess(process)

mockConfig.failOnEmptyTestSuite = true

await server._start(mockConfig, mockLauncher, null, mockFileList, browserCollection, mockExecutor, (exitCode) => {
resolveExitCode(exitCode)
})

server.emit('browser_complete_with_no_more_retries', { id: 'fake' })

function mockProcess (process) {
sinon.stub(process, 'kill').callsFake((pid, ev) => process.emit(ev))
}
expect(await exitCode()).to.have.equal(1)
})
})
})

Expand Down

0 comments on commit 7e03d1f

Please sign in to comment.