Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): Add test coverage for config.singleRun true branch. #3384

Merged
merged 1 commit into from Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/browser_collection.js
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
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
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
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