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(test): clear up clearContext #3597

Merged
merged 1 commit into from
Dec 23, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 23 additions & 30 deletions client/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@ function Karma (socket, iframe, opener, navigator, location, document) {
}
}

function clearContext () {
navigateContextTo('about:blank')
}

this.log = function (type, args) {
var values = []

Expand Down Expand Up @@ -234,15 +230,15 @@ function Karma (socket, iframe, opener, navigator, location, document) {
socket.emit('result', resultsBuffer)
resultsBuffer = []
}
// A test could have incorrectly issued a navigate. Wait one turn
// to ensure the error from an incorrect navigate is processed.
setTimeout(() => {
if (this.config.clearContext) {
navigateContextTo('about:blank')
}

if (self.config.clearContext) {
// A test could have incorrectly issued a navigate. To clear the context
// we will navigate the iframe. Delay ours to ensure the error from an
// incorrect navigate is processed.
setTimeout(clearContext)
}
socket.emit('complete', result || {})

socket.emit('complete', result || {}, function () {
if (returnUrl) {
location.href = returnUrl
}
Expand All @@ -260,26 +256,23 @@ function Karma (socket, iframe, opener, navigator, location, document) {
}

socket.on('execute', function (cfg) {
// Delay our navigation to the next event in case the clearContext has not completed.
setTimeout(function allowClearContextToComplete () {
// reset startEmitted and reload the iframe
startEmitted = false
self.config = cfg

navigateContextTo(constant.CONTEXT_URL)

if (self.config.clientDisplayNone) {
[].forEach.call(document.querySelectorAll('#banner, #browsers'), function (el) {
el.style.display = 'none'
})
}
// reset startEmitted and reload the iframe
startEmitted = false
self.config = cfg

// 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) {
window.console.clear()
}
})
navigateContextTo(constant.CONTEXT_URL)

if (self.config.clientDisplayNone) {
[].forEach.call(document.querySelectorAll('#banner, #browsers'), function (el) {
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) {
window.console.clear()
}
})
socket.on('stop', function () {
this.complete()
Expand Down
2 changes: 0 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ class Server extends KarmaEventEmitter {

const replySocketEvents = events.bufferEvents(socket, ['start', 'info', 'karma_error', 'result', 'complete'])

socket.on('complete', (data, ack) => ack())

socket.on('error', (err) => {
this.log.debug('karma server socket error: ' + err)
})
Expand Down
53 changes: 23 additions & 30 deletions static/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ function Karma (socket, iframe, opener, navigator, location, document) {
}
}

function clearContext () {
navigateContextTo('about:blank')
}

this.log = function (type, args) {
var values = []

Expand Down Expand Up @@ -244,15 +240,15 @@ function Karma (socket, iframe, opener, navigator, location, document) {
socket.emit('result', resultsBuffer)
resultsBuffer = []
}
// A test could have incorrectly issued a navigate. Wait one turn
// to ensure the error from an incorrect navigate is processed.
setTimeout(() => {
if (this.config.clearContext) {
navigateContextTo('about:blank')
}

if (self.config.clearContext) {
// A test could have incorrectly issued a navigate. To clear the context
// we will navigate the iframe. Delay ours to ensure the error from an
// incorrect navigate is processed.
setTimeout(clearContext)
}
socket.emit('complete', result || {})

socket.emit('complete', result || {}, function () {
if (returnUrl) {
location.href = returnUrl
}
Expand All @@ -270,26 +266,23 @@ function Karma (socket, iframe, opener, navigator, location, document) {
}

socket.on('execute', function (cfg) {
// Delay our navigation to the next event in case the clearContext has not completed.
setTimeout(function allowClearContextToComplete () {
// reset startEmitted and reload the iframe
startEmitted = false
self.config = cfg

navigateContextTo(constant.CONTEXT_URL)

if (self.config.clientDisplayNone) {
[].forEach.call(document.querySelectorAll('#banner, #browsers'), function (el) {
el.style.display = 'none'
})
}
// reset startEmitted and reload the iframe
startEmitted = false
self.config = cfg

// 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) {
window.console.clear()
}
})
navigateContextTo(constant.CONTEXT_URL)

if (self.config.clientDisplayNone) {
[].forEach.call(document.querySelectorAll('#banner, #browsers'), function (el) {
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) {
window.console.clear()
}
})
socket.on('stop', function () {
this.complete()
Expand Down
12 changes: 4 additions & 8 deletions test/client/karma.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,24 +437,20 @@ describe('Karma', function () {
it('should navigate the client to return_url if specified', function (done) {
windowLocation.search = '?id=567&return_url=http://return.com'
socket = new MockSocket()
k = new ClientKarma(socket, {}, windowStub, windowNavigator, windowLocation)
k = new ClientKarma(socket, iframe, windowStub, windowNavigator, windowLocation)
clientWindow = { karma: k }
ck = new ContextKarma(ContextKarma.getDirectCallParentKarmaMethod(clientWindow))
ck.config = {}

sinon.spy(socket, 'disconnect')

socket.on('complete', function (data, ack) {
ack()
})
clock.tick(500)

ck.complete()

clock.tick(500)
setTimeout(function () {
setTimeout(() => {
assert(windowLocation.href === 'http://return.com')
done()
}, 5)

clock.tick(10)
})

Expand Down