-
Notifications
You must be signed in to change notification settings - Fork 85
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
b6d9c1b
commit 8ba06c4
Showing
3 changed files
with
54 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
test('Check SDK is loaded as object and api calls reaching to hit network', () => { | ||
let xhrMock = { | ||
open: jest.fn(), | ||
setRequestHeader: jest.fn(), | ||
onreadystatechange: jest.fn(), | ||
send: jest.fn(), | ||
readyState: 4, | ||
responseText: JSON.stringify({}), | ||
status: 200 | ||
} | ||
|
||
window.XMLHttpRequest = jest.fn(() => xhrMock) | ||
|
||
document.head.innerHTML = ` | ||
`; | ||
rudderanalytics = window.rudderanalytics = []; | ||
for(var methods=["load","page","track","alias","group","identify","ready","reset"],i=0;i<methods.length;i++){var method=methods[i];rudderanalytics[method]=function(d){return function(){rudderanalytics.push([d,...arguments])}}(method)}rudderanalytics.load("1d4Qof5j9WqTuFhvUkmLaHe4EV3","https://hosted.rudderlabs.com", {logLevel:"DEBUG"}),rudderanalytics.page(); | ||
|
||
require("./prod_test.js") | ||
|
||
console.log(rudderanalytics) | ||
|
||
rudderanalytics.page() | ||
rudderanalytics.track("test-event") | ||
rudderanalytics.identify("jest-user") | ||
|
||
// check the sdk loaded successfully | ||
expect(global.rudderanalytics.push).not.toBe(Array.prototype.push); | ||
// one source config endpoint call, one implicit page call, three explicit calls | ||
expect(xhrMock.send).toHaveBeenCalledTimes(5) | ||
}); |
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,20 @@ | ||
version: 0.2 | ||
|
||
phases: | ||
install: | ||
runtime-versions: | ||
nodejs: 10 | ||
build: | ||
commands: | ||
- ls | ||
- npm install --unsafe-perm | ||
- npm run prodTest | ||
- npm run buildProdBrowser | ||
- sed 's|rudder-analytics.min.js.map|https://cdn.rudderlabs.com/rudder-analytics.min.js.map|' dist/rudder-analytics.min.js > dist/prod.js | ||
- mv dist/prod.js dist/rudder-analytics.min.js | ||
post_build: | ||
commands: | ||
- aws s3 cp dist/rudder-analytics.min.js s3://test-JS/rudder-analytics.min.js --metadata '{"max-age":"3600"}' | ||
artifacts: | ||
files: | ||
- "**/*" |
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