Skip to content

Commit

Permalink
Modularization es6 (aws-amplify#4007)
Browse files Browse the repository at this point in the history
* Build ES6 Modules along with CJS Modules
* Upgrade Typescript to 3.5
* Upgrade Webpack to 4
* Upgrade Jest to 24
[Delivers #168385455]

* Removing unused variable from build scripts

* Fix signout component being undefined

* Fix PR comments

* Apply Prettier formatting

* Merge branch 'master' of github.com:aws-amplify/amplify-js into modularization-merge

* Fix tests that were failing after merge from master

* Revert docs and other directories impacted by prettier

* Update repository and homepage urls for all packages

* Add diagnostic information to build script in event of failures

* Revert formatter command as library now used Prettier with pre-commit hook

* Adding unit test for pubsub desconnection issue

* Fixing websocket disconnect issue on MqttProvider

* Update stale.yml

* fix: lerna linking for unstable and beta

* fix(amazon-cognito-identity-js): linting config (aws-amplify#4097)

* partially resolves linting issues in cognito sdk

* removes no-cap lint change

* using prettier to extend eslint in cognito sdk

* removing newline

* using airbnb lint config as well as prettier

* Fix failing pubsub tests because of jest upgrade

* Fix issue SignOut component being undefined

* Apply suggestions from code review

Co-Authored-By: Manuel Iglesias <[email protected]>

* Made mock window worker in angular tests more explicit

* Fix failing pubsub tests because of jest upgrade

* fix(@aws-amplify/core): removed unused variables (aws-amplify#3926)

* Added link to docs for local development to CONTRIBUTING (aws-amplify#3990)

* disabled autocomplete when resetting password for new password field

* added local development resources to contributing

* Fixed typo (aws-amplify#4156)

* disabled autocomplete when resetting password for new password field

* added local development resources to contributing

* fixed typo in CONTRIBUTING doc, aws-amplify#3990

* fix(@aws-amplify/api) Adding x-amz-user-agent for AppSync calls

* Adding x-amz-user-agent for appsync calls

* Fixing unit test

* chore(release): Publish [ci skip]

 - [email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]

* Publish

 - [email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]

* chore(release): Publish [ci skip]

 - [email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - [email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]
 - @aws-amplify/[email protected]

* fix(aws-amplify#4001) (aws-amplify#4131)

* fix picker parent style (aws-amplify#4135)

* Reduce threads to 1 while running jest tests as Circle CI constantly running out of memory

* Remove unnecessary async/awaits in pubsub tests

* Add Credentials mock explicitly on two tests that are failing only in circle ci

* Move spyon in beforeEach
  • Loading branch information
Amplifiyer authored Oct 17, 2019
1 parent 10d7470 commit 5c20630
Show file tree
Hide file tree
Showing 114 changed files with 2,429 additions and 2,168 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ lerna-debug.log
node_modules/**
packages/*/node_modules/**
packages/**/lib/
packages/**/lib-esm/
packages/**/dist/
packages/**/es/
.DS_Store
Expand Down
30 changes: 20 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"lint": "lerna run lint",
"link-all": "yarn unlink-all && lerna exec --parallel yarn link",
"unlink-all": "lerna exec --parallel --bail=false yarn unlink",
"publish:master": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=unstable --preid=unstable --exact",
"publish:beta": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=beta --preid=beta --exact",
"publish:master": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=unstable --preid=unstable --exact",
"publish:beta": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=beta --preid=beta --exact",
"publish:release": "lerna publish --conventional-commits --yes --message 'chore(release): Publish [ci skip]'"
},
"husky": {
Expand All @@ -40,30 +40,40 @@
},
"homepage": "https://aws-amplify.github.io/",
"devDependencies": {
"@types/jest": "^20.0.7",
"@types/jest": "^24.0.18",
"@types/node": "^8.9.5",
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.0",
"codecov": "^1.0.1",
"compression-webpack-plugin": "^1.1.3",
"cypress": "^3.2.0",
"husky": "^3.0.5",
"jest": "^22.4.3",
"jest": "^24.x.x",
"json-loader": "^0.5.7",
"lerna": "^3.13.1",
"pretty-quick": "^1.11.1",
"rimraf": "^2.6.2",
"rollup": "^0.67.4",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-typescript": "^1.0.0",
"source-map-loader": "^0.2.1",
"ts-jest": "^22.0.0",
"ts-jest": "^24.x.x",
"tslint": "^5.7.0",
"tslint-config-airbnb": "^5.8.0",
"typedoc": "^0.11.0",
"typescript": "^2.9.2",
"typescript": "^3.5.3",
"uglifyjs-webpack-plugin": "^0.4.6",
"webpack": "^3.5.5"
"webpack": "^4.32.0",
"webpack-bundle-analyzer": "^3.3.2",
"webpack-cli": "^3.1.0"
},
"jest": {
"transform": {
"^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"resetMocks": true,
"verbose": true
}
Expand Down
4 changes: 2 additions & 2 deletions packages/amazon-cognito-identity-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"repository": {
"type": "git",
"url": "https://github.com/aws/aws-amplify.git"
"url": "https://github.com/aws-amplify/amplify-js.git"
},
"license": "SEE LICENSE IN LICENSE.txt",
"licenses": [
Expand All @@ -50,7 +50,7 @@
"doc": "jsdoc src -d docs",
"lint": "eslint src",
"lint2": "eslint enhance-rn.js",
"test": "jest --passWithNoTests",
"test": "jest -w 1 --passWithNoTests",
"format": "echo \"Not implemented\""
},
"main": "lib/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,114 +11,121 @@
* and limitations under the License.
*/
jest.mock('aws-sdk/clients/personalizeevents', () => {
const PersonalizeEvents = () => {
var personalizeEvents = null;
return personalizeEvents;
}
const PersonalizeEvents = () => {
var personalizeEvents = null;
return personalizeEvents;
};

PersonalizeEvents.prototype.putEvents = (params, callback) => {
callback(null, 'data');
}
PersonalizeEvents.prototype.putEvents = (params, callback) => {
callback(null, 'data');
};

return PersonalizeEvents;
return PersonalizeEvents;
});

import { Credentials } from '@aws-amplify/core';
import AmazonPersonalizeProvider from "../../src/Providers/AmazonPersonalizeProvider";
import AmazonPersonalizeProvider from '../../src/Providers/AmazonPersonalizeProvider';

jest.useFakeTimers();

const clientInfo = {
appVersion: '1.0',
make: 'make',
model: 'model',
version: '1.0.0',
platform: 'platform'
}
appVersion: '1.0',
make: 'make',
model: 'model',
version: '1.0.0',
platform: 'platform',
};

const credentials = {
accessKeyId: 'accessKeyId',
sessionToken: 'sessionToken',
secretAccessKey: 'secretAccessKey',
identityId: 'identityId',
authenticated: true
}
accessKeyId: 'accessKeyId',
sessionToken: 'sessionToken',
secretAccessKey: 'secretAccessKey',
identityId: 'identityId',
authenticated: true,
};

const TRACKING_ID = "trackingId";
const TRACKING_ID = 'trackingId';

jest.useFakeTimers()
jest.useFakeTimers();

describe('Personalize provider test', () => {
describe('getProviderName test', () => {
test('happy case', () => {
const analytics = new AmazonPersonalizeProvider();

expect(analytics.getProviderName()).toBe('AmazonPersonalize');
});
});

describe('configure test', () => {
test('happy case', () => {
const analytics = new AmazonPersonalizeProvider();
analytics.configure({"trackingId": TRACKING_ID});
expect(analytics.configure({region: 'region1'})).toEqual(
{"flushInterval": 5000, "flushSize": 5, "region": "region1", "trackingId": "trackingId"});
});
});

describe('record test', () => {
test('record without credentials', async () => {
const analytics = new AmazonPersonalizeProvider();
analytics.configure({"trackingId": TRACKING_ID});
const spyon = jest.spyOn(Credentials, 'get').mockImplementationOnce(() => {
return Promise.reject('err');
});

expect(await analytics.record('params')).toBe(false);
spyon.mockClear();
});

test('record happy case with identify event', async () => {
const analytics = new AmazonPersonalizeProvider();
analytics.configure({"trackingId": TRACKING_ID});
const spyon = jest.spyOn(Credentials, 'get').mockImplementationOnce(() => {
return Promise.resolve(credentials);
});


await analytics.record({
event: {
eventType: "Identify",
properties: {"userId": "user1"},
},
config: {}
});

jest.advanceTimersByTime(6000);

spyon.mockClear();
});

test('record happy case with Click event', async () => {
const analytics = new AmazonPersonalizeProvider();
analytics.configure({"trackingId": TRACKING_ID});
const spyon = jest.spyOn(Credentials, 'get').mockImplementationOnce(() => {
return Promise.resolve(credentials);
});


await analytics.record({
event: {
eventType: "Click",
properties: {"itemId": "item1", "eventValue": "value1"},
},
config: {}
});

jest.advanceTimersByTime(6000);

spyon.mockClear();
});

});
};
describe('getProviderName test', () => {
test('happy case', () => {
const analytics = new AmazonPersonalizeProvider();

expect(analytics.getProviderName()).toBe('AmazonPersonalize');
});
});

describe('configure test', () => {
test('happy case', () => {
const analytics = new AmazonPersonalizeProvider();
analytics.configure({ trackingId: TRACKING_ID });
expect(analytics.configure({ region: 'region1' })).toEqual({
flushInterval: 5000,
flushSize: 5,
region: 'region1',
trackingId: 'trackingId',
});
});
});

describe('record test', () => {
test('record without credentials', async () => {
const analytics = new AmazonPersonalizeProvider();
analytics.configure({ trackingId: TRACKING_ID });
const spyon = jest
.spyOn(Credentials, 'get')
.mockImplementationOnce(() => {
return Promise.reject('err');
});

expect(await analytics.record('params')).toBe(false);
spyon.mockClear();
});

test('record happy case with identify event', async () => {
const analytics = new AmazonPersonalizeProvider();
analytics.configure({ trackingId: TRACKING_ID });
const spyon = jest
.spyOn(Credentials, 'get')
.mockImplementationOnce(() => {
return Promise.resolve(credentials);
});

await analytics.record({
event: {
eventType: 'Identify',
properties: { userId: 'user1' },
},
config: {},
});

jest.advanceTimersByTime(6000);

spyon.mockClear();
});

test('record happy case with Click event', async () => {
const analytics = new AmazonPersonalizeProvider();
analytics.configure({ trackingId: TRACKING_ID });
const spyon = jest
.spyOn(Credentials, 'get')
.mockImplementationOnce(() => {
return Promise.resolve(credentials);
});

await analytics.record({
event: {
eventType: 'Click',
properties: { itemId: 'item1', eventValue: 'value1' },
},
config: {},
});

jest.advanceTimersByTime(6000);

spyon.mockClear();
});
});
});
5 changes: 5 additions & 0 deletions packages/analytics/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

const build = require('../../scripts/build');

build(process.argv[2]);
3 changes: 3 additions & 0 deletions packages/analytics/index-rn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('./lib-esm/index.js');
7 changes: 7 additions & 0 deletions packages/analytics/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/aws-amplify-analytics.min.js');
} else {
module.exports = require('./dist/aws-amplify-analytics.js');
}
Loading

0 comments on commit 5c20630

Please sign in to comment.