Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sayan-rudder committed Jun 9, 2020
1 parent b6d9c1b commit 8ba06c4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
31 changes: 31 additions & 0 deletions __tests__/script.test.js
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)
});
20 changes: 20 additions & 0 deletions buildspec.yml
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:
- "**/*"
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
],
"scripts": {
"test": "./scripts/run_tests.sh",
"prodTest": "npm run buildProdBrowser && sed 's/var rudderanalytics/rudderanalytics/g' dist/rudder-analytics.min.js > __tests__/prod_test.js && jest script.test.js",
"buildDevBrowser": "NODE_ENV=false uglify=false rollup -c",
"buildProdBrowser": "NODE_ENV=false PROD_DEBUG=true ENV=prod uglify=true rollup -c",
"buildProdBrowserDebug": "NODE_ENV=false ENV=prod PROD_DEBUG_INLINE=true uglify=true rollup -c",
Expand Down Expand Up @@ -59,6 +60,7 @@
"devDependencies": {
"@babel/core": "^7.6.2",
"@babel/preset-env": "^7.6.2",
"@mediaeventservices/jest-environment-jsdom-external-scripts": "^21.2.2",
"@size-limit/preset-big-lib": "^4.4.1",
"eslint": "^6.1.0",
"eslint-config-airbnb": "^18.0.1",
Expand All @@ -68,6 +70,7 @@
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-react": "^7.14.3",
"eslint-plugin-react-hooks": "^1.7.0",
"jest": "^26.0.1",
"rollup": "^1.22.0",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-brotli": "^2.0.2",
Expand Down

0 comments on commit 8ba06c4

Please sign in to comment.