-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af2ec5d
commit 52abaf0
Showing
24 changed files
with
464 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module.exports = config => { | ||
config.set({ | ||
frameworks: ['mocha-webworker'], | ||
files: [ | ||
{ | ||
pattern: 'test/web-worker.js', | ||
included: false, | ||
}, | ||
{ | ||
pattern: 'amplitude.js', | ||
included: false, | ||
}, | ||
{ | ||
pattern: 'node_modules/sinon/pkg/sinon.js', | ||
included: false, | ||
}, | ||
], | ||
browsers: ['ChromeHeadless'], | ||
autoWatch: false, | ||
singleRun: true, | ||
reporters: ['mocha'], | ||
client: { | ||
mochaWebWorker: { | ||
pattern: [ | ||
'test/web-worker.js', | ||
'amplitude.js', | ||
'node_modules/sinon/pkg/sinon.js' | ||
], | ||
worker: 'Worker', | ||
mocha: { | ||
ui: 'bdd' | ||
} | ||
} | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
import GlobalScope from './global-scope'; | ||
|
||
const getHost = (url) => { | ||
const a = document.createElement('a'); | ||
a.href = url; | ||
return a.hostname || location.hostname; | ||
if (url) { | ||
if (typeof document !== 'undefined') { | ||
const a = document.createElement('a'); | ||
a.href = url; | ||
return a.hostname || GlobalScope.location.hostname; | ||
} | ||
if (typeof URL === 'function') { | ||
const u = new URL(url); | ||
return u.hostname || GlobalScope.location.hostname; | ||
} | ||
} | ||
return GlobalScope.location.hostname; | ||
}; | ||
|
||
export default getHost; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import GlobalScope from './global-scope'; | ||
|
||
const getLocation = () => { | ||
return window.location; | ||
return GlobalScope.location; | ||
}; | ||
|
||
export default getLocation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const GlobalScope = typeof window !== 'undefined' ? window : self; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
kevinpagtakhan
Author
Contributor
|
||
export default GlobalScope; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
@kevinpagtakhan
self
isn't available in a node scope so we can't directly replacewindow
checks withGlobalScope
in the current form.This means you'll get a
Uncaught ReferenceError: self is not defined
in a node context.We'll need to check that
self
is defined as well.Or if you dislike nested terneries