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

feat(config): clientDisplayNone sets client elements display none. #3348

Merged
merged 2 commits into from Sep 9, 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
8 changes: 7 additions & 1 deletion client/karma.js
Expand Up @@ -2,7 +2,7 @@ var stringify = require('../common/stringify')
var constant = require('./constants')
var util = require('../common/util')

function Karma (socket, iframe, opener, navigator, location) {
function Karma (socket, iframe, opener, navigator, location, document) {
var startEmitted = false
var reloadingContext = false
var self = this
Expand Down Expand Up @@ -239,6 +239,12 @@ function Karma (socket, iframe, opener, navigator, location) {
reloadingContext = !self.config.clearContext
navigateContextTo(constant.CONTEXT_URL)

if (self.config.clientDisplayNone) {
[].forEach.call(document.querySelectorAll('#banner, #browsers'), function (el) {
johnjbarton marked this conversation as resolved.
Show resolved Hide resolved
el.style.display = 'none'
})
}

// clear the console before run
// works only on FF (Safari, Chrome do not allow to clear console from js source)
if (window.console && window.console.clear) {
Expand Down
2 changes: 1 addition & 1 deletion client/main.js
Expand Up @@ -23,4 +23,4 @@ var socket = io(location.host, {
// instantiate the updater of the view
new StatusUpdater(socket, util.elm('title'), util.elm('banner'), util.elm('browsers'))
window.karma = new Karma(socket, util.elm('context'), window.open,
window.navigator, window.location)
window.navigator, window.location, window.document)
17 changes: 13 additions & 4 deletions docs/config/01-configuration-file.md
Expand Up @@ -59,10 +59,10 @@ Under the hood Karma uses ts-node to transpile TypeScript to JavaScript. If the
Create a JavaScript configuration file that overrides the module format.
```javascript
// karma.conf.js
require('ts-node').register({
compilerOptions: {
module: 'commonjs'
}
require('ts-node').register({
compilerOptions: {
module: 'commonjs'
}
});
require('./karma.conf.ts');
```
Expand Down Expand Up @@ -268,6 +268,15 @@ If true, Karma runs the tests inside the original window without using iframe. I
If true, Karma clears the context window upon the completion of running the tests. If false, Karma does not clear the context window
upon the completion of running the tests. Setting this to false is useful when embedding a Jasmine Spec Runner Template.

## client.clientDisplayNone
**Type:** Boolean

**Default:** `false`

**Description:** Set style display none on client elements.

If true, Karma does not display the banner and browser list. Useful when using karma on component tests with screenshots.

## colors
**Type:** Boolean

Expand Down
18 changes: 17 additions & 1 deletion test/client/karma.spec.js
Expand Up @@ -9,6 +9,7 @@ var MockSocket = require('./mocks').Socket

describe('Karma', function () {
var socket, k, ck, windowNavigator, windowLocation, windowStub, startSpy, iframe, clientWindow
var windowDocument, elements

function setTransportTo (transportName) {
socket._setTransportNameTo(transportName)
Expand All @@ -21,8 +22,10 @@ describe('Karma', function () {
windowNavigator = {}
windowLocation = { search: '' }
windowStub = sinon.stub().returns({})
elements = [{ style: {} }, { style: {} }]
windowDocument = { querySelectorAll: sinon.stub().returns(elements) }

k = new ClientKarma(socket, iframe, windowStub, windowNavigator, windowLocation)
k = new ClientKarma(socket, iframe, windowStub, windowNavigator, windowLocation, windowDocument)
clientWindow = {
karma: k
}
Expand Down Expand Up @@ -57,6 +60,19 @@ describe('Karma', function () {
assert(windowStub.calledWith('context.html'))
})

it('should not set style on elements', function () {
var config = {}
socket.emit('execute', config)
assert(Object.keys(elements[0].style).length === 0)
})

it('should set display none on elements if clientDisplayNone', function () {
var config = { clientDisplayNone: true }
socket.emit('execute', config)
assert(elements[0].style.display === 'none')
assert(elements[1].style.display === 'none')
})

it('should stop execution', function () {
sinon.spy(k, 'complete')
socket.emit('stop')
Expand Down