Skip to content

Commit

Permalink
fix(client): fix issue with loaded on safari 10 (#3252)
Browse files Browse the repository at this point in the history
Safari 10 supports type=module but ignores nomodule which causes loaded() to execute twice.

Fixes #3198
  • Loading branch information
curquhart authored and johnjbarton committed Jan 18, 2019
1 parent 376142e commit 571191c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion context/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function ContextKarma (callParentKarmaMethod) {
// Define local variables
var hasError = false
var self = this
var isLoaded = false

// Define our loggers
// DEV: These are intentionally repeated in client and context
Expand Down Expand Up @@ -36,7 +37,8 @@ function ContextKarma (callParentKarmaMethod) {
// all files loaded, let's start the execution
this.loaded = function () {
// has error -> cancel
if (!hasError) {
if (!hasError && !isLoaded) {
isLoaded = true
try {
this.start(this.config)
} catch (error) {
Expand Down
15 changes: 15 additions & 0 deletions test/client/karma.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,5 +433,20 @@ describe('Karma', function () {

assert.equal(iframe.src, CURRENT_URL)
})

it('should accept multiple calls to loaded', function () {
// support for Safari 10 since it supports type=module but not nomodule.
var config = ck.config = {
useIframe: true
}

socket.emit('execute', config)
assert(!startSpy.called)

ck.loaded()
ck.loaded()
assert(startSpy.calledWith(config))
assert(startSpy.getCalls().length === 1)
})
})
})

0 comments on commit 571191c

Please sign in to comment.